Revert "Bump Rustyline to 7.0.0 (#2776)" (#2778)

This reverts commit e73278990c.
This commit is contained in:
Jonathan Turner 2020-12-05 17:12:42 +13:00 committed by GitHub
parent d2ab287756
commit 2d15df9e6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 85 additions and 109 deletions

43
Cargo.lock generated
View file

@ -1251,6 +1251,16 @@ dependencies = [
"dirs-sys", "dirs-sys",
] ]
[[package]]
name = "dirs-next"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf36e65a80337bea855cd4ef9b8401ffce06a7baedf2e85ec467b1ac3f6e82b6"
dependencies = [
"cfg-if 1.0.0",
"dirs-sys-next",
]
[[package]] [[package]]
name = "dirs-sys" name = "dirs-sys"
version = "0.3.5" version = "0.3.5"
@ -1262,6 +1272,17 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "dirs-sys-next"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99de365f605554ae33f115102a02057d4fc18b01f3284d6870be0938743cfe7d"
dependencies = [
"libc",
"redox_users",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "doc-comment" name = "doc-comment"
version = "0.3.3" version = "0.3.3"
@ -1541,16 +1562,6 @@ dependencies = [
"percent-encoding 2.1.0", "percent-encoding 2.1.0",
] ]
[[package]]
name = "fs2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213"
dependencies = [
"libc",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "fs_extra" name = "fs_extra"
version = "1.2.0" version = "1.2.0"
@ -4815,18 +4826,16 @@ dependencies = [
[[package]] [[package]]
name = "rustyline" name = "rustyline"
version = "7.0.0" version = "6.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a5f54deba50e65ee4cf786dbc37e8b3c63bdccccbcf9d3a8a9fd0c1bb7e1984" checksum = "6f0d5e7b0219a3eadd5439498525d4765c59b7c993ef0c12244865cd2d988413"
dependencies = [ dependencies = [
"bitflags", "cfg-if 0.1.10",
"cfg-if 1.0.0", "dirs-next",
"dirs 3.0.1",
"fs2",
"libc", "libc",
"log 0.4.11", "log 0.4.11",
"memchr", "memchr",
"nix 0.19.0", "nix 0.18.0",
"scopeguard", "scopeguard",
"unicode-segmentation", "unicode-segmentation",
"unicode-width", "unicode-width",

View file

@ -75,7 +75,7 @@ rayon = "1.4.0"
regex = "1.3.9" regex = "1.3.9"
roxmltree = "0.13.0" roxmltree = "0.13.0"
rust-embed = "5.6.0" rust-embed = "5.6.0"
rustyline = {version = "7.0.0", optional = true} rustyline = {version = "6.3.0", optional = true}
serde = {version = "1.0.115", features = ["derive"]} serde = {version = "1.0.115", features = ["derive"]}
serde_bytes = "0.11.5" serde_bytes = "0.11.5"
serde_ini = "0.2.0" serde_ini = "0.2.0"

View file

@ -1,25 +1,24 @@
use crate::commands::classified::block::run_block; use crate::commands::classified::block::run_block;
use crate::commands::classified::maybe_text_codec::{MaybeTextCodec, StringOrBinary}; use crate::commands::classified::maybe_text_codec::{MaybeTextCodec, StringOrBinary};
use crate::evaluation_context::EvaluationContext; use crate::evaluation_context::EvaluationContext;
#[cfg(feature = "rustyline-support")]
use crate::keybinding::{convert_keyevent, KeyEvent};
use crate::path::canonicalize; use crate::path::canonicalize;
use crate::prelude::*; use crate::prelude::*;
#[cfg(feature = "rustyline-support")] #[cfg(feature = "rustyline-support")]
use crate::shell::Helper; use crate::shell::Helper;
use crate::EnvironmentSyncer; use crate::EnvironmentSyncer;
use futures_codec::FramedRead; use futures_codec::FramedRead;
use log::{debug, trace};
use nu_errors::ShellError; use nu_errors::ShellError;
use nu_protocol::hir::{ClassifiedCommand, Expression, InternalCommand, Literal, NamedArguments}; use nu_protocol::hir::{ClassifiedCommand, Expression, InternalCommand, Literal, NamedArguments};
use nu_protocol::{Primitive, ReturnSuccess, Scope, UntaggedValue, Value}; use nu_protocol::{Primitive, ReturnSuccess, Scope, UntaggedValue, Value};
use log::{debug, trace};
#[cfg(feature = "rustyline-support")] #[cfg(feature = "rustyline-support")]
use rustyline::{ use rustyline::{
self, self,
config::Configurer, config::Configurer,
config::{ColorMode, CompletionType, Config}, config::{ColorMode, CompletionType, Config},
error::ReadlineError, error::ReadlineError,
At, Cmd, Editor, Movement, Word, At, Cmd, Editor, KeyPress, Movement, Word,
}; };
use std::error::Error; use std::error::Error;
use std::iter::Iterator; use std::iter::Iterator;
@ -679,19 +678,16 @@ fn default_rustyline_editor_configuration() -> Editor<Helper> {
// add key bindings to move over a whole word with Ctrl+ArrowLeft and Ctrl+ArrowRight // add key bindings to move over a whole word with Ctrl+ArrowLeft and Ctrl+ArrowRight
rl.bind_sequence( rl.bind_sequence(
convert_keyevent(KeyEvent::ControlLeft), KeyPress::ControlLeft,
Cmd::Move(Movement::BackwardWord(1, Word::Vi)), Cmd::Move(Movement::BackwardWord(1, Word::Vi)),
); );
rl.bind_sequence( rl.bind_sequence(
convert_keyevent(KeyEvent::ControlRight), KeyPress::ControlRight,
Cmd::Move(Movement::ForwardWord(1, At::AfterEnd, Word::Vi)), Cmd::Move(Movement::ForwardWord(1, At::AfterEnd, Word::Vi)),
); );
// workaround for multiline-paste hang in rustyline (see https://github.com/kkawakam/rustyline/issues/202) // workaround for multiline-paste hang in rustyline (see https://github.com/kkawakam/rustyline/issues/202)
rl.bind_sequence( rl.bind_sequence(KeyPress::BracketedPasteStart, rustyline::Cmd::Noop);
convert_keyevent(KeyEvent::BracketedPasteStart),
rustyline::Cmd::Noop,
);
// Let's set the defaults up front and then override them later if the user indicates // Let's set the defaults up front and then override them later if the user indicates
// defaults taken from here https://github.com/kkawakam/rustyline/blob/2fe886c9576c1ea13ca0e5808053ad491a6fe049/src/config.rs#L150-L167 // defaults taken from here https://github.com/kkawakam/rustyline/blob/2fe886c9576c1ea13ca0e5808053ad491a6fe049/src/config.rs#L150-L167

View file

@ -1,64 +1,38 @@
use rustyline::{KeyCode, Modifiers};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub fn convert_keyevent(key_event: KeyEvent) -> rustyline::KeyEvent { fn convert_keypress(keypress: KeyPress) -> rustyline::KeyPress {
match key_event { match keypress {
KeyEvent::UnknownEscSeq => convert_to_rl_keyevent(rustyline::KeyCode::UnknownEscSeq, None), KeyPress::UnknownEscSeq => rustyline::KeyPress::UnknownEscSeq,
KeyEvent::Backspace => convert_to_rl_keyevent(rustyline::KeyCode::Backspace, None), KeyPress::Backspace => rustyline::KeyPress::Backspace,
KeyEvent::BackTab => convert_to_rl_keyevent(rustyline::KeyCode::BackTab, None), KeyPress::BackTab => rustyline::KeyPress::BackTab,
KeyEvent::BracketedPasteStart => { KeyPress::BracketedPasteStart => rustyline::KeyPress::BracketedPasteStart,
convert_to_rl_keyevent(rustyline::KeyCode::BracketedPasteStart, None) KeyPress::BracketedPasteEnd => rustyline::KeyPress::BracketedPasteEnd,
} KeyPress::Char(c) => rustyline::KeyPress::Char(c),
KeyEvent::BracketedPasteEnd => { KeyPress::ControlDown => rustyline::KeyPress::ControlDown,
convert_to_rl_keyevent(rustyline::KeyCode::BracketedPasteEnd, None) KeyPress::ControlLeft => rustyline::KeyPress::ControlLeft,
} KeyPress::ControlRight => rustyline::KeyPress::ControlRight,
KeyEvent::Char(c) => convert_to_rl_keyevent(rustyline::KeyCode::Char(c), None), KeyPress::ControlUp => rustyline::KeyPress::ControlUp,
KeyEvent::ControlDown => { KeyPress::Ctrl(c) => rustyline::KeyPress::Ctrl(c),
convert_to_rl_keyevent(rustyline::KeyCode::Down, Some(Modifiers::CTRL)) KeyPress::Delete => rustyline::KeyPress::Delete,
} KeyPress::Down => rustyline::KeyPress::Down,
KeyEvent::ControlLeft => { KeyPress::End => rustyline::KeyPress::End,
convert_to_rl_keyevent(rustyline::KeyCode::Left, Some(Modifiers::CTRL)) KeyPress::Enter => rustyline::KeyPress::Enter,
} KeyPress::Esc => rustyline::KeyPress::Esc,
KeyEvent::ControlRight => { KeyPress::F(u) => rustyline::KeyPress::F(u),
convert_to_rl_keyevent(rustyline::KeyCode::Right, Some(Modifiers::CTRL)) KeyPress::Home => rustyline::KeyPress::Home,
} KeyPress::Insert => rustyline::KeyPress::Insert,
KeyEvent::ControlUp => { KeyPress::Left => rustyline::KeyPress::Left,
convert_to_rl_keyevent(rustyline::KeyCode::Up, Some(Modifiers::CTRL)) KeyPress::Meta(c) => rustyline::KeyPress::Meta(c),
} KeyPress::Null => rustyline::KeyPress::Null,
KeyEvent::Ctrl(c) => rustyline::KeyEvent::ctrl(c), KeyPress::PageDown => rustyline::KeyPress::PageDown,
KeyEvent::Delete => convert_to_rl_keyevent(rustyline::KeyCode::Delete, None), KeyPress::PageUp => rustyline::KeyPress::PageUp,
KeyEvent::Down => convert_to_rl_keyevent(rustyline::KeyCode::Down, None), KeyPress::Right => rustyline::KeyPress::Right,
KeyEvent::End => convert_to_rl_keyevent(rustyline::KeyCode::End, None), KeyPress::ShiftDown => rustyline::KeyPress::ShiftDown,
KeyEvent::Enter => convert_to_rl_keyevent(rustyline::KeyCode::Enter, None), KeyPress::ShiftLeft => rustyline::KeyPress::ShiftLeft,
KeyEvent::Esc => convert_to_rl_keyevent(rustyline::KeyCode::Esc, None), KeyPress::ShiftRight => rustyline::KeyPress::ShiftRight,
KeyEvent::F(u) => convert_to_rl_keyevent(rustyline::KeyCode::F(u), None), KeyPress::ShiftUp => rustyline::KeyPress::ShiftUp,
KeyEvent::Home => convert_to_rl_keyevent(rustyline::KeyCode::Home, None), KeyPress::Tab => rustyline::KeyPress::Tab,
KeyEvent::Insert => convert_to_rl_keyevent(rustyline::KeyCode::Insert, None), KeyPress::Up => rustyline::KeyPress::Up,
KeyEvent::Left => convert_to_rl_keyevent(rustyline::KeyCode::Left, None),
KeyEvent::Meta(c) => rustyline::KeyEvent::new(c, Modifiers::NONE),
KeyEvent::Null => convert_to_rl_keyevent(rustyline::KeyCode::Null, None),
KeyEvent::PageDown => convert_to_rl_keyevent(rustyline::KeyCode::PageDown, None),
KeyEvent::PageUp => convert_to_rl_keyevent(rustyline::KeyCode::PageUp, None),
KeyEvent::Right => convert_to_rl_keyevent(rustyline::KeyCode::Right, None),
KeyEvent::ShiftDown => {
convert_to_rl_keyevent(rustyline::KeyCode::Down, Some(Modifiers::SHIFT))
}
KeyEvent::ShiftLeft => {
convert_to_rl_keyevent(rustyline::KeyCode::Left, Some(Modifiers::SHIFT))
}
KeyEvent::ShiftRight => {
convert_to_rl_keyevent(rustyline::KeyCode::Right, Some(Modifiers::SHIFT))
}
KeyEvent::ShiftUp => convert_to_rl_keyevent(rustyline::KeyCode::Up, Some(Modifiers::SHIFT)),
KeyEvent::Tab => convert_to_rl_keyevent(rustyline::KeyCode::Tab, None),
KeyEvent::Up => convert_to_rl_keyevent(rustyline::KeyCode::Up, None),
}
}
fn convert_to_rl_keyevent(key_event: KeyCode, modifier: Option<Modifiers>) -> rustyline::KeyEvent {
rustyline::KeyEvent {
0: key_event,
1: modifier.unwrap_or(Modifiers::NONE),
} }
} }
@ -123,9 +97,7 @@ fn convert_cmd(cmd: Cmd) -> rustyline::Cmd {
match cmd { match cmd {
Cmd::Abort => rustyline::Cmd::Abort, Cmd::Abort => rustyline::Cmd::Abort,
Cmd::AcceptLine => rustyline::Cmd::AcceptLine, Cmd::AcceptLine => rustyline::Cmd::AcceptLine,
Cmd::AcceptOrInsertLine => rustyline::Cmd::AcceptOrInsertLine { Cmd::AcceptOrInsertLine => rustyline::Cmd::AcceptOrInsertLine,
accept_in_the_middle: false,
},
Cmd::BeginningOfHistory => rustyline::Cmd::BeginningOfHistory, Cmd::BeginningOfHistory => rustyline::Cmd::BeginningOfHistory,
Cmd::CapitalizeWord => rustyline::Cmd::CapitalizeWord, Cmd::CapitalizeWord => rustyline::Cmd::CapitalizeWord,
Cmd::ClearScreen => rustyline::Cmd::ClearScreen, Cmd::ClearScreen => rustyline::Cmd::ClearScreen,
@ -168,18 +140,18 @@ fn convert_cmd(cmd: Cmd) -> rustyline::Cmd {
} }
} }
fn convert_keybinding(keybinding: Keybinding) -> (rustyline::KeyEvent, rustyline::Cmd) { fn convert_keybinding(keybinding: Keybinding) -> (rustyline::KeyPress, rustyline::Cmd) {
( (
convert_keyevent(keybinding.key), convert_keypress(keybinding.key),
convert_cmd(keybinding.binding), convert_cmd(keybinding.binding),
) )
} }
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub enum KeyEvent { pub enum KeyPress {
/// Unsupported escape sequence (on unix platform) /// Unsupported escape sequence (on unix platform)
UnknownEscSeq, UnknownEscSeq,
/// ⌫ or `KeyEvent::Ctrl('H')` /// ⌫ or `KeyPress::Ctrl('H')`
Backspace, Backspace,
/// ⇤ (usually Shift-Tab) /// ⇤ (usually Shift-Tab)
BackTab, BackTab,
@ -205,9 +177,9 @@ pub enum KeyEvent {
Down, Down,
/// ⇲ /// ⇲
End, End,
/// ↵ or `KeyEvent::Ctrl('M')` /// ↵ or `KeyPress::Ctrl('M')`
Enter, Enter,
/// Escape or `KeyEvent::Ctrl('[')` /// Escape or `KeyPress::Ctrl('[')`
Esc, Esc,
/// Function key /// Function key
F(u8), F(u8),
@ -219,7 +191,7 @@ pub enum KeyEvent {
Left, Left,
/// Escape-char or Alt-char /// Escape-char or Alt-char
Meta(char), Meta(char),
/// `KeyEvent::Char('\0')` /// `KeyPress::Char('\0')`
Null, Null,
/// ⇟ /// ⇟
PageDown, PageDown,
@ -235,7 +207,7 @@ pub enum KeyEvent {
ShiftRight, ShiftRight,
/// Shift-↑ /// Shift-↑
ShiftUp, ShiftUp,
/// ⇥ or `KeyEvent::Ctrl('I')` /// ⇥ or `KeyPress::Ctrl('I')`
Tab, Tab,
/// ↑ arrow key /// ↑ arrow key
Up, Up,
@ -427,7 +399,7 @@ pub type RepeatCount = usize;
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Keybinding { pub struct Keybinding {
key: KeyEvent, key: KeyPress,
binding: Cmd, binding: Cmd,
} }

View file

@ -62,7 +62,6 @@ impl rustyline::completion::Completer for Helper {
} }
impl rustyline::hint::Hinter for Helper { impl rustyline::hint::Hinter for Helper {
type Hint = String;
fn hint(&self, line: &str, pos: usize, ctx: &rustyline::Context<'_>) -> Option<String> { fn hint(&self, line: &str, pos: usize, ctx: &rustyline::Context<'_>) -> Option<String> {
self.hinter.as_ref().and_then(|h| h.hint(line, pos, &ctx)) self.hinter.as_ref().and_then(|h| h.hint(line, pos, &ctx))
} }

View file

@ -74,7 +74,7 @@
Enter: Enter:
binding: binding:
AcceptLine: AcceptLine:
# Next match from history # Next match from history
- key: - key:
Down: #Down Arrow Key Down: #Down Arrow Key
@ -150,7 +150,7 @@
binding: binding:
Undo: 1 Undo: 1
# KeyEvent::UnknownEscSeq => Cmd::Noop, # KeyPress::UnknownEscSeq => Cmd::Noop,
- key: - key:
UnknownEscSeq: UnknownEscSeq:
binding: binding:
@ -161,7 +161,7 @@
########################################################## ##########################################################
# /// Unsupported escape sequence (on unix platform) # /// Unsupported escape sequence (on unix platform)
# UnknownEscSeq, # UnknownEscSeq,
# /// ⌫ or `KeyEvent::Ctrl('H')` # /// ⌫ or `KeyPress::Ctrl('H')`
# Backspace, # Backspace,
# /// ⇤ (usually Shift-Tab) # /// ⇤ (usually Shift-Tab)
# BackTab, # BackTab,
@ -187,9 +187,9 @@
# Down, # Down,
# /// ⇲ # /// ⇲
# End, # End,
# /// ↵ or `KeyEvent::Ctrl('M')` # /// ↵ or `KeyPress::Ctrl('M')`
# Enter, # Enter,
# /// Escape or `KeyEvent::Ctrl('[')` # /// Escape or `KeyPress::Ctrl('[')`
# Esc, # Esc,
# /// Function key # /// Function key
# F(u8), # F(u8),
@ -201,7 +201,7 @@
# Left, # Left,
# /// Escape-char or Alt-char # /// Escape-char or Alt-char
# Meta(char), # Meta(char),
# /// `KeyEvent::Char('\0')` # /// `KeyPress::Char('\0')`
# Null, # Null,
# /// ⇟ # /// ⇟
# PageDown, # PageDown,
@ -217,7 +217,7 @@
# ShiftRight, # ShiftRight,
# /// Shift-↑ # /// Shift-↑
# ShiftUp, # ShiftUp,
# /// ⇥ or `KeyEvent::Ctrl('I')` # /// ⇥ or `KeyPress::Ctrl('I')`
# Tab, # Tab,
# /// ↑ arrow key # /// ↑ arrow key
# Up, # Up,
@ -330,7 +330,7 @@
# BeforeEnd, # BeforeEnd,
# /// After end of word. # /// After end of word.
# AfterEnd, # AfterEnd,
########################################################## ##########################################################
# Possible options for Anchor # Possible options for Anchor
########################################################## ##########################################################
@ -381,4 +381,4 @@
# /// beginning-of-buffer # /// beginning-of-buffer
# BeginningOfBuffer, # BeginningOfBuffer,
# /// end-of-buffer # /// end-of-buffer
# EndOfBuffer, # EndOfBuffer,