explore: highlight selected cell using background colour instead of cursor (#10533)

More incremental `explore` improvements!

This PR removes the `show_cursor` config from the `explore` command, in
favour of always using the background colour to highlight the selected
cell. I believe this is a better default and I'd like to remove the
`show_cursor` functionality entirely as part of the effort to simplify
`explore`.

The style for selected cells is still configurable. I went with light
blue for the default background colour, it looks OK to me.

## Before:

![Screenshot from 2023-09-27
08-51-03](https://github.com/nushell/nushell/assets/26268125/798636be-a4ea-467f-b852-c0e929e4aa9d)


## After:

![Screenshot from 2023-09-27
08-50-59](https://github.com/nushell/nushell/assets/26268125/c88662e7-05b5-42a7-bf30-b03c70fba79d)
This commit is contained in:
Reilly Wood 2023-09-28 18:17:56 -07:00 committed by GitHub
parent dc739f703a
commit 78d0e1d0b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 27 deletions

View File

@ -33,7 +33,6 @@ struct TableSettings {
selected_cell_s: Option<Style>, selected_cell_s: Option<Style>,
selected_row_s: Option<Style>, selected_row_s: Option<Style>,
selected_column_s: Option<Style>, selected_column_s: Option<Style>,
show_cursor: Option<bool>,
padding_column_left: Option<usize>, padding_column_left: Option<usize>,
padding_column_right: Option<usize>, padding_column_right: Option<usize>,
padding_index_left: Option<usize>, padding_index_left: Option<usize>,
@ -97,8 +96,6 @@ impl ViewCommand for TableCmd {
ConfigOption::boolean(":table group", "Lines are lines", "table.line_shift"), ConfigOption::boolean(":table group", "Lines are lines", "table.line_shift"),
ConfigOption::boolean(":table group", "Lines are lines", "table.line_index"), ConfigOption::boolean(":table group", "Lines are lines", "table.line_index"),
ConfigOption::boolean(":table group", "Show cursor", "table.show_cursor"),
ConfigOption::new(":table group", "Color of selected cell", "table.selected_cell", default_color_list()), ConfigOption::new(":table group", "Color of selected cell", "table.selected_cell", default_color_list()),
ConfigOption::new(":table group", "Color of selected row", "table.selected_row", default_color_list()), ConfigOption::new(":table group", "Color of selected row", "table.selected_row", default_color_list()),
ConfigOption::new(":table group", "Color of selected column", "table.selected_column", default_color_list()), ConfigOption::new(":table group", "Color of selected column", "table.selected_column", default_color_list()),
@ -164,10 +161,6 @@ impl ViewCommand for TableCmd {
view.set_line_trailing(true); view.set_line_trailing(true);
} }
if self.settings.show_cursor.unwrap_or(false) {
view.show_cursor(true);
}
if let Some(style) = self.settings.selected_cell_s { if let Some(style) = self.settings.selected_cell_s {
view.set_style_selected_cell(style); view.set_style_selected_cell(style);
} }

View File

@ -211,8 +211,6 @@ fn prepare_default_config(config: &mut HashMap<String, Value>) {
const TABLE_LINE_SHIFT: bool = true; const TABLE_LINE_SHIFT: bool = true;
const TABLE_SELECT_CURSOR: bool = true;
const TABLE_SELECT_CELL: Style = color(None, None); const TABLE_SELECT_CELL: Style = color(None, None);
const TABLE_SELECT_ROW: Style = color(None, None); const TABLE_SELECT_ROW: Style = color(None, None);
@ -251,7 +249,6 @@ fn prepare_default_config(config: &mut HashMap<String, Value>) {
insert_style(&mut hm, "selected_cell", TABLE_SELECT_CELL); insert_style(&mut hm, "selected_cell", TABLE_SELECT_CELL);
insert_style(&mut hm, "selected_row", TABLE_SELECT_ROW); insert_style(&mut hm, "selected_row", TABLE_SELECT_ROW);
insert_style(&mut hm, "selected_column", TABLE_SELECT_COLUMN); insert_style(&mut hm, "selected_column", TABLE_SELECT_COLUMN);
insert_bool(&mut hm, "cursor", TABLE_SELECT_CURSOR);
insert_bool(&mut hm, "line_head_top", TABLE_LINE_HEADER_TOP); insert_bool(&mut hm, "line_head_top", TABLE_LINE_HEADER_TOP);
insert_bool(&mut hm, "line_head_bottom", TABLE_LINE_HEADER_BOTTOM); insert_bool(&mut hm, "line_head_bottom", TABLE_LINE_HEADER_BOTTOM);
insert_bool(&mut hm, "line_shift", TABLE_LINE_SHIFT); insert_bool(&mut hm, "line_shift", TABLE_LINE_SHIFT);

View File

@ -75,10 +75,6 @@ impl<'a> RecordView<'a> {
self.theme.cursor.selected_column = Some(style) self.theme.cursor.selected_column = Some(style)
} }
pub fn show_cursor(&mut self, b: bool) {
self.theme.cursor.show_cursor = b;
}
pub fn set_line_head_top(&mut self, b: bool) { pub fn set_line_head_top(&mut self, b: bool) {
self.theme.table.header_top = b; self.theme.table.header_top = b;
} }
@ -682,27 +678,33 @@ fn convert_records_to_string(
} }
fn highlight_cell(f: &mut Frame, area: Rect, info: ElementInfo, theme: &CursorStyle) { fn highlight_cell(f: &mut Frame, area: Rect, info: ElementInfo, theme: &CursorStyle) {
// highlight selected column
if let Some(style) = theme.selected_column { if let Some(style) = theme.selected_column {
let highlight_block = Block::default().style(nu_style_to_tui(style)); let highlight_block = Block::default().style(nu_style_to_tui(style));
let area = Rect::new(info.area.x, area.y, info.area.width, area.height); let area = Rect::new(info.area.x, area.y, info.area.width, area.height);
f.render_widget(highlight_block.clone(), area); f.render_widget(highlight_block.clone(), area);
} }
// highlight selected row
if let Some(style) = theme.selected_row { if let Some(style) = theme.selected_row {
let highlight_block = Block::default().style(nu_style_to_tui(style)); let highlight_block = Block::default().style(nu_style_to_tui(style));
let area = Rect::new(area.x, info.area.y, area.width, 1); let area = Rect::new(area.x, info.area.y, area.width, 1);
f.render_widget(highlight_block.clone(), area); f.render_widget(highlight_block.clone(), area);
} }
if let Some(style) = theme.selected_cell { // highlight selected cell
let highlight_block = Block::default().style(nu_style_to_tui(style)); let cell_style = match theme.selected_cell {
let area = Rect::new(info.area.x, info.area.y, info.area.width, 1); Some(s) => s,
f.render_widget(highlight_block.clone(), area); None => {
} let mut style = nu_ansi_term::Style::new();
// light blue chosen somewhat arbitrarily, looks OK but I'm not set on it
if theme.show_cursor { style.background = Some(nu_ansi_term::Color::LightBlue);
f.set_cursor(info.area.x, info.area.y); style
} }
};
let highlight_block = Block::default().style(nu_style_to_tui(cell_style));
let area = Rect::new(info.area.x, info.area.y, info.area.width, 1);
f.render_widget(highlight_block.clone(), area)
} }
fn build_last_value(v: &RecordView) -> Value { fn build_last_value(v: &RecordView) -> Value {
@ -852,7 +854,6 @@ fn theme_from_config(config: &ConfigMap) -> TableTheme {
theme.cursor.selected_cell = colors.get("selected_cell").cloned(); theme.cursor.selected_cell = colors.get("selected_cell").cloned();
theme.cursor.selected_row = colors.get("selected_row").cloned(); theme.cursor.selected_row = colors.get("selected_row").cloned();
theme.cursor.selected_column = colors.get("selected_column").cloned(); theme.cursor.selected_column = colors.get("selected_column").cloned();
theme.cursor.show_cursor = config_get_bool(config, "show_cursor", true);
theme.table.header_top = config_get_bool(config, "line_head_top", true); theme.table.header_top = config_get_bool(config, "line_head_top", true);
theme.table.header_bottom = config_get_bool(config, "line_head_bottom", true); theme.table.header_bottom = config_get_bool(config, "line_head_bottom", true);
@ -896,5 +897,4 @@ struct CursorStyle {
selected_cell: Option<NuStyle>, selected_cell: Option<NuStyle>,
selected_column: Option<NuStyle>, selected_column: Option<NuStyle>,
selected_row: Option<NuStyle>, selected_row: Option<NuStyle>,
show_cursor: bool,
} }

View File

@ -189,10 +189,9 @@ $env.config = {
}, },
table: { table: {
split_line: {fg: "#404040"}, split_line: {fg: "#404040"},
selected_cell: {}, selected_cell: {bg: light_blue},
selected_row: {}, selected_row: {},
selected_column: {}, selected_column: {},
show_cursor: true,
line_head_top: true, line_head_top: true,
line_head_bottom: true, line_head_bottom: true,
line_shift: true, line_shift: true,