From a56cee67e693617d60dbad4e862bc1084ba0ab65 Mon Sep 17 00:00:00 2001 From: Tim Stack Date: Thu, 15 Dec 2022 21:32:50 -0800 Subject: [PATCH] [view-cursor] support for theming of the cursor line (#1088) Add a role for the cursor line so that it can be themed. The role is now optionally applied in textviews, which fixes issues with other textviews having the wrong selection highlight (e.g. filters, breadcrumb menus) Still need to fix some issues with overlays... --- docs/schemas/config-v1.schema.json | 5 +++++ src/base/string_attr_type.hh | 7 ++++--- src/field_overlay_source.cc | 4 ++-- src/lnav.cc | 1 + src/lnav_config.cc | 4 ++++ src/styling.hh | 1 + src/textview_curses.cc | 10 +++++----- src/textview_curses.hh | 1 + src/themes/default-theme.json | 6 ++++++ src/themes/eldar.json | 6 ++++++ src/themes/grayscale.json | 6 ++++++ src/themes/monocai.json | 6 ++++++ src/themes/night-owl.json | 6 ++++++ src/themes/solarized-dark.json | 6 ++++++ src/themes/solarized-light.json | 6 ++++++ src/view_curses.cc | 2 ++ 16 files changed, 67 insertions(+), 10 deletions(-) diff --git a/docs/schemas/config-v1.schema.json b/docs/schemas/config-v1.schema.json index 736de5e3..e2285cc3 100644 --- a/docs/schemas/config-v1.schema.json +++ b/docs/schemas/config-v1.schema.json @@ -284,6 +284,11 @@ "title": "/ui/theme-defs//styles/hidden", "$ref": "#/definitions/style" }, + "cursor-line": { + "description": "Styling for the cursor line in the main view", + "title": "/ui/theme-defs//styles/cursor-line", + "$ref": "#/definitions/style" + }, "adjusted-time": { "description": "Styling for timestamps that have been adjusted", "title": "/ui/theme-defs//styles/adjusted-time", diff --git a/src/base/string_attr_type.hh b/src/base/string_attr_type.hh index fe1b987e..22da3053 100644 --- a/src/base/string_attr_type.hh +++ b/src/base/string_attr_type.hh @@ -54,6 +54,7 @@ enum class role_t : int32_t { VCR_WARNING, /*< A warning message. */ VCR_ALT_ROW, /*< Highlight for alternating rows in a list */ VCR_HIDDEN, + VCR_CURSOR_LINE, VCR_ADJUSTED_TIME, VCR_SKEWED_TIME, VCR_OFFSET_TIME, @@ -145,9 +146,9 @@ struct text_attrs { bool operator==(const text_attrs& other) const { - return this->ta_attrs == other.ta_attrs && - this->ta_fg_color == other.ta_fg_color && - this->ta_bg_color == other.ta_bg_color; + return this->ta_attrs == other.ta_attrs + && this->ta_fg_color == other.ta_fg_color + && this->ta_bg_color == other.ta_bg_color; } int32_t ta_attrs{0}; diff --git a/src/field_overlay_source.cc b/src/field_overlay_source.cc index 03d17688..d731706b 100644 --- a/src/field_overlay_source.cc +++ b/src/field_overlay_source.cc @@ -72,7 +72,7 @@ field_overlay_source::build_field_lines(const listview_curses& lv) display = display || this->fos_contexts.top().c_show; } - this->build_meta_line(lv, this->fos_lines, lv.get_selection()); + this->build_meta_line(lv, this->fos_lines, lv.get_top()); if (!display) { return; @@ -546,7 +546,7 @@ field_overlay_source::list_value_for_overlay(const listview_curses& lv, vis_line_t row, attr_line_t& value_out) { - if (y <= 0) { + if (y == 0) { this->build_field_lines(lv); return false; } diff --git a/src/lnav.cc b/src/lnav.cc index 6dae5ae1..6483604a 100644 --- a/src/lnav.cc +++ b/src/lnav.cc @@ -1337,6 +1337,7 @@ looper() vis_line_t(-(rlc->get_height() + 3))); lnav_data.ld_views[lpc].set_scroll_action(sb); lnav_data.ld_views[lpc].set_search_action(update_hits); + lnav_data.ld_views[lpc].tc_cursor_role = role_t::VCR_CURSOR_LINE; lnav_data.ld_views[lpc].tc_state_event_handler = event_handler; } diff --git a/src/lnav_config.cc b/src/lnav_config.cc index 6dc32e4c..b5472883 100644 --- a/src/lnav_config.cc +++ b/src/lnav_config.cc @@ -603,6 +603,10 @@ static const struct json_path_container theme_styles_handlers = { .with_description("Styling for hidden fields in logs") .for_child(&lnav_theme::lt_style_hidden) .with_children(style_config_handlers), + yajlpp::property_handler("cursor-line") + .with_description("Styling for the cursor line in the main view") + .for_child(&lnav_theme::lt_style_cursor_line) + .with_children(style_config_handlers), yajlpp::property_handler("adjusted-time") .with_description("Styling for timestamps that have been adjusted") .for_child(&lnav_theme::lt_style_adjusted_time) diff --git a/src/styling.hh b/src/styling.hh index 540d3c72..001383a5 100644 --- a/src/styling.hh +++ b/src/styling.hh @@ -173,6 +173,7 @@ struct lnav_theme { positioned_property lt_style_disabled_focused; positioned_property lt_style_scrollbar; positioned_property lt_style_hidden; + positioned_property lt_style_cursor_line; positioned_property lt_style_adjusted_time; positioned_property lt_style_skewed_time; positioned_property lt_style_offset_time; diff --git a/src/textview_curses.cc b/src/textview_curses.cc index 47092f8d..2fa0049d 100644 --- a/src/textview_curses.cc +++ b/src/textview_curses.cc @@ -458,11 +458,11 @@ textview_curses::textview_value_for_row(vis_line_t row, attr_line_t& value_out) format_name = format_attr_opt.value().get(); } - if (this->is_selectable() && row == this->get_selection()) { - sa.emplace_back( - line_range{orig_line.lr_start, -1}, - VC_STYLE.value(text_attrs{ - A_BOLD | A_DIM | A_UNDERLINE, COLOR_CYAN, COLOR_RED})); + if (this->is_selectable() && row == this->get_selection() + && this->tc_cursor_role) + { + sa.emplace_back(line_range{orig_line.lr_start, -1}, + VC_ROLE.value(this->tc_cursor_role.value())); } for (auto& tc_highlight : this->tc_highlights) { diff --git a/src/textview_curses.hh b/src/textview_curses.hh index 51bb4fe6..aadbbe6b 100644 --- a/src/textview_curses.hh +++ b/src/textview_curses.hh @@ -702,6 +702,7 @@ public: std::function tc_state_event_handler; + nonstd::optional tc_cursor_role; protected: class grep_highlighter { public: diff --git a/src/themes/default-theme.json b/src/themes/default-theme.json index b23b8120..5448ed10 100644 --- a/src/themes/default-theme.json +++ b/src/themes/default-theme.json @@ -35,6 +35,12 @@ "color": "Yellow", "bold": true }, + "cursor-line": { + "color": "Cyan", + "background-color": "Red", + "bold": true, + "underline": true + }, "adjusted-time": { "color": "Maroon" }, diff --git a/src/themes/eldar.json b/src/themes/eldar.json index f063b0dc..f46b6cf8 100644 --- a/src/themes/eldar.json +++ b/src/themes/eldar.json @@ -44,6 +44,12 @@ "color": "$yellow", "bold": true }, + "cursor-line": { + "color": "$cyan", + "background-color": "$red", + "bold": true, + "underline": true + }, "adjusted-time": { "color": "$magenta" }, diff --git a/src/themes/grayscale.json b/src/themes/grayscale.json index 887736a0..4dcbe15b 100644 --- a/src/themes/grayscale.json +++ b/src/themes/grayscale.json @@ -45,6 +45,12 @@ "color": "$yellow", "bold": true }, + "cursor-line": { + "color": "$cyan", + "background-color": "$red", + "bold": true, + "underline": true + }, "adjusted-time": { "color": "$magenta" }, diff --git a/src/themes/monocai.json b/src/themes/monocai.json index eb512805..6edb5abc 100644 --- a/src/themes/monocai.json +++ b/src/themes/monocai.json @@ -47,6 +47,12 @@ "color": "$yellow", "bold": true }, + "cursor-line": { + "color": "$cyan", + "background-color": "$red", + "bold": true, + "underline": true + }, "adjusted-time": { "color": "$magenta" }, diff --git a/src/themes/night-owl.json b/src/themes/night-owl.json index d3d3a9bc..a4210c91 100644 --- a/src/themes/night-owl.json +++ b/src/themes/night-owl.json @@ -44,6 +44,12 @@ "color": "$yellow", "bold": true }, + "cursor-line": { + "color": "$cyan", + "background-color": "$red", + "bold": true, + "underline": true + }, "adjusted-time": { "color": "$magenta" }, diff --git a/src/themes/solarized-dark.json b/src/themes/solarized-dark.json index 3ff21a97..1590de04 100644 --- a/src/themes/solarized-dark.json +++ b/src/themes/solarized-dark.json @@ -53,6 +53,12 @@ "color": "$yellow", "bold": true }, + "cursor-line": { + "color": "$cyan", + "background-color": "$red", + "bold": true, + "underline": true + }, "adjusted-time": { "color": "$magenta" }, diff --git a/src/themes/solarized-light.json b/src/themes/solarized-light.json index 08737a60..3e7c5750 100644 --- a/src/themes/solarized-light.json +++ b/src/themes/solarized-light.json @@ -53,6 +53,12 @@ "color": "$yellow", "bold": true }, + "cursor-line": { + "color": "$cyan", + "background-color": "$red", + "bold": true, + "underline": true + }, "adjusted-time": { "color": "$magenta" }, diff --git a/src/view_curses.cc b/src/view_curses.cc index 5788eab9..d98f14ca 100644 --- a/src/view_curses.cc +++ b/src/view_curses.cc @@ -732,6 +732,8 @@ view_colors::init_roles(const lnav_theme& lt, = this->to_attrs(lt, lt.lt_style_alt_text, reporter); this->vc_role_attrs[lnav::enums::to_underlying(role_t::VCR_HIDDEN)] = this->to_attrs(lt, lt.lt_style_hidden, reporter); + this->vc_role_attrs[lnav::enums::to_underlying(role_t::VCR_CURSOR_LINE)] + = this->to_attrs(lt, lt.lt_style_cursor_line, reporter); this->vc_role_attrs[lnav::enums::to_underlying(role_t::VCR_ADJUSTED_TIME)] = this->to_attrs(lt, lt.lt_style_adjusted_time, reporter); this->vc_role_attrs[lnav::enums::to_underlying(role_t::VCR_SKEWED_TIME)]