mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
default keybindings command (#943)
This commit is contained in:
parent
73dcec8ea1
commit
abaeffab91
5 changed files with 86 additions and 2 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -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",
|
||||
|
|
|
@ -186,6 +186,7 @@ pub fn create_default_context(cwd: impl AsRef<Path>) -> EngineState {
|
|||
AnsiGradient,
|
||||
AnsiStrip,
|
||||
Clear,
|
||||
DefaultKeybindings,
|
||||
Input,
|
||||
InputKeys,
|
||||
Keybindings,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Example> {
|
||||
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<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
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())
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue