mirror of
https://github.com/nushell/nushell.git
synced 2025-03-20 10:36:48 +01:00
update keybindings to support new rustyline functionality (#3511)
* update keybindings to support new rustyline functionality * remove some keybindings comments * fix wasm build * fixed multiline editing binding
This commit is contained in:
parent
87a6d7166c
commit
ed515cbc0c
@ -1,63 +1,42 @@
|
|||||||
use rustyline::{KeyCode, Modifiers};
|
use rustyline::{KeyCode as RustyKeyCode, Modifiers};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub fn convert_keyevent(key_event: KeyEvent) -> rustyline::KeyEvent {
|
pub fn convert_keyevent(key_event: KeyCode, modifiers: Option<Modifiers>) -> rustyline::KeyEvent {
|
||||||
match key_event {
|
match key_event {
|
||||||
KeyEvent::UnknownEscSeq => convert_to_rl_keyevent(rustyline::KeyCode::UnknownEscSeq, None),
|
KeyCode::UnknownEscSeq => convert_to_rl_keyevent(RustyKeyCode::UnknownEscSeq, modifiers),
|
||||||
KeyEvent::Backspace => convert_to_rl_keyevent(rustyline::KeyCode::Backspace, None),
|
KeyCode::Backspace => convert_to_rl_keyevent(RustyKeyCode::Backspace, modifiers),
|
||||||
KeyEvent::BackTab => convert_to_rl_keyevent(rustyline::KeyCode::BackTab, None),
|
KeyCode::BackTab => convert_to_rl_keyevent(RustyKeyCode::BackTab, modifiers),
|
||||||
KeyEvent::BracketedPasteStart => {
|
KeyCode::BracketedPasteStart => {
|
||||||
convert_to_rl_keyevent(rustyline::KeyCode::BracketedPasteStart, None)
|
convert_to_rl_keyevent(RustyKeyCode::BracketedPasteStart, modifiers)
|
||||||
}
|
}
|
||||||
KeyEvent::BracketedPasteEnd => {
|
KeyCode::BracketedPasteEnd => {
|
||||||
convert_to_rl_keyevent(rustyline::KeyCode::BracketedPasteEnd, None)
|
convert_to_rl_keyevent(RustyKeyCode::BracketedPasteEnd, modifiers)
|
||||||
}
|
}
|
||||||
KeyEvent::Char(c) => convert_to_rl_keyevent(rustyline::KeyCode::Char(c), None),
|
KeyCode::Char(c) => convert_to_rl_keyevent(RustyKeyCode::Char(c), modifiers),
|
||||||
KeyEvent::ControlDown => {
|
KeyCode::Delete => convert_to_rl_keyevent(RustyKeyCode::Delete, modifiers),
|
||||||
convert_to_rl_keyevent(rustyline::KeyCode::Down, Some(Modifiers::CTRL))
|
KeyCode::Down => convert_to_rl_keyevent(RustyKeyCode::Down, modifiers),
|
||||||
}
|
KeyCode::End => convert_to_rl_keyevent(RustyKeyCode::End, modifiers),
|
||||||
KeyEvent::ControlLeft => {
|
KeyCode::Enter => convert_to_rl_keyevent(RustyKeyCode::Enter, modifiers),
|
||||||
convert_to_rl_keyevent(rustyline::KeyCode::Left, Some(Modifiers::CTRL))
|
KeyCode::Esc => convert_to_rl_keyevent(RustyKeyCode::Esc, modifiers),
|
||||||
}
|
KeyCode::F(u) => convert_to_rl_keyevent(RustyKeyCode::F(u), modifiers),
|
||||||
KeyEvent::ControlRight => {
|
KeyCode::Home => convert_to_rl_keyevent(RustyKeyCode::Home, modifiers),
|
||||||
convert_to_rl_keyevent(rustyline::KeyCode::Right, Some(Modifiers::CTRL))
|
KeyCode::Insert => convert_to_rl_keyevent(RustyKeyCode::Insert, modifiers),
|
||||||
}
|
KeyCode::Left => convert_to_rl_keyevent(RustyKeyCode::Left, modifiers),
|
||||||
KeyEvent::ControlUp => {
|
KeyCode::Null => convert_to_rl_keyevent(RustyKeyCode::Null, modifiers),
|
||||||
convert_to_rl_keyevent(rustyline::KeyCode::Up, Some(Modifiers::CTRL))
|
KeyCode::PageDown => convert_to_rl_keyevent(RustyKeyCode::PageDown, modifiers),
|
||||||
}
|
KeyCode::PageUp => convert_to_rl_keyevent(RustyKeyCode::PageUp, modifiers),
|
||||||
KeyEvent::Ctrl(c) => rustyline::KeyEvent::ctrl(c),
|
KeyCode::Right => convert_to_rl_keyevent(RustyKeyCode::Right, modifiers),
|
||||||
KeyEvent::Delete => convert_to_rl_keyevent(rustyline::KeyCode::Delete, None),
|
KeyCode::Tab => convert_to_rl_keyevent(RustyKeyCode::Tab, modifiers),
|
||||||
KeyEvent::Down => convert_to_rl_keyevent(rustyline::KeyCode::Down, None),
|
KeyCode::Up => convert_to_rl_keyevent(RustyKeyCode::Up, modifiers),
|
||||||
KeyEvent::End => convert_to_rl_keyevent(rustyline::KeyCode::End, None),
|
|
||||||
KeyEvent::Enter => convert_to_rl_keyevent(rustyline::KeyCode::Enter, None),
|
|
||||||
KeyEvent::Esc => convert_to_rl_keyevent(rustyline::KeyCode::Esc, None),
|
|
||||||
KeyEvent::F(u) => convert_to_rl_keyevent(rustyline::KeyCode::F(u), None),
|
|
||||||
KeyEvent::Home => convert_to_rl_keyevent(rustyline::KeyCode::Home, None),
|
|
||||||
KeyEvent::Insert => convert_to_rl_keyevent(rustyline::KeyCode::Insert, None),
|
|
||||||
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 {
|
fn convert_to_rl_keyevent(
|
||||||
|
key_code: RustyKeyCode,
|
||||||
|
modifier: Option<Modifiers>,
|
||||||
|
) -> rustyline::KeyEvent {
|
||||||
rustyline::KeyEvent {
|
rustyline::KeyEvent {
|
||||||
0: key_event,
|
0: key_code,
|
||||||
1: modifier.unwrap_or(Modifiers::NONE),
|
1: modifier.unwrap_or(Modifiers::NONE),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,12 +111,14 @@ fn convert_cmd(cmd: Cmd) -> rustyline::Cmd {
|
|||||||
Cmd::Complete => rustyline::Cmd::Complete,
|
Cmd::Complete => rustyline::Cmd::Complete,
|
||||||
Cmd::CompleteBackward => rustyline::Cmd::CompleteBackward,
|
Cmd::CompleteBackward => rustyline::Cmd::CompleteBackward,
|
||||||
Cmd::CompleteHint => rustyline::Cmd::CompleteHint,
|
Cmd::CompleteHint => rustyline::Cmd::CompleteHint,
|
||||||
|
Cmd::Dedent(movement) => rustyline::Cmd::Dedent(convert_movement(movement)),
|
||||||
Cmd::DowncaseWord => rustyline::Cmd::DowncaseWord,
|
Cmd::DowncaseWord => rustyline::Cmd::DowncaseWord,
|
||||||
Cmd::EndOfFile => rustyline::Cmd::EndOfFile,
|
Cmd::EndOfFile => rustyline::Cmd::EndOfFile,
|
||||||
Cmd::EndOfHistory => rustyline::Cmd::EndOfHistory,
|
Cmd::EndOfHistory => rustyline::Cmd::EndOfHistory,
|
||||||
Cmd::ForwardSearchHistory => rustyline::Cmd::ForwardSearchHistory,
|
Cmd::ForwardSearchHistory => rustyline::Cmd::ForwardSearchHistory,
|
||||||
Cmd::HistorySearchBackward => rustyline::Cmd::HistorySearchBackward,
|
Cmd::HistorySearchBackward => rustyline::Cmd::HistorySearchBackward,
|
||||||
Cmd::HistorySearchForward => rustyline::Cmd::HistorySearchForward,
|
Cmd::HistorySearchForward => rustyline::Cmd::HistorySearchForward,
|
||||||
|
Cmd::Indent(movement) => rustyline::Cmd::Indent(convert_movement(movement)),
|
||||||
Cmd::Insert { repeat, string } => rustyline::Cmd::Insert(repeat, string),
|
Cmd::Insert { repeat, string } => rustyline::Cmd::Insert(repeat, string),
|
||||||
Cmd::Interrupt => rustyline::Cmd::Interrupt,
|
Cmd::Interrupt => rustyline::Cmd::Interrupt,
|
||||||
Cmd::Kill(movement) => rustyline::Cmd::Kill(convert_movement(movement)),
|
Cmd::Kill(movement) => rustyline::Cmd::Kill(convert_movement(movement)),
|
||||||
@ -145,8 +126,11 @@ fn convert_cmd(cmd: Cmd) -> rustyline::Cmd {
|
|||||||
Cmd::LineUpOrPreviousHistory(u) => rustyline::Cmd::LineUpOrPreviousHistory(u),
|
Cmd::LineUpOrPreviousHistory(u) => rustyline::Cmd::LineUpOrPreviousHistory(u),
|
||||||
Cmd::Move(movement) => rustyline::Cmd::Move(convert_movement(movement)),
|
Cmd::Move(movement) => rustyline::Cmd::Move(convert_movement(movement)),
|
||||||
Cmd::NextHistory => rustyline::Cmd::NextHistory,
|
Cmd::NextHistory => rustyline::Cmd::NextHistory,
|
||||||
|
Cmd::Newline => rustyline::Cmd::Newline,
|
||||||
Cmd::Noop => rustyline::Cmd::Noop,
|
Cmd::Noop => rustyline::Cmd::Noop,
|
||||||
Cmd::Overwrite(c) => rustyline::Cmd::Overwrite(c),
|
Cmd::Overwrite(c) => rustyline::Cmd::Overwrite(c),
|
||||||
|
#[cfg(windows)]
|
||||||
|
Cmd::PasteFromClipboard => rustyline::Cmd::PasteFromClipboard,
|
||||||
Cmd::PreviousHistory => rustyline::Cmd::PreviousHistory,
|
Cmd::PreviousHistory => rustyline::Cmd::PreviousHistory,
|
||||||
Cmd::QuotedInsert => rustyline::Cmd::QuotedInsert,
|
Cmd::QuotedInsert => rustyline::Cmd::QuotedInsert,
|
||||||
Cmd::Replace {
|
Cmd::Replace {
|
||||||
@ -169,14 +153,28 @@ fn convert_cmd(cmd: Cmd) -> rustyline::Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn convert_keybinding(keybinding: Keybinding) -> (rustyline::KeyEvent, rustyline::Cmd) {
|
fn convert_keybinding(keybinding: Keybinding) -> (rustyline::KeyEvent, rustyline::Cmd) {
|
||||||
|
let rusty_modifiers = match keybinding.modifiers {
|
||||||
|
Some(mods) => match mods {
|
||||||
|
NuModifiers::CTRL => Some(Modifiers::CTRL),
|
||||||
|
NuModifiers::ALT => Some(Modifiers::ALT),
|
||||||
|
NuModifiers::SHIFT => Some(Modifiers::SHIFT),
|
||||||
|
NuModifiers::NONE => Some(Modifiers::NONE),
|
||||||
|
NuModifiers::CTRL_SHIFT => Some(Modifiers::CTRL_SHIFT),
|
||||||
|
NuModifiers::ALT_SHIFT => Some(Modifiers::ALT_SHIFT),
|
||||||
|
NuModifiers::CTRL_ALT => Some(Modifiers::CTRL_ALT),
|
||||||
|
NuModifiers::CTRL_ALT_SHIFT => Some(Modifiers::CTRL_ALT_SHIFT),
|
||||||
|
// _ => None,
|
||||||
|
},
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
(
|
(
|
||||||
convert_keyevent(keybinding.key),
|
convert_keyevent(keybinding.key, rusty_modifiers),
|
||||||
convert_cmd(keybinding.binding),
|
convert_cmd(keybinding.binding),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub enum KeyEvent {
|
pub enum KeyCode {
|
||||||
/// Unsupported escape sequence (on unix platform)
|
/// Unsupported escape sequence (on unix platform)
|
||||||
UnknownEscSeq,
|
UnknownEscSeq,
|
||||||
/// ⌫ or `KeyEvent::Ctrl('H')`
|
/// ⌫ or `KeyEvent::Ctrl('H')`
|
||||||
@ -189,16 +187,6 @@ pub enum KeyEvent {
|
|||||||
BracketedPasteEnd,
|
BracketedPasteEnd,
|
||||||
/// Single char
|
/// Single char
|
||||||
Char(char),
|
Char(char),
|
||||||
/// Ctrl-↓
|
|
||||||
ControlDown,
|
|
||||||
/// Ctrl-←
|
|
||||||
ControlLeft,
|
|
||||||
/// Ctrl-→
|
|
||||||
ControlRight,
|
|
||||||
/// Ctrl-↑
|
|
||||||
ControlUp,
|
|
||||||
/// Ctrl-char
|
|
||||||
Ctrl(char),
|
|
||||||
/// ⌦
|
/// ⌦
|
||||||
Delete,
|
Delete,
|
||||||
/// ↓ arrow key
|
/// ↓ arrow key
|
||||||
@ -217,9 +205,7 @@ pub enum KeyEvent {
|
|||||||
Insert,
|
Insert,
|
||||||
/// ← arrow key
|
/// ← arrow key
|
||||||
Left,
|
Left,
|
||||||
/// Escape-char or Alt-char
|
// /// `KeyEvent::Char('\0')`
|
||||||
Meta(char),
|
|
||||||
/// `KeyEvent::Char('\0')`
|
|
||||||
Null,
|
Null,
|
||||||
/// ⇟
|
/// ⇟
|
||||||
PageDown,
|
PageDown,
|
||||||
@ -227,14 +213,6 @@ pub enum KeyEvent {
|
|||||||
PageUp,
|
PageUp,
|
||||||
/// → arrow key
|
/// → arrow key
|
||||||
Right,
|
Right,
|
||||||
/// Shift-↓
|
|
||||||
ShiftDown,
|
|
||||||
/// Shift-←
|
|
||||||
ShiftLeft,
|
|
||||||
/// Shift-→
|
|
||||||
ShiftRight,
|
|
||||||
/// Shift-↑
|
|
||||||
ShiftUp,
|
|
||||||
/// ⇥ or `KeyEvent::Ctrl('I')`
|
/// ⇥ or `KeyEvent::Ctrl('I')`
|
||||||
Tab,
|
Tab,
|
||||||
/// ↑ arrow key
|
/// ↑ arrow key
|
||||||
@ -259,6 +237,8 @@ pub enum Cmd {
|
|||||||
CompleteBackward,
|
CompleteBackward,
|
||||||
/// complete-hint
|
/// complete-hint
|
||||||
CompleteHint,
|
CompleteHint,
|
||||||
|
/// Dedent current line
|
||||||
|
Dedent(Movement),
|
||||||
/// downcase-word
|
/// downcase-word
|
||||||
DowncaseWord,
|
DowncaseWord,
|
||||||
/// vi-eof-maybe
|
/// vi-eof-maybe
|
||||||
@ -271,6 +251,8 @@ pub enum Cmd {
|
|||||||
HistorySearchBackward,
|
HistorySearchBackward,
|
||||||
/// history-search-forward
|
/// history-search-forward
|
||||||
HistorySearchForward,
|
HistorySearchForward,
|
||||||
|
/// Indent current line
|
||||||
|
Indent(Movement),
|
||||||
/// Insert text
|
/// Insert text
|
||||||
Insert { repeat: RepeatCount, string: String },
|
Insert { repeat: RepeatCount, string: String },
|
||||||
/// Interrupt signal (Ctrl-C)
|
/// Interrupt signal (Ctrl-C)
|
||||||
@ -283,12 +265,17 @@ pub enum Cmd {
|
|||||||
/// forward-char, forward-word, vi-char-search, vi-end-word, vi-next-word,
|
/// forward-char, forward-word, vi-char-search, vi-end-word, vi-next-word,
|
||||||
/// vi-prev-word
|
/// vi-prev-word
|
||||||
Move(Movement),
|
Move(Movement),
|
||||||
|
/// Inserts a newline
|
||||||
|
Newline,
|
||||||
/// next-history
|
/// next-history
|
||||||
NextHistory,
|
NextHistory,
|
||||||
/// No action
|
/// No action
|
||||||
Noop,
|
Noop,
|
||||||
/// vi-replace
|
/// vi-replace
|
||||||
Overwrite(char),
|
Overwrite(char),
|
||||||
|
/// Paste from the clipboard
|
||||||
|
#[cfg(windows)]
|
||||||
|
PasteFromClipboard,
|
||||||
/// previous-history
|
/// previous-history
|
||||||
PreviousHistory,
|
PreviousHistory,
|
||||||
/// quoted-insert
|
/// quoted-insert
|
||||||
@ -422,12 +409,36 @@ pub enum CharSearch {
|
|||||||
BackwardAfter(char),
|
BackwardAfter(char),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The set of modifier keys that were triggered along with a key press.
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
#[allow(clippy::clippy::upper_case_acronyms)]
|
||||||
|
pub enum NuModifiers {
|
||||||
|
/// Control modifier
|
||||||
|
CTRL = 8,
|
||||||
|
/// Escape or Alt modifier
|
||||||
|
ALT = 4,
|
||||||
|
/// Shift modifier
|
||||||
|
SHIFT = 2,
|
||||||
|
/// No modifier
|
||||||
|
NONE = 0,
|
||||||
|
/// Ctrl + Shift
|
||||||
|
CTRL_SHIFT = 10,
|
||||||
|
/// Alt + Shift
|
||||||
|
ALT_SHIFT = 6,
|
||||||
|
/// Ctrl + Alt
|
||||||
|
CTRL_ALT = 12,
|
||||||
|
/// Ctrl + Alt + Shift
|
||||||
|
CTRL_ALT_SHIFT = 14,
|
||||||
|
}
|
||||||
|
|
||||||
/// The number of times one command should be repeated.
|
/// The number of times one command should be repeated.
|
||||||
pub type RepeatCount = usize;
|
pub type RepeatCount = usize;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Keybinding {
|
pub struct Keybinding {
|
||||||
key: KeyEvent,
|
key: KeyCode,
|
||||||
|
modifiers: Option<NuModifiers>,
|
||||||
binding: Cmd,
|
binding: Cmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,7 +453,7 @@ pub(crate) fn load_keybindings(
|
|||||||
// Silently fail if there is no file there
|
// Silently fail if there is no file there
|
||||||
if let Ok(contents) = contents {
|
if let Ok(contents) = contents {
|
||||||
let keybindings: Keybindings = serde_yaml::from_str(&contents)?;
|
let keybindings: Keybindings = serde_yaml::from_str(&contents)?;
|
||||||
|
// eprint!("{}{}{}", keybindings.key, keybindings.mo);
|
||||||
for keybinding in keybindings.into_iter() {
|
for keybinding in keybindings.into_iter() {
|
||||||
let (k, b) = convert_keybinding(keybinding);
|
let (k, b) = convert_keybinding(keybinding);
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use crate::prelude::*;
|
|||||||
use nu_engine::script::LineResult;
|
use nu_engine::script::LineResult;
|
||||||
|
|
||||||
#[cfg(feature = "rustyline-support")]
|
#[cfg(feature = "rustyline-support")]
|
||||||
use crate::keybinding::{convert_keyevent, KeyEvent};
|
use crate::keybinding::{convert_keyevent, KeyCode};
|
||||||
|
|
||||||
#[cfg(feature = "rustyline-support")]
|
#[cfg(feature = "rustyline-support")]
|
||||||
use crate::shell::Helper;
|
use crate::shell::Helper;
|
||||||
@ -20,7 +20,7 @@ use rustyline::{
|
|||||||
config::{ColorMode, CompletionType, Config},
|
config::{ColorMode, CompletionType, Config},
|
||||||
error::ReadlineError,
|
error::ReadlineError,
|
||||||
line_buffer::LineBuffer,
|
line_buffer::LineBuffer,
|
||||||
At, Cmd, ConditionalEventHandler, Editor, EventHandler, Movement, Word,
|
At, Cmd, ConditionalEventHandler, Editor, EventHandler, Modifiers, Movement, Word,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "rustyline-support")]
|
#[cfg(feature = "rustyline-support")]
|
||||||
@ -79,18 +79,20 @@ pub fn default_rustyline_editor_configuration() -> Editor<Helper> {
|
|||||||
let mut rl: Editor<_> = Editor::with_config(config);
|
let mut rl: Editor<_> = Editor::with_config(config);
|
||||||
|
|
||||||
// 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
|
||||||
|
//M modifier, E KeyEvent, K KeyCode
|
||||||
rl.bind_sequence(
|
rl.bind_sequence(
|
||||||
convert_keyevent(KeyEvent::ControlLeft),
|
convert_keyevent(KeyCode::Left, Some(Modifiers::CTRL)),
|
||||||
Cmd::Move(Movement::BackwardWord(1, Word::Vi)),
|
Cmd::Move(Movement::BackwardWord(1, Word::Vi)),
|
||||||
);
|
);
|
||||||
|
|
||||||
rl.bind_sequence(
|
rl.bind_sequence(
|
||||||
convert_keyevent(KeyEvent::ControlRight),
|
convert_keyevent(KeyCode::Right, Some(Modifiers::CTRL)),
|
||||||
EventHandler::Conditional(Box::new(PartialCompleteHintHandler)),
|
EventHandler::Conditional(Box::new(PartialCompleteHintHandler)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// 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(
|
||||||
convert_keyevent(KeyEvent::BracketedPasteStart),
|
convert_keyevent(KeyCode::BracketedPasteStart, None),
|
||||||
rustyline::Cmd::Noop,
|
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
|
||||||
|
@ -3,13 +3,40 @@
|
|||||||
# "key:". If you want to change the modifier you should change or add the
|
# "key:". If you want to change the modifier you should change or add the
|
||||||
# modifier after "key:", such as:
|
# modifier after "key:", such as:
|
||||||
# key:
|
# key:
|
||||||
# Ctrl: A
|
# Char: A
|
||||||
# Available modifiers are Ctrl, F (for function), Meta (escape-char, alt-char)
|
# modifiers:
|
||||||
|
# CTRL:
|
||||||
|
# binding:
|
||||||
|
# blah:
|
||||||
|
# Available modifiers are CTRL, ALT, SHIFT, NONE, CTRL_SHIFT,
|
||||||
|
# ALT_SHIFT, CTRL_ALT, CTRL_ALT_SHIFT
|
||||||
|
|
||||||
##########################################################
|
##########################################################
|
||||||
# Common From https://github.com/kkawakam/rustyline#actions
|
# Common From https://github.com/kkawakam/rustyline#actions
|
||||||
##########################################################
|
##########################################################
|
||||||
|
|
||||||
|
# Control Backspace, delete 1 word at a time
|
||||||
|
- key:
|
||||||
|
Backspace:
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
|
binding:
|
||||||
|
Kill:
|
||||||
|
BackwardWord:
|
||||||
|
repeat: 1
|
||||||
|
word: Big
|
||||||
|
|
||||||
|
# Alt Backspace, delete 1 word at a time
|
||||||
|
- key:
|
||||||
|
Backspace:
|
||||||
|
modifiers:
|
||||||
|
ALT:
|
||||||
|
binding:
|
||||||
|
Kill:
|
||||||
|
BackwardWord:
|
||||||
|
repeat: 1
|
||||||
|
word: Big
|
||||||
|
|
||||||
# Move cursor to the beginning of line
|
# Move cursor to the beginning of line
|
||||||
- key:
|
- key:
|
||||||
Home:
|
Home:
|
||||||
@ -38,19 +65,31 @@
|
|||||||
|
|
||||||
# Complete Hint
|
# Complete Hint
|
||||||
- key:
|
- key:
|
||||||
ShiftRight:
|
Right:
|
||||||
|
modifiers:
|
||||||
|
SHIFT:
|
||||||
|
binding:
|
||||||
|
CompleteHint:
|
||||||
|
- key:
|
||||||
|
Char: F
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
binding:
|
binding:
|
||||||
CompleteHint:
|
CompleteHint:
|
||||||
|
|
||||||
# Interrupt/Cancel edition
|
# Interrupt/Cancel edition
|
||||||
- key:
|
- key:
|
||||||
Ctrl: C
|
Char: C
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
binding:
|
binding:
|
||||||
Interrupt:
|
Interrupt:
|
||||||
|
|
||||||
# (if line is not empty) Delete character under cursor
|
# (if line is not empty) Delete character under cursor
|
||||||
- key:
|
- key:
|
||||||
Ctrl: D
|
Char: D
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
binding:
|
binding:
|
||||||
EndOfFile:
|
EndOfFile:
|
||||||
|
|
||||||
@ -63,18 +102,24 @@
|
|||||||
|
|
||||||
# Finish the line entry
|
# Finish the line entry
|
||||||
- key:
|
- key:
|
||||||
Ctrl: J
|
Char: J
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
binding:
|
binding:
|
||||||
AcceptLine:
|
AcceptLine:
|
||||||
- key:
|
- key:
|
||||||
Ctrl: M
|
Char: M
|
||||||
binding:
|
modifiers:
|
||||||
AcceptLine:
|
CTRL:
|
||||||
- key:
|
|
||||||
Enter:
|
|
||||||
binding:
|
binding:
|
||||||
AcceptLine:
|
AcceptLine:
|
||||||
|
|
||||||
|
# This makes multiline editing stop working since Enter accepts a line
|
||||||
|
# - key:
|
||||||
|
# Enter:
|
||||||
|
# binding:
|
||||||
|
# AcceptLine:
|
||||||
|
|
||||||
# Next match from history
|
# Next match from history
|
||||||
- key:
|
- key:
|
||||||
Down: #Down Arrow Key
|
Down: #Down Arrow Key
|
||||||
@ -89,41 +134,55 @@
|
|||||||
|
|
||||||
# Reverse Search history (Ctrl-S forward, Ctrl-G cancel)
|
# Reverse Search history (Ctrl-S forward, Ctrl-G cancel)
|
||||||
- key:
|
- key:
|
||||||
Ctrl: R
|
Char: R
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
binding:
|
binding:
|
||||||
ReverseSearchHistory:
|
ReverseSearchHistory:
|
||||||
|
|
||||||
# Forward Search history (Ctrl-R backward, Ctrl-G cancel)
|
# Forward Search history (Ctrl-R backward, Ctrl-G cancel)
|
||||||
- key:
|
- key:
|
||||||
Ctrl: S
|
Char: S
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
binding:
|
binding:
|
||||||
ForwardSearchHistory:
|
ForwardSearchHistory:
|
||||||
|
|
||||||
# Transpose previous character with current character
|
# Transpose previous character with current character
|
||||||
- key:
|
- key:
|
||||||
Ctrl: T
|
Char: T
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
binding:
|
binding:
|
||||||
TransposeChars:
|
TransposeChars:
|
||||||
|
|
||||||
# Delete from start of line to cursor
|
# Delete from start of line to cursor
|
||||||
- key:
|
- key:
|
||||||
Ctrl: U
|
Char: U
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
binding:
|
binding:
|
||||||
Kill: BeginningOfLine
|
Kill: BeginningOfLine
|
||||||
|
|
||||||
# Insert any special character without performing its associated action (#65)
|
# Insert any special character without performing its associated action (#65)
|
||||||
- key:
|
- key:
|
||||||
Ctrl: Q
|
Char: Q
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
binding:
|
binding:
|
||||||
QuotedInsert:
|
QuotedInsert:
|
||||||
- key:
|
- key:
|
||||||
Ctrl: V
|
Char: V
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
binding:
|
binding:
|
||||||
QuotedInsert:
|
QuotedInsert:
|
||||||
|
|
||||||
# Delete word leading up to cursor (using white space as a word boundary)
|
# Delete word leading up to cursor (using white space as a word boundary)
|
||||||
- key:
|
- key:
|
||||||
Ctrl: W
|
Char: W
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
binding:
|
binding:
|
||||||
Kill:
|
Kill:
|
||||||
BackwardWord:
|
BackwardWord:
|
||||||
@ -132,7 +191,9 @@
|
|||||||
|
|
||||||
# Paste from Yank buffer
|
# Paste from Yank buffer
|
||||||
- key:
|
- key:
|
||||||
Ctrl: Y
|
Char: Y
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
binding:
|
binding:
|
||||||
Yank:
|
Yank:
|
||||||
repeat: 1
|
repeat: 1
|
||||||
@ -140,22 +201,25 @@
|
|||||||
|
|
||||||
# Suspend (Unix only)
|
# Suspend (Unix only)
|
||||||
- key:
|
- key:
|
||||||
Ctrl: Z
|
Char: Z
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
binding:
|
binding:
|
||||||
Suspend:
|
Suspend:
|
||||||
|
|
||||||
# Undo
|
# Undo
|
||||||
- key:
|
- key:
|
||||||
Ctrl: '_'
|
Char: "_"
|
||||||
|
modifiers:
|
||||||
|
CTRL:
|
||||||
binding:
|
binding:
|
||||||
Undo: 1
|
Undo: 1
|
||||||
|
|
||||||
# KeyEvent::UnknownEscSeq => Cmd::Noop,
|
# KeyPress::UnknownEscSeq => Cmd::Noop,
|
||||||
- key:
|
- key:
|
||||||
UnknownEscSeq:
|
UnknownEscSeq:
|
||||||
binding:
|
binding:
|
||||||
Noop:
|
Noop:
|
||||||
|
|
||||||
##########################################################
|
##########################################################
|
||||||
# Possible options for key:
|
# Possible options for key:
|
||||||
##########################################################
|
##########################################################
|
||||||
@ -171,16 +235,6 @@
|
|||||||
# BracketedPasteEnd,
|
# BracketedPasteEnd,
|
||||||
# /// Single char
|
# /// Single char
|
||||||
# Char(char),
|
# Char(char),
|
||||||
# /// Ctrl-↓
|
|
||||||
# ControlDown,
|
|
||||||
# /// Ctrl-←
|
|
||||||
# ControlLeft,
|
|
||||||
# /// Ctrl-→
|
|
||||||
# ControlRight,
|
|
||||||
# /// Ctrl-↑
|
|
||||||
# ControlUp,
|
|
||||||
# /// Ctrl-char
|
|
||||||
# Ctrl(char),
|
|
||||||
# /// ⌦
|
# /// ⌦
|
||||||
# Delete,
|
# Delete,
|
||||||
# /// ↓ arrow key
|
# /// ↓ arrow key
|
||||||
@ -199,9 +253,7 @@
|
|||||||
# Insert,
|
# Insert,
|
||||||
# /// ← arrow key
|
# /// ← arrow key
|
||||||
# Left,
|
# Left,
|
||||||
# /// Escape-char or Alt-char
|
# // /// `KeyEvent::Char('\0')`
|
||||||
# Meta(char),
|
|
||||||
# /// `KeyEvent::Char('\0')`
|
|
||||||
# Null,
|
# Null,
|
||||||
# /// ⇟
|
# /// ⇟
|
||||||
# PageDown,
|
# PageDown,
|
||||||
@ -209,14 +261,6 @@
|
|||||||
# PageUp,
|
# PageUp,
|
||||||
# /// → arrow key
|
# /// → arrow key
|
||||||
# Right,
|
# Right,
|
||||||
# /// Shift-↓
|
|
||||||
# ShiftDown,
|
|
||||||
# /// Shift-←
|
|
||||||
# ShiftLeft,
|
|
||||||
# /// Shift-→
|
|
||||||
# ShiftRight,
|
|
||||||
# /// Shift-↑
|
|
||||||
# ShiftUp,
|
|
||||||
# /// ⇥ or `KeyEvent::Ctrl('I')`
|
# /// ⇥ or `KeyEvent::Ctrl('I')`
|
||||||
# Tab,
|
# Tab,
|
||||||
# /// ↑ arrow key
|
# /// ↑ arrow key
|
||||||
@ -241,6 +285,8 @@
|
|||||||
# CompleteBackward,
|
# CompleteBackward,
|
||||||
# /// complete-hint
|
# /// complete-hint
|
||||||
# CompleteHint,
|
# CompleteHint,
|
||||||
|
# /// Dedent current line
|
||||||
|
# Dedent(Movement),
|
||||||
# /// downcase-word
|
# /// downcase-word
|
||||||
# DowncaseWord,
|
# DowncaseWord,
|
||||||
# /// vi-eof-maybe
|
# /// vi-eof-maybe
|
||||||
@ -253,8 +299,10 @@
|
|||||||
# HistorySearchBackward,
|
# HistorySearchBackward,
|
||||||
# /// history-search-forward
|
# /// history-search-forward
|
||||||
# HistorySearchForward,
|
# HistorySearchForward,
|
||||||
|
# /// Indent current line
|
||||||
|
# Indent(Movement),
|
||||||
# /// Insert text
|
# /// Insert text
|
||||||
# Insert(RepeatCount, String),
|
# Insert { repeat: RepeatCount, string: String },
|
||||||
# /// Interrupt signal (Ctrl-C)
|
# /// Interrupt signal (Ctrl-C)
|
||||||
# Interrupt,
|
# Interrupt,
|
||||||
# /// backward-delete-char, backward-kill-line, backward-kill-word
|
# /// backward-delete-char, backward-kill-line, backward-kill-word
|
||||||
@ -265,24 +313,32 @@
|
|||||||
# /// forward-char, forward-word, vi-char-search, vi-end-word, vi-next-word,
|
# /// forward-char, forward-word, vi-char-search, vi-end-word, vi-next-word,
|
||||||
# /// vi-prev-word
|
# /// vi-prev-word
|
||||||
# Move(Movement),
|
# Move(Movement),
|
||||||
|
# /// Inserts a newline
|
||||||
|
# Newline,
|
||||||
# /// next-history
|
# /// next-history
|
||||||
# NextHistory,
|
# NextHistory,
|
||||||
# /// No action
|
# /// No action
|
||||||
# Noop,
|
# Noop,
|
||||||
# /// vi-replace
|
# /// vi-replace
|
||||||
# Overwrite(char),
|
# Overwrite(char),
|
||||||
|
# /// Paste from the clipboard
|
||||||
|
# #[cfg(windows)]
|
||||||
|
# PasteFromClipboard,
|
||||||
# /// previous-history
|
# /// previous-history
|
||||||
# PreviousHistory,
|
# PreviousHistory,
|
||||||
# /// quoted-insert
|
# /// quoted-insert
|
||||||
# QuotedInsert,
|
# QuotedInsert,
|
||||||
# /// vi-change-char
|
# /// vi-change-char
|
||||||
# ReplaceChar(RepeatCount, char),
|
# ReplaceChar { repeat: RepeatCount, ch: char },
|
||||||
# /// vi-change-to, vi-substitute
|
# /// vi-change-to, vi-substitute
|
||||||
# Replace(Movement, Option<String>),
|
# Replace {
|
||||||
|
# movement: Movement,
|
||||||
|
# replacement: Option<String>,
|
||||||
|
# },
|
||||||
# /// reverse-search-history
|
# /// reverse-search-history
|
||||||
# ReverseSearchHistory,
|
# ReverseSearchHistory,
|
||||||
# /// self-insert
|
# /// self-insert
|
||||||
# SelfInsert(RepeatCount, char),
|
# SelfInsert { repeat: RepeatCount, ch: char },
|
||||||
# /// Suspend signal (Ctrl-Z on unix platform)
|
# /// Suspend signal (Ctrl-Z on unix platform)
|
||||||
# Suspend,
|
# Suspend,
|
||||||
# /// transpose-chars
|
# /// transpose-chars
|
||||||
@ -298,7 +354,7 @@
|
|||||||
# /// vi-yank-to
|
# /// vi-yank-to
|
||||||
# ViYankTo(Movement),
|
# ViYankTo(Movement),
|
||||||
# /// yank, vi-put
|
# /// yank, vi-put
|
||||||
# Yank(RepeatCount, Anchor),
|
# Yank { repeat: RepeatCount, anchor: Anchor },
|
||||||
# /// yank-pop
|
# /// yank-pop
|
||||||
# YankPop,
|
# YankPop,
|
||||||
# /// moves cursor to the line above or switches to prev history entry if
|
# /// moves cursor to the line above or switches to prev history entry if
|
||||||
|
Loading…
Reference in New Issue
Block a user