diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 4157784483d2..b27d84961cb5 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -235,13 +235,15 @@ pub fn evaluate_repl( // Find the configured cursor shapes for each mode let cursor_config = CursorConfig { - vi_insert: Some(map_nucursorshape_to_cursorshape( - config.cursor_shape_vi_insert, - )), - vi_normal: Some(map_nucursorshape_to_cursorshape( - config.cursor_shape_vi_normal, - )), - emacs: Some(map_nucursorshape_to_cursorshape(config.cursor_shape_emacs)), + vi_insert: config + .cursor_shape_vi_insert + .map(map_nucursorshape_to_cursorshape), + vi_normal: config + .cursor_shape_vi_normal + .map(map_nucursorshape_to_cursorshape), + emacs: config + .cursor_shape_emacs + .map(map_nucursorshape_to_cursorshape), }; perf( "get config/cursor config", diff --git a/crates/nu-protocol/src/config.rs b/crates/nu-protocol/src/config.rs index 9d30ab3ee4d7..40b229b9934f 100644 --- a/crates/nu-protocol/src/config.rs +++ b/crates/nu-protocol/src/config.rs @@ -108,9 +108,9 @@ pub struct Config { pub show_clickable_links_in_ls: bool, pub render_right_prompt_on_last_line: bool, pub explore: HashMap, - pub cursor_shape_vi_insert: NuCursorShape, - pub cursor_shape_vi_normal: NuCursorShape, - pub cursor_shape_emacs: NuCursorShape, + pub cursor_shape_vi_insert: Option, + pub cursor_shape_vi_normal: Option, + pub cursor_shape_emacs: Option, pub datetime_normal_format: Option, pub datetime_table_format: Option, pub error_style: String, @@ -156,9 +156,9 @@ impl Default for Config { filesize_metric: false, filesize_format: "auto".into(), - cursor_shape_emacs: NuCursorShape::Line, - cursor_shape_vi_insert: NuCursorShape::Block, - cursor_shape_vi_normal: NuCursorShape::UnderScore, + cursor_shape_emacs: None, + cursor_shape_vi_insert: None, + cursor_shape_vi_normal: None, color_config: HashMap::new(), use_grid_icons: true, @@ -683,12 +683,13 @@ impl Value { ($name:expr, $span:expr) => { Value::string( match $name { - NuCursorShape::Line => "line", - NuCursorShape::Block => "block", - NuCursorShape::UnderScore => "underscore", - NuCursorShape::BlinkLine => "blink_line", - NuCursorShape::BlinkBlock => "blink_block", - NuCursorShape::BlinkUnderScore => "blink_underscore", + Some(NuCursorShape::Line) => "line", + Some(NuCursorShape::Block) => "block", + Some(NuCursorShape::UnderScore) => "underscore", + Some(NuCursorShape::BlinkLine) => "blink_line", + Some(NuCursorShape::BlinkBlock) => "blink_block", + Some(NuCursorShape::BlinkUnderScore) => "blink_underscore", + None => "inherit", }, $span, ) @@ -706,31 +707,34 @@ impl Value { match val_str.as_ref() { "line" => { config.cursor_shape_vi_insert = - NuCursorShape::Line; + Some(NuCursorShape::Line); } "block" => { config.cursor_shape_vi_insert = - NuCursorShape::Block; + Some(NuCursorShape::Block); } "underscore" => { config.cursor_shape_vi_insert = - NuCursorShape::UnderScore; + Some(NuCursorShape::UnderScore); } "blink_line" => { config.cursor_shape_vi_insert = - NuCursorShape::BlinkLine; + Some(NuCursorShape::BlinkLine); } "blink_block" => { config.cursor_shape_vi_insert = - NuCursorShape::BlinkBlock; + Some(NuCursorShape::BlinkBlock); } "blink_underscore" => { config.cursor_shape_vi_insert = - NuCursorShape::BlinkUnderScore; + Some(NuCursorShape::BlinkUnderScore); + } + "inherit" => { + config.cursor_shape_vi_insert = None; } _ => { invalid!(Some(span), - "unrecognized $env.config.{key}.{key2} '{val_str}'; expected either 'line', 'block', 'underscore', 'blink_line', 'blink_block', or 'blink_underscore'" + "unrecognized $env.config.{key}.{key2} '{val_str}'; expected either 'line', 'block', 'underscore', 'blink_line', 'blink_block', 'blink_underscore' or 'inherit'" ); // Reconstruct vals[index] = reconstruct_cursor_shape!( @@ -754,31 +758,34 @@ impl Value { match val_str.as_ref() { "line" => { config.cursor_shape_vi_normal = - NuCursorShape::Line; + Some(NuCursorShape::Line); } "block" => { config.cursor_shape_vi_normal = - NuCursorShape::Block; + Some(NuCursorShape::Block); } "underscore" => { config.cursor_shape_vi_normal = - NuCursorShape::UnderScore; + Some(NuCursorShape::UnderScore); } "blink_line" => { config.cursor_shape_vi_normal = - NuCursorShape::BlinkLine; + Some(NuCursorShape::BlinkLine); } "blink_block" => { config.cursor_shape_vi_normal = - NuCursorShape::BlinkBlock; + Some(NuCursorShape::BlinkBlock); } "blink_underscore" => { config.cursor_shape_vi_normal = - NuCursorShape::BlinkUnderScore; + Some(NuCursorShape::BlinkUnderScore); + } + "inherit" => { + config.cursor_shape_vi_normal = None; } _ => { invalid!(Some(span), - "unrecognized $env.config.{key}.{key2} '{val_str}'; expected either 'line', 'block', 'underscore', 'blink_line', 'blink_block', or 'blink_underscore'" + "unrecognized $env.config.{key}.{key2} '{val_str}'; expected either 'line', 'block', 'underscore', 'blink_line', 'blink_block', 'blink_underscore' or 'inherit'" ); // Reconstruct vals[index] = reconstruct_cursor_shape!( @@ -801,31 +808,35 @@ impl Value { let val_str = v.to_lowercase(); match val_str.as_ref() { "line" => { - config.cursor_shape_emacs = NuCursorShape::Line; + config.cursor_shape_emacs = + Some(NuCursorShape::Line); } "block" => { config.cursor_shape_emacs = - NuCursorShape::Block; + Some(NuCursorShape::Block); } "underscore" => { config.cursor_shape_emacs = - NuCursorShape::UnderScore; + Some(NuCursorShape::UnderScore); } "blink_line" => { config.cursor_shape_emacs = - NuCursorShape::BlinkLine; + Some(NuCursorShape::BlinkLine); } "blink_block" => { config.cursor_shape_emacs = - NuCursorShape::BlinkBlock; + Some(NuCursorShape::BlinkBlock); } "blink_underscore" => { config.cursor_shape_emacs = - NuCursorShape::BlinkUnderScore; + Some(NuCursorShape::BlinkUnderScore); + } + "inherit" => { + config.cursor_shape_emacs = None; } _ => { invalid!(Some(span), - "unrecognized $env.config.{key}.{key2} '{val_str}'; expected either 'line', 'block', 'underscore', 'blink_line', 'blink_block', or 'blink_underscore'" + "unrecognized $env.config.{key}.{key2} '{val_str}'; expected either 'line', 'block', 'underscore', 'blink_line', 'blink_block', 'blink_underscore' or 'inherit'" ); // Reconstruct vals[index] = reconstruct_cursor_shape!( diff --git a/crates/nu-utils/src/sample_config/default_config.nu b/crates/nu-utils/src/sample_config/default_config.nu index 75a19cece4b4..42ac3e41fc83 100644 --- a/crates/nu-utils/src/sample_config/default_config.nu +++ b/crates/nu-utils/src/sample_config/default_config.nu @@ -224,9 +224,9 @@ $env.config = { } cursor_shape: { - emacs: line # block, underscore, line, blink_block, blink_underscore, blink_line (line is the default) - vi_insert: block # block, underscore, line , blink_block, blink_underscore, blink_line (block is the default) - vi_normal: underscore # block, underscore, line, blink_block, blink_underscore, blink_line (underscore is the default) + emacs: line # block, underscore, line, blink_block, blink_underscore, blink_line, inherit to skip setting cursor shape (line is the default) + vi_insert: block # block, underscore, line, blink_block, blink_underscore, blink_line, inherit to skip setting cursor shape (block is the default) + vi_normal: underscore # block, underscore, line, blink_block, blink_underscore, blink_line, inherit to skip setting cursor shape (underscore is the default) } color_config: $dark_theme # if you want a more interesting theme, you can replace the empty record with `$dark_theme`, `$light_theme` or another custom record