Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cursor_shape optional #10289

Merged
merged 3 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions crates/nu-cli/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
77 changes: 44 additions & 33 deletions crates/nu-protocol/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Value>,
pub cursor_shape_vi_insert: NuCursorShape,
pub cursor_shape_vi_normal: NuCursorShape,
pub cursor_shape_emacs: NuCursorShape,
pub cursor_shape_vi_insert: Option<NuCursorShape>,
pub cursor_shape_vi_normal: Option<NuCursorShape>,
pub cursor_shape_emacs: Option<NuCursorShape>,
pub datetime_normal_format: Option<String>,
pub datetime_table_format: Option<String>,
pub error_style: String,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)
Expand All @@ -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!(
Expand All @@ -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!(
Expand All @@ -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!(
Expand Down
6 changes: 3 additions & 3 deletions crates/nu-utils/src/sample_config/default_config.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading