diff --git a/Cargo.lock b/Cargo.lock index 7e23f9b623..4ac24586d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3277,7 +3277,7 @@ dependencies = [ [[package]] name = "reedline" version = "0.2.0" -source = "git+https://github.com/nushell/reedline?branch=main#e4cec995262fc85fab3e08cad267e28a3da60460" +source = "git+https://github.com/nushell/reedline?branch=main#18f538361296c2b3e92b2efa622db8ab4528a937" dependencies = [ "chrono", "crossterm", diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index c1f4b1b747..28b94edb63 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -186,6 +186,7 @@ pub fn create_default_context(cwd: impl AsRef) -> EngineState { AnsiGradient, AnsiStrip, Clear, + DefaultKeybindings, Input, InputKeys, Keybindings, diff --git a/crates/nu-command/src/platform/mod.rs b/crates/nu-command/src/platform/mod.rs index 5cbc35c4b2..e42fa45ad3 100644 --- a/crates/nu-command/src/platform/mod.rs +++ b/crates/nu-command/src/platform/mod.rs @@ -14,6 +14,6 @@ pub use dir_info::{DirBuilder, DirInfo, FileInfo}; pub use du::Du; pub use input::Input; pub use kill::Kill; -pub use reedline_commands::{InputKeys, Keybindings, ListKeybindings}; +pub use reedline_commands::{DefaultKeybindings, InputKeys, Keybindings, ListKeybindings}; pub use sleep::Sleep; pub use term_size::TermSize; diff --git a/crates/nu-command/src/platform/reedline_commands/default_keybindings.rs b/crates/nu-command/src/platform/reedline_commands/default_keybindings.rs new file mode 100644 index 0000000000..faf4420088 --- /dev/null +++ b/crates/nu-command/src/platform/reedline_commands/default_keybindings.rs @@ -0,0 +1,81 @@ +use nu_protocol::{ + ast::Call, + engine::{Command, EngineState, Stack}, + Category, Example, IntoPipelineData, PipelineData, Signature, Value, +}; +use reedline::get_reedline_default_keybindings; + +#[derive(Clone)] +pub struct DefaultKeybindings; + +impl Command for DefaultKeybindings { + fn name(&self) -> &str { + "keybindings default" + } + + fn signature(&self) -> Signature { + Signature::build(self.name()).category(Category::Platform) + } + + fn usage(&self) -> &str { + "List default keybindings" + } + + fn examples(&self) -> Vec { + vec![Example { + description: "Get list with default keybindings", + example: "keybindings default", + result: None, + }] + } + + fn run( + &self, + _engine_state: &EngineState, + _stack: &mut Stack, + call: &Call, + _input: PipelineData, + ) -> Result { + let records = get_reedline_default_keybindings() + .into_iter() + .map(|(mode, modifier, code, event)| { + let mode = Value::String { + val: mode, + span: call.head, + }; + + let modifier = Value::String { + val: modifier, + span: call.head, + }; + + let code = Value::String { + val: code, + span: call.head, + }; + + let event = Value::String { + val: event, + span: call.head, + }; + + Value::Record { + cols: vec![ + "mode".to_string(), + "modifier".to_string(), + "code".to_string(), + "event".to_string(), + ], + vals: vec![mode, modifier, code, event], + span: call.head, + } + }) + .collect(); + + Ok(Value::List { + vals: records, + span: call.head, + } + .into_pipeline_data()) + } +} diff --git a/crates/nu-command/src/platform/reedline_commands/mod.rs b/crates/nu-command/src/platform/reedline_commands/mod.rs index 0f3e1247bb..18c18bb3c8 100644 --- a/crates/nu-command/src/platform/reedline_commands/mod.rs +++ b/crates/nu-command/src/platform/reedline_commands/mod.rs @@ -1,7 +1,9 @@ mod command; +mod default_keybindings; mod input_keys; mod list_keybindings; pub use command::Keybindings; +pub use default_keybindings::DefaultKeybindings; pub use input_keys::InputKeys; pub use list_keybindings::ListKeybindings;