1
1
mirror of https://github.com/tstack/lnav.git synced 2024-08-16 16:30:25 +03:00

[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...
This commit is contained in:
Tim Stack 2022-12-15 21:32:50 -08:00
parent 9a323ffe84
commit a56cee67e6
16 changed files with 67 additions and 10 deletions

View File

@ -284,6 +284,11 @@
"title": "/ui/theme-defs/<theme_name>/styles/hidden",
"$ref": "#/definitions/style"
},
"cursor-line": {
"description": "Styling for the cursor line in the main view",
"title": "/ui/theme-defs/<theme_name>/styles/cursor-line",
"$ref": "#/definitions/style"
},
"adjusted-time": {
"description": "Styling for timestamps that have been adjusted",
"title": "/ui/theme-defs/<theme_name>/styles/adjusted-time",

View File

@ -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};

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)

View File

@ -173,6 +173,7 @@ struct lnav_theme {
positioned_property<style_config> lt_style_disabled_focused;
positioned_property<style_config> lt_style_scrollbar;
positioned_property<style_config> lt_style_hidden;
positioned_property<style_config> lt_style_cursor_line;
positioned_property<style_config> lt_style_adjusted_time;
positioned_property<style_config> lt_style_skewed_time;
positioned_property<style_config> lt_style_offset_time;

View File

@ -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) {

View File

@ -702,6 +702,7 @@ public:
std::function<void(textview_curses&)> tc_state_event_handler;
nonstd::optional<role_t> tc_cursor_role;
protected:
class grep_highlighter {
public:

View File

@ -35,6 +35,12 @@
"color": "Yellow",
"bold": true
},
"cursor-line": {
"color": "Cyan",
"background-color": "Red",
"bold": true,
"underline": true
},
"adjusted-time": {
"color": "Maroon"
},

View File

@ -44,6 +44,12 @@
"color": "$yellow",
"bold": true
},
"cursor-line": {
"color": "$cyan",
"background-color": "$red",
"bold": true,
"underline": true
},
"adjusted-time": {
"color": "$magenta"
},

View File

@ -45,6 +45,12 @@
"color": "$yellow",
"bold": true
},
"cursor-line": {
"color": "$cyan",
"background-color": "$red",
"bold": true,
"underline": true
},
"adjusted-time": {
"color": "$magenta"
},

View File

@ -47,6 +47,12 @@
"color": "$yellow",
"bold": true
},
"cursor-line": {
"color": "$cyan",
"background-color": "$red",
"bold": true,
"underline": true
},
"adjusted-time": {
"color": "$magenta"
},

View File

@ -44,6 +44,12 @@
"color": "$yellow",
"bold": true
},
"cursor-line": {
"color": "$cyan",
"background-color": "$red",
"bold": true,
"underline": true
},
"adjusted-time": {
"color": "$magenta"
},

View File

@ -53,6 +53,12 @@
"color": "$yellow",
"bold": true
},
"cursor-line": {
"color": "$cyan",
"background-color": "$red",
"bold": true,
"underline": true
},
"adjusted-time": {
"color": "$magenta"
},

View File

@ -53,6 +53,12 @@
"color": "$yellow",
"bold": true
},
"cursor-line": {
"color": "$cyan",
"background-color": "$red",
"bold": true,
"underline": true
},
"adjusted-time": {
"color": "$magenta"
},

View File

@ -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)]