mirror of
https://github.com/nushell/nushell
synced 2024-12-27 21:43:09 +00:00
remove cmd from edit (#4840)
This commit is contained in:
parent
72daf8c64e
commit
6e65aef9bf
2 changed files with 139 additions and 144 deletions
|
@ -247,7 +247,7 @@ let $config = {
|
||||||
event: {
|
event: {
|
||||||
until: [
|
until: [
|
||||||
{ send: menupageprevious }
|
{ send: menupageprevious }
|
||||||
{ edit: { cmd: undo } }
|
{ edit: undo }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -368,7 +368,13 @@ fn parse_event(value: &Value, config: &Config) -> Result<ReedlineEvent, ShellErr
|
||||||
span,
|
span,
|
||||||
),
|
),
|
||||||
EventType::Edit(value) => {
|
EventType::Edit(value) => {
|
||||||
let edit = parse_edit(value, config)?;
|
let edit = edit_from_record(
|
||||||
|
value.into_string("", config).to_lowercase().as_str(),
|
||||||
|
cols,
|
||||||
|
vals,
|
||||||
|
config,
|
||||||
|
span,
|
||||||
|
)?;
|
||||||
Ok(ReedlineEvent::Edit(vec![edit]))
|
Ok(ReedlineEvent::Edit(vec![edit]))
|
||||||
}
|
}
|
||||||
EventType::Until(value) => match value {
|
EventType::Until(value) => match value {
|
||||||
|
@ -411,144 +417,144 @@ fn event_from_record(
|
||||||
config: &Config,
|
config: &Config,
|
||||||
span: &Span,
|
span: &Span,
|
||||||
) -> Result<ReedlineEvent, ShellError> {
|
) -> Result<ReedlineEvent, ShellError> {
|
||||||
match name {
|
let event = match name {
|
||||||
"none" => Ok(ReedlineEvent::None),
|
"none" => ReedlineEvent::None,
|
||||||
"actionhandler" => Ok(ReedlineEvent::ActionHandler),
|
"actionhandler" => ReedlineEvent::ActionHandler,
|
||||||
"clearscreen" => Ok(ReedlineEvent::ClearScreen),
|
"clearscreen" => ReedlineEvent::ClearScreen,
|
||||||
"historyhintcomplete" => Ok(ReedlineEvent::HistoryHintComplete),
|
"historyhintcomplete" => ReedlineEvent::HistoryHintComplete,
|
||||||
"historyhintwordcomplete" => Ok(ReedlineEvent::HistoryHintWordComplete),
|
"historyhintwordcomplete" => ReedlineEvent::HistoryHintWordComplete,
|
||||||
"ctrld" => Ok(ReedlineEvent::CtrlD),
|
"ctrld" => ReedlineEvent::CtrlD,
|
||||||
"ctrlc" => Ok(ReedlineEvent::CtrlC),
|
"ctrlc" => ReedlineEvent::CtrlC,
|
||||||
"enter" => Ok(ReedlineEvent::Enter),
|
"enter" => ReedlineEvent::Enter,
|
||||||
"esc" | "escape" => Ok(ReedlineEvent::Esc),
|
"esc" | "escape" => ReedlineEvent::Esc,
|
||||||
"up" => Ok(ReedlineEvent::Up),
|
"up" => ReedlineEvent::Up,
|
||||||
"down" => Ok(ReedlineEvent::Down),
|
"down" => ReedlineEvent::Down,
|
||||||
"right" => Ok(ReedlineEvent::Right),
|
"right" => ReedlineEvent::Right,
|
||||||
"left" => Ok(ReedlineEvent::Left),
|
"left" => ReedlineEvent::Left,
|
||||||
"searchhistory" => Ok(ReedlineEvent::SearchHistory),
|
"searchhistory" => ReedlineEvent::SearchHistory,
|
||||||
"nexthistory" => Ok(ReedlineEvent::NextHistory),
|
"nexthistory" => ReedlineEvent::NextHistory,
|
||||||
"previoushistory" => Ok(ReedlineEvent::PreviousHistory),
|
"previoushistory" => ReedlineEvent::PreviousHistory,
|
||||||
"repaint" => Ok(ReedlineEvent::Repaint),
|
"repaint" => ReedlineEvent::Repaint,
|
||||||
"menudown" => Ok(ReedlineEvent::MenuDown),
|
"menudown" => ReedlineEvent::MenuDown,
|
||||||
"menuup" => Ok(ReedlineEvent::MenuUp),
|
"menuup" => ReedlineEvent::MenuUp,
|
||||||
"menuleft" => Ok(ReedlineEvent::MenuLeft),
|
"menuleft" => ReedlineEvent::MenuLeft,
|
||||||
"menuright" => Ok(ReedlineEvent::MenuRight),
|
"menuright" => ReedlineEvent::MenuRight,
|
||||||
"menunext" => Ok(ReedlineEvent::MenuNext),
|
"menunext" => ReedlineEvent::MenuNext,
|
||||||
"menuprevious" => Ok(ReedlineEvent::MenuPrevious),
|
"menuprevious" => ReedlineEvent::MenuPrevious,
|
||||||
"menupagenext" => Ok(ReedlineEvent::MenuPageNext),
|
"menupagenext" => ReedlineEvent::MenuPageNext,
|
||||||
"menupageprevious" => Ok(ReedlineEvent::MenuPagePrevious),
|
"menupageprevious" => ReedlineEvent::MenuPagePrevious,
|
||||||
"menu" => {
|
"menu" => {
|
||||||
let menu = extract_value("name", cols, vals, span)?;
|
let menu = extract_value("name", cols, vals, span)?;
|
||||||
Ok(ReedlineEvent::Menu(menu.into_string("", config)))
|
ReedlineEvent::Menu(menu.into_string("", config))
|
||||||
}
|
}
|
||||||
"executehostcommand" => {
|
"executehostcommand" => {
|
||||||
let cmd = extract_value("cmd", cols, vals, span)?;
|
let cmd = extract_value("cmd", cols, vals, span)?;
|
||||||
Ok(ReedlineEvent::ExecuteHostCommand(
|
ReedlineEvent::ExecuteHostCommand(cmd.into_string("", config))
|
||||||
cmd.into_string("", config),
|
}
|
||||||
|
v => {
|
||||||
|
return Err(ShellError::UnsupportedConfigValue(
|
||||||
|
"Reedline event".to_string(),
|
||||||
|
v.to_string(),
|
||||||
|
*span,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
v => Err(ShellError::UnsupportedConfigValue(
|
};
|
||||||
"Reedline event".to_string(),
|
|
||||||
v.to_string(),
|
Ok(event)
|
||||||
*span,
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_edit(edit: &Value, config: &Config) -> Result<EditCommand, ShellError> {
|
fn edit_from_record(
|
||||||
let edit = match edit {
|
name: &str,
|
||||||
Value::Record {
|
cols: &[String],
|
||||||
cols: edit_cols,
|
vals: &[Value],
|
||||||
vals: edit_vals,
|
config: &Config,
|
||||||
span: edit_span,
|
span: &Span,
|
||||||
} => {
|
) -> Result<EditCommand, ShellError> {
|
||||||
let cmd = extract_value("cmd", edit_cols, edit_vals, edit_span)?;
|
let edit = match name {
|
||||||
|
"movetostart" => EditCommand::MoveToStart,
|
||||||
match cmd.into_string("", config).to_lowercase().as_str() {
|
"movetolinestart" => EditCommand::MoveToLineStart,
|
||||||
"movetostart" => EditCommand::MoveToStart,
|
"movetoend" => EditCommand::MoveToEnd,
|
||||||
"movetolinestart" => EditCommand::MoveToLineStart,
|
"movetolineend" => EditCommand::MoveToLineEnd,
|
||||||
"movetoend" => EditCommand::MoveToEnd,
|
"moveleft" => EditCommand::MoveLeft,
|
||||||
"movetolineend" => EditCommand::MoveToLineEnd,
|
"moveright" => EditCommand::MoveRight,
|
||||||
"moveleft" => EditCommand::MoveLeft,
|
"movewordleft" => EditCommand::MoveWordLeft,
|
||||||
"moveright" => EditCommand::MoveRight,
|
"movewordright" => EditCommand::MoveWordRight,
|
||||||
"movewordleft" => EditCommand::MoveWordLeft,
|
"insertchar" => {
|
||||||
"movewordright" => EditCommand::MoveWordRight,
|
let value = extract_value("value", cols, vals, span)?;
|
||||||
"insertchar" => {
|
let char = extract_char(value, config)?;
|
||||||
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", cols, vals, 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 value = extract_value("value", cols, vals, span)?;
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
let char = extract_char(value, config)?;
|
||||||
EditCommand::CutRightUntil(char)
|
EditCommand::CutRightUntil(char)
|
||||||
}
|
}
|
||||||
"cutrightbefore" => {
|
"cutrightbefore" => {
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
let value = extract_value("value", cols, vals, span)?;
|
||||||
EditCommand::CutRightBefore(char)
|
let char = extract_char(value, config)?;
|
||||||
}
|
EditCommand::CutRightBefore(char)
|
||||||
"moverightuntil" => {
|
}
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
"moverightuntil" => {
|
||||||
EditCommand::MoveRightUntil(char)
|
let value = extract_value("value", cols, vals, span)?;
|
||||||
}
|
let char = extract_char(value, config)?;
|
||||||
"moverightbefore" => {
|
EditCommand::MoveRightUntil(char)
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
}
|
||||||
EditCommand::MoveRightBefore(char)
|
"moverightbefore" => {
|
||||||
}
|
let value = extract_value("value", cols, vals, span)?;
|
||||||
"cutleftuntil" => {
|
let char = extract_char(value, config)?;
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
EditCommand::MoveRightBefore(char)
|
||||||
EditCommand::CutLeftUntil(char)
|
}
|
||||||
}
|
"cutleftuntil" => {
|
||||||
"cutleftbefore" => {
|
let value = extract_value("value", cols, vals, span)?;
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
let char = extract_char(value, config)?;
|
||||||
EditCommand::CutLeftBefore(char)
|
EditCommand::CutLeftUntil(char)
|
||||||
}
|
}
|
||||||
"moveleftuntil" => {
|
"cutleftbefore" => {
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
let value = extract_value("value", cols, vals, span)?;
|
||||||
EditCommand::MoveLeftUntil(char)
|
let char = extract_char(value, config)?;
|
||||||
}
|
EditCommand::CutLeftBefore(char)
|
||||||
"moveleftbefore" => {
|
}
|
||||||
let char = extract_char("value", edit_cols, edit_vals, config, edit_span)?;
|
"moveleftuntil" => {
|
||||||
EditCommand::MoveLeftBefore(char)
|
let value = extract_value("value", cols, vals, span)?;
|
||||||
}
|
let char = extract_char(value, config)?;
|
||||||
e => {
|
EditCommand::MoveLeftUntil(char)
|
||||||
return Err(ShellError::UnsupportedConfigValue(
|
}
|
||||||
"reedline EditCommand".to_string(),
|
"moveleftbefore" => {
|
||||||
e.to_string(),
|
let value = extract_value("value", cols, vals, span)?;
|
||||||
edit.span()?,
|
let char = extract_char(value, config)?;
|
||||||
))
|
EditCommand::MoveLeftBefore(char)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
e => {
|
e => {
|
||||||
return Err(ShellError::UnsupportedConfigValue(
|
return Err(ShellError::UnsupportedConfigValue(
|
||||||
"record with EditCommand".to_string(),
|
"reedline EditCommand".to_string(),
|
||||||
e.into_abbreviated_string(config),
|
e.to_string(),
|
||||||
edit.span()?,
|
*span,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -556,20 +562,13 @@ fn parse_edit(edit: &Value, config: &Config) -> Result<EditCommand, ShellError>
|
||||||
Ok(edit)
|
Ok(edit)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_char<'record>(
|
fn extract_char(value: &Value, config: &Config) -> Result<char, ShellError> {
|
||||||
name: &str,
|
let span = value.span()?;
|
||||||
cols: &'record [String],
|
|
||||||
vals: &'record [Value],
|
|
||||||
config: &Config,
|
|
||||||
span: &Span,
|
|
||||||
) -> Result<char, ShellError> {
|
|
||||||
let value = extract_value(name, cols, vals, span)?;
|
|
||||||
|
|
||||||
value
|
value
|
||||||
.into_string("", config)
|
.into_string("", config)
|
||||||
.chars()
|
.chars()
|
||||||
.next()
|
.next()
|
||||||
.ok_or_else(|| ShellError::MissingConfigValue("char to insert".to_string(), *span))
|
.ok_or_else(|| ShellError::MissingConfigValue("char to insert".to_string(), span))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -602,12 +601,8 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_edit_event() {
|
fn test_edit_event() {
|
||||||
let cols = vec!["edit".to_string()];
|
let cols = vec!["edit".to_string()];
|
||||||
let vals = vec![Value::Record {
|
let vals = vec![Value::String {
|
||||||
cols: vec!["cmd".to_string()],
|
val: "Clear".to_string(),
|
||||||
vals: vec![Value::String {
|
|
||||||
val: "Clear".to_string(),
|
|
||||||
span: Span::test_data(),
|
|
||||||
}],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue