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

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

Merged
merged 2 commits into from
Sep 29, 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
7 changes: 0 additions & 7 deletions crates/nu-explore/src/commands/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ struct TableSettings {
selected_cell_s: Option<Style>,
selected_row_s: Option<Style>,
selected_column_s: Option<Style>,
show_cursor: Option<bool>,
padding_column_left: Option<usize>,
padding_column_right: Option<usize>,
padding_index_left: Option<usize>,
Expand Down Expand Up @@ -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_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 row", "table.selected_row", default_color_list()),
ConfigOption::new(":table group", "Color of selected column", "table.selected_column", default_color_list()),
Expand Down Expand Up @@ -164,10 +161,6 @@ impl ViewCommand for TableCmd {
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 {
view.set_style_selected_cell(style);
}
Expand Down
3 changes: 0 additions & 3 deletions crates/nu-explore/src/explore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ fn prepare_default_config(config: &mut HashMap<String, Value>) {

const TABLE_LINE_SHIFT: bool = true;

const TABLE_SELECT_CURSOR: bool = true;

const TABLE_SELECT_CELL: Style = color(None, None);

const TABLE_SELECT_ROW: Style = color(None, None);
Expand Down Expand Up @@ -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_row", TABLE_SELECT_ROW);
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_bottom", TABLE_LINE_HEADER_BOTTOM);
insert_bool(&mut hm, "line_shift", TABLE_LINE_SHIFT);
Expand Down
30 changes: 15 additions & 15 deletions crates/nu-explore/src/views/record/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ impl<'a> RecordView<'a> {
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) {
self.theme.table.header_top = b;
}
Expand Down Expand Up @@ -682,27 +678,33 @@ fn convert_records_to_string(
}

fn highlight_cell(f: &mut Frame, area: Rect, info: ElementInfo, theme: &CursorStyle) {
// highlight selected column
if let Some(style) = theme.selected_column {
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);
f.render_widget(highlight_block.clone(), area);
}

// highlight selected row
if let Some(style) = theme.selected_row {
let highlight_block = Block::default().style(nu_style_to_tui(style));
let area = Rect::new(area.x, info.area.y, area.width, 1);
f.render_widget(highlight_block.clone(), area);
}

if let Some(style) = theme.selected_cell {
let highlight_block = Block::default().style(nu_style_to_tui(style));
let area = Rect::new(info.area.x, info.area.y, info.area.width, 1);
f.render_widget(highlight_block.clone(), area);
}

if theme.show_cursor {
f.set_cursor(info.area.x, info.area.y);
}
// highlight selected cell
let cell_style = match theme.selected_cell {
Some(s) => s,
None => {
let mut style = nu_ansi_term::Style::new();
// light blue chosen somewhat arbitrarily, looks OK but I'm not set on it
style.background = Some(nu_ansi_term::Color::LightBlue);
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 {
Expand Down Expand Up @@ -852,7 +854,6 @@ fn theme_from_config(config: &ConfigMap) -> TableTheme {
theme.cursor.selected_cell = colors.get("selected_cell").cloned();
theme.cursor.selected_row = colors.get("selected_row").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_bottom = config_get_bool(config, "line_head_bottom", true);
Expand Down Expand Up @@ -896,5 +897,4 @@ struct CursorStyle {
selected_cell: Option<NuStyle>,
selected_column: Option<NuStyle>,
selected_row: Option<NuStyle>,
show_cursor: bool,
}
3 changes: 1 addition & 2 deletions crates/nu-utils/src/sample_config/default_config.nu
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@ $env.config = {
},
table: {
split_line: {fg: "#404040"},
selected_cell: {},
selected_cell: {bg: light_blue},
selected_row: {},
selected_column: {},
show_cursor: true,
line_head_top: true,
line_head_bottom: true,
line_shift: true,
Expand Down