mirror of
https://github.com/nushell/nushell.git
synced 2024-11-26 02:13:47 +01:00
completeness, make case-insensitive (#780)
This commit is contained in:
parent
be8c905ca7
commit
54ed82a19a
@ -114,13 +114,19 @@ fn add_keybinding(
|
|||||||
keybinding: &ParsedKeybinding,
|
keybinding: &ParsedKeybinding,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
) -> Result<(), ShellError> {
|
) -> Result<(), ShellError> {
|
||||||
let modifier = match keybinding.modifier.into_string("", config).as_str() {
|
let modifier = match keybinding
|
||||||
"CONTROL" => KeyModifiers::CONTROL,
|
.modifier
|
||||||
"SHIFT" => KeyModifiers::SHIFT,
|
.into_string("", config)
|
||||||
"ALT" => KeyModifiers::ALT,
|
.to_lowercase()
|
||||||
"NONE" => KeyModifiers::NONE,
|
.as_str()
|
||||||
"CONTROL | ALT" => KeyModifiers::CONTROL | KeyModifiers::ALT,
|
{
|
||||||
"CONTROL | ALT | SHIFT" => KeyModifiers::CONTROL | KeyModifiers::ALT | KeyModifiers::SHIFT,
|
"control" => KeyModifiers::CONTROL,
|
||||||
|
"shift" => KeyModifiers::SHIFT,
|
||||||
|
"alt" => KeyModifiers::ALT,
|
||||||
|
"none" => KeyModifiers::NONE,
|
||||||
|
"control | shift" => KeyModifiers::CONTROL | KeyModifiers::SHIFT,
|
||||||
|
"control | alt" => KeyModifiers::CONTROL | KeyModifiers::ALT,
|
||||||
|
"control | alt | shift" => KeyModifiers::CONTROL | KeyModifiers::ALT | KeyModifiers::SHIFT,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(ShellError::UnsupportedConfigValue(
|
return Err(ShellError::UnsupportedConfigValue(
|
||||||
keybinding.modifier.into_abbreviated_string(config),
|
keybinding.modifier.into_abbreviated_string(config),
|
||||||
@ -130,13 +136,20 @@ fn add_keybinding(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let keycode = match keybinding.keycode.into_string("", config).as_str() {
|
let keycode = match keybinding
|
||||||
c if c.starts_with("Char_") => {
|
.keycode
|
||||||
let char = c.replace("Char_", "");
|
.into_string("", config)
|
||||||
|
.to_lowercase()
|
||||||
|
.as_str()
|
||||||
|
{
|
||||||
|
"backspace" => KeyCode::Backspace,
|
||||||
|
"enter" => KeyCode::Enter,
|
||||||
|
c if c.starts_with("char_") => {
|
||||||
|
let char = c.replace("char_", "");
|
||||||
let char = char.chars().next().ok_or({
|
let char = char.chars().next().ok_or({
|
||||||
ShellError::UnsupportedConfigValue(
|
ShellError::UnsupportedConfigValue(
|
||||||
c.to_string(),
|
c.to_string(),
|
||||||
"Char_ plus char".to_string(),
|
"char_ plus char".to_string(),
|
||||||
keybinding.keycode.span()?,
|
keybinding.keycode.span()?,
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
@ -146,8 +159,17 @@ fn add_keybinding(
|
|||||||
"up" => KeyCode::Up,
|
"up" => KeyCode::Up,
|
||||||
"left" => KeyCode::Left,
|
"left" => KeyCode::Left,
|
||||||
"right" => KeyCode::Right,
|
"right" => KeyCode::Right,
|
||||||
"Tab" => KeyCode::Tab,
|
"home" => KeyCode::Home,
|
||||||
"BackTab" => KeyCode::BackTab,
|
"end" => KeyCode::End,
|
||||||
|
"pageup" => KeyCode::PageUp,
|
||||||
|
"pagedown" => KeyCode::PageDown,
|
||||||
|
"tab" => KeyCode::Tab,
|
||||||
|
"backtab" => KeyCode::BackTab,
|
||||||
|
"delete" => KeyCode::Delete,
|
||||||
|
"insert" => KeyCode::Insert,
|
||||||
|
// TODO: Add KeyCode::F(u8) for function keys
|
||||||
|
"null" => KeyCode::Null,
|
||||||
|
"esc" | "escape" => KeyCode::Esc,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(ShellError::UnsupportedConfigValue(
|
return Err(ShellError::UnsupportedConfigValue(
|
||||||
keybinding.keycode.into_abbreviated_string(config),
|
keybinding.keycode.into_abbreviated_string(config),
|
||||||
@ -168,24 +190,30 @@ fn parse_event(value: Value, config: &Config) -> Result<ReedlineEvent, ShellErro
|
|||||||
match value {
|
match value {
|
||||||
Value::Record { cols, vals, span } => {
|
Value::Record { cols, vals, span } => {
|
||||||
let event = match extract_value("send", &cols, &vals, &span) {
|
let event = match extract_value("send", &cols, &vals, &span) {
|
||||||
Ok(event) => match event.into_string("", config).as_str() {
|
Ok(event) => match event.into_string("", config).to_lowercase().as_str() {
|
||||||
"ActionHandler" => ReedlineEvent::ActionHandler,
|
"none" => ReedlineEvent::None,
|
||||||
"ClearScreen" => ReedlineEvent::ClearScreen,
|
"actionhandler" => ReedlineEvent::ActionHandler,
|
||||||
"ContextMenu" => ReedlineEvent::ContextMenu,
|
"clearscreen" => ReedlineEvent::ClearScreen,
|
||||||
"Complete" => ReedlineEvent::Complete,
|
"contextmenu" => ReedlineEvent::ContextMenu,
|
||||||
"Enter" => ReedlineEvent::Enter,
|
"complete" => ReedlineEvent::Complete,
|
||||||
"Esc" => ReedlineEvent::Esc,
|
"ctrld" => ReedlineEvent::CtrlD,
|
||||||
"Up" => ReedlineEvent::Up,
|
"ctrlc" => ReedlineEvent::CtrlC,
|
||||||
"Down" => ReedlineEvent::Down,
|
"enter" => ReedlineEvent::Enter,
|
||||||
"Right" => ReedlineEvent::Right,
|
"esc" | "escape" => ReedlineEvent::Esc,
|
||||||
"Left" => ReedlineEvent::Left,
|
"up" => ReedlineEvent::Up,
|
||||||
"NextElement" => ReedlineEvent::NextElement,
|
"down" => ReedlineEvent::Down,
|
||||||
"NextHistory" => ReedlineEvent::NextHistory,
|
"right" => ReedlineEvent::Right,
|
||||||
"PreviousElement" => ReedlineEvent::PreviousElement,
|
"left" => ReedlineEvent::Left,
|
||||||
"PreviousHistory" => ReedlineEvent::PreviousHistory,
|
"nextelement" => ReedlineEvent::NextElement,
|
||||||
"SearchHistory" => ReedlineEvent::SearchHistory,
|
"nexthistory" => ReedlineEvent::NextHistory,
|
||||||
"Repaint" => ReedlineEvent::Repaint,
|
"previouselement" => ReedlineEvent::PreviousElement,
|
||||||
"Edit" => {
|
"previoushistory" => ReedlineEvent::PreviousHistory,
|
||||||
|
"searchhistory" => ReedlineEvent::SearchHistory,
|
||||||
|
"repaint" => ReedlineEvent::Repaint,
|
||||||
|
// TODO: add ReedlineEvent::Mouse
|
||||||
|
// TODO: add ReedlineEvent::Resize
|
||||||
|
// TODO: add ReedlineEvent::Paste
|
||||||
|
"edit" => {
|
||||||
let edit = extract_value("edit", &cols, &vals, &span)?;
|
let edit = extract_value("edit", &cols, &vals, &span)?;
|
||||||
let edit = parse_edit(edit, config)?;
|
let edit = parse_edit(edit, config)?;
|
||||||
|
|
||||||
@ -242,74 +270,74 @@ fn parse_edit(edit: &Value, config: &Config) -> Result<EditCommand, ShellError>
|
|||||||
} => {
|
} => {
|
||||||
let cmd = extract_value("cmd", edit_cols, edit_vals, edit_span)?;
|
let cmd = extract_value("cmd", edit_cols, edit_vals, edit_span)?;
|
||||||
|
|
||||||
match cmd.into_string("", config).as_str() {
|
match cmd.into_string("", config).to_lowercase().as_str() {
|
||||||
"MoveToStart" => EditCommand::MoveToStart,
|
"movetostart" => EditCommand::MoveToStart,
|
||||||
"MoveToLineStart" => EditCommand::MoveToLineStart,
|
"movetolinestart" => EditCommand::MoveToLineStart,
|
||||||
"MoveToEnd" => EditCommand::MoveToEnd,
|
"movetoend" => EditCommand::MoveToEnd,
|
||||||
"MoveToLineEnd" => EditCommand::MoveToLineEnd,
|
"movetolineend" => EditCommand::MoveToLineEnd,
|
||||||
"MoveLeft" => EditCommand::MoveLeft,
|
"moveleft" => EditCommand::MoveLeft,
|
||||||
"MoveRight" => EditCommand::MoveRight,
|
"moveright" => EditCommand::MoveRight,
|
||||||
"MoveWordLeft" => EditCommand::MoveWordLeft,
|
"movewordleft" => EditCommand::MoveWordLeft,
|
||||||
"MoveWordRight" => EditCommand::MoveWordRight,
|
"movewordright" => EditCommand::MoveWordRight,
|
||||||
"InsertChar" => {
|
"insertchar" => {
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
||||||
EditCommand::InsertChar(char)
|
EditCommand::InsertChar(char)
|
||||||
}
|
}
|
||||||
"InsertString" => {
|
"insertstring" => {
|
||||||
let value = extract_value("value", edit_cols, edit_vals, edit_span)?;
|
let value = extract_value("value", edit_cols, edit_vals, edit_span)?;
|
||||||
EditCommand::InsertString(value.into_string("", config))
|
EditCommand::InsertString(value.into_string("", config))
|
||||||
}
|
}
|
||||||
"Backspace" => EditCommand::Backspace,
|
"backspace" => EditCommand::Backspace,
|
||||||
"Delete" => EditCommand::Delete,
|
"delete" => EditCommand::Delete,
|
||||||
"BackspaceWord" => EditCommand::BackspaceWord,
|
"backspaceword" => EditCommand::BackspaceWord,
|
||||||
"DeleteWord" => EditCommand::DeleteWord,
|
"deleteword" => EditCommand::DeleteWord,
|
||||||
"Clear" => EditCommand::Clear,
|
"clear" => EditCommand::Clear,
|
||||||
"ClearToLineEnd" => EditCommand::ClearToLineEnd,
|
"cleartolineend" => EditCommand::ClearToLineEnd,
|
||||||
"CutCurrentLine" => EditCommand::CutCurrentLine,
|
"cutcurrentline" => EditCommand::CutCurrentLine,
|
||||||
"CutFromStart" => EditCommand::CutFromStart,
|
"cutfromstart" => EditCommand::CutFromStart,
|
||||||
"CutFromLineStart" => EditCommand::CutFromLineStart,
|
"cutfromlinestart" => EditCommand::CutFromLineStart,
|
||||||
"CutToEnd" => EditCommand::CutToEnd,
|
"cuttoend" => EditCommand::CutToEnd,
|
||||||
"CutToLineEnd" => EditCommand::CutToLineEnd,
|
"cuttolineend" => EditCommand::CutToLineEnd,
|
||||||
"CutWordLeft" => EditCommand::CutWordLeft,
|
"cutwordleft" => EditCommand::CutWordLeft,
|
||||||
"CutWordRight" => EditCommand::CutWordRight,
|
"cutwordright" => EditCommand::CutWordRight,
|
||||||
"PasteCutBufferBefore" => EditCommand::PasteCutBufferBefore,
|
"pastecutbufferbefore" => EditCommand::PasteCutBufferBefore,
|
||||||
"PasteCutBufferAfter" => EditCommand::PasteCutBufferAfter,
|
"pastecutbufferafter" => EditCommand::PasteCutBufferAfter,
|
||||||
"UppercaseWord" => EditCommand::UppercaseWord,
|
"uppercaseword" => EditCommand::UppercaseWord,
|
||||||
"LowercaseWord" => EditCommand::LowercaseWord,
|
"lowercaseword" => EditCommand::LowercaseWord,
|
||||||
"CapitalizeChar" => EditCommand::CapitalizeChar,
|
"capitalizechar" => EditCommand::CapitalizeChar,
|
||||||
"SwapWords" => EditCommand::SwapWords,
|
"swapwords" => EditCommand::SwapWords,
|
||||||
"SwapGraphemes" => EditCommand::SwapGraphemes,
|
"swapgraphemes" => EditCommand::SwapGraphemes,
|
||||||
"Undo" => EditCommand::Undo,
|
"undo" => EditCommand::Undo,
|
||||||
"Redo" => EditCommand::Redo,
|
"redo" => EditCommand::Redo,
|
||||||
"CutRightUntil" => {
|
"cutrightuntil" => {
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
||||||
EditCommand::CutRightUntil(char)
|
EditCommand::CutRightUntil(char)
|
||||||
}
|
}
|
||||||
"CutRightBefore" => {
|
"cutrightbefore" => {
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
||||||
EditCommand::CutRightBefore(char)
|
EditCommand::CutRightBefore(char)
|
||||||
}
|
}
|
||||||
"MoveRightUntil" => {
|
"moverightuntil" => {
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
||||||
EditCommand::MoveRightUntil(char)
|
EditCommand::MoveRightUntil(char)
|
||||||
}
|
}
|
||||||
"MoveRightBefore" => {
|
"moverightbefore" => {
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
||||||
EditCommand::MoveRightBefore(char)
|
EditCommand::MoveRightBefore(char)
|
||||||
}
|
}
|
||||||
"CutLeftUntil" => {
|
"cutleftuntil" => {
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
||||||
EditCommand::CutLeftUntil(char)
|
EditCommand::CutLeftUntil(char)
|
||||||
}
|
}
|
||||||
"CutLeftBefore" => {
|
"cutleftbefore" => {
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
||||||
EditCommand::CutLeftBefore(char)
|
EditCommand::CutLeftBefore(char)
|
||||||
}
|
}
|
||||||
"MoveLeftUntil" => {
|
"moveleftuntil" => {
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
||||||
EditCommand::MoveLeftUntil(char)
|
EditCommand::MoveLeftUntil(char)
|
||||||
}
|
}
|
||||||
"MoveLeftBefore" => {
|
"moveleftbefore" => {
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
||||||
EditCommand::MoveLeftBefore(char)
|
EditCommand::MoveLeftBefore(char)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user