From 5733a134094ebcb392ccc506412af320b2ff446a Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Wed, 26 Apr 2023 21:14:50 +0800 Subject: [PATCH] support blink cursor, and fix underscore's cursorshape (#8990) # Description Close: #8988 Thanks to new crossterm version, nushell can support blink cursor shape. It can be config with the following value: 1. blink_block 2. blink_line 3. blink_underscore And original block, line, underscore will be steady. It also fixes wrong shape of `underscore`. # User-Facing Changes Here is a little breaking change, before the change: `line` cursor shape is blinking line, but after this pr, it will be `steady line`. To make a blink line, we need to change the value to `blink_line`. But I think it's ok, because after the change, we have a good naming convention about the name of shape # Tests + Formatting # After Submitting --- crates/nu-cli/src/repl.rs | 7 ++- crates/nu-protocol/src/config.rs | 48 +++++++++++++++++-- .../src/sample_config/default_config.nu | 6 +-- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 563a9da865..35ff7489b6 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -716,8 +716,11 @@ pub fn evaluate_repl( fn map_nucursorshape_to_cursorshape(shape: NuCursorShape) -> SetCursorStyle { match shape { NuCursorShape::Block => SetCursorStyle::SteadyBlock, - NuCursorShape::UnderScore => SetCursorStyle::DefaultUserShape, - NuCursorShape::Line => SetCursorStyle::BlinkingBar, + NuCursorShape::UnderScore => SetCursorStyle::SteadyUnderScore, + NuCursorShape::Line => SetCursorStyle::SteadyBar, + NuCursorShape::BlinkBlock => SetCursorStyle::BlinkingBlock, + NuCursorShape::BlinkUnderScore => SetCursorStyle::BlinkingUnderScore, + NuCursorShape::BlinkLine => SetCursorStyle::BlinkingBar, } } diff --git a/crates/nu-protocol/src/config.rs b/crates/nu-protocol/src/config.rs index 992179e10a..ac9847bf97 100644 --- a/crates/nu-protocol/src/config.rs +++ b/crates/nu-protocol/src/config.rs @@ -60,6 +60,9 @@ pub enum NuCursorShape { UnderScore, Line, Block, + BlinkUnderScore, + BlinkLine, + BlinkBlock, } #[derive(Serialize, Deserialize, Clone, Debug)] @@ -654,6 +657,9 @@ impl Value { NuCursorShape::Line => "line", NuCursorShape::Block => "block", NuCursorShape::UnderScore => "underscore", + NuCursorShape::BlinkLine => "blink_line", + NuCursorShape::BlinkBlock => "blink_block", + NuCursorShape::BlinkUnderScore => "blink_underscore", }, *$span, ) @@ -680,9 +686,21 @@ impl Value { config.cursor_shape_vi_insert = NuCursorShape::UnderScore; } + "blink_line" => { + config.cursor_shape_vi_insert = + NuCursorShape::BlinkLine; + } + "blink_block" => { + config.cursor_shape_vi_insert = + NuCursorShape::BlinkBlock; + } + "blink_underscore" => { + config.cursor_shape_vi_insert = + NuCursorShape::BlinkUnderScore; + } _ => { invalid!(Some(*span), - "unrecognized $env.config.{key}.{key2} '{val_str}'; expected either 'line', 'block', or 'underscore'" + "unrecognized $env.config.{key}.{key2} '{val_str}'; expected either 'line', 'block', 'underscore', 'blink_line', 'blink_block', or 'blink_underscore'" ); // Reconstruct vals[index] = reconstruct_cursor_shape!( @@ -716,9 +734,21 @@ impl Value { config.cursor_shape_vi_normal = NuCursorShape::UnderScore; } + "blink_line" => { + config.cursor_shape_vi_normal = + NuCursorShape::BlinkLine; + } + "blink_block" => { + config.cursor_shape_vi_normal = + NuCursorShape::BlinkBlock; + } + "blink_underscore" => { + config.cursor_shape_vi_normal = + NuCursorShape::BlinkUnderScore; + } _ => { invalid!(Some(*span), - "unrecognized $env.config.{key}.{key2} '{val_str}'; expected either 'line', 'block', or 'underscore'" + "unrecognized $env.config.{key}.{key2} '{val_str}'; expected either 'line', 'block', 'underscore', 'blink_line', 'blink_block', or 'blink_underscore'" ); // Reconstruct vals[index] = reconstruct_cursor_shape!( @@ -751,9 +781,21 @@ impl Value { config.cursor_shape_emacs = NuCursorShape::UnderScore; } + "blink_line" => { + config.cursor_shape_emacs = + NuCursorShape::BlinkLine; + } + "blink_block" => { + config.cursor_shape_emacs = + NuCursorShape::BlinkBlock; + } + "blink_underscore" => { + config.cursor_shape_emacs = + NuCursorShape::BlinkUnderScore; + } _ => { invalid!(Some(*span), - "unrecognized $env.config.{key}.{key2} '{val_str}'; expected either 'line', 'block', or 'underscore'" + "unrecognized $env.config.{key}.{key2} '{val_str}'; expected either 'line', 'block', 'underscore', 'blink_line', 'blink_block', or 'blink_underscore'" ); // 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 f1b2dcecbd..7d2c70835c 100644 --- a/crates/nu-utils/src/sample_config/default_config.nu +++ b/crates/nu-utils/src/sample_config/default_config.nu @@ -283,9 +283,9 @@ let-env config = { format: "auto" # b, kb, kib, mb, mib, gb, gib, tb, tib, pb, pib, eb, eib, zb, zib, auto } cursor_shape: { - emacs: line # block, underscore, line (line is the default) - vi_insert: block # block, underscore, line (block is the default) - vi_normal: underscore # block, underscore, line (underscore is the default) + 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) } color_config: $dark_theme # if you want a light theme, replace `$dark_theme` to `$light_theme` use_grid_icons: true