Skip to content

Commit aac22f2

Browse files
committed
[styling] add object-key style config
Related to #1510
1 parent e1ba8ac commit aac22f2

22 files changed

Lines changed: 570 additions & 432 deletions

docs/schemas/config-v1.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,11 @@
709709
"title": "/ui/theme-defs/<theme_name>/syntax-styles/code-border",
710710
"$ref": "#/definitions/style"
711711
},
712+
"object-key": {
713+
"description": "Styling for a key in an object",
714+
"title": "/ui/theme-defs/<theme_name>/syntax-styles/object-key",
715+
"$ref": "#/definitions/style"
716+
},
712717
"keyword": {
713718
"description": "Styling for keywords in source files",
714719
"title": "/ui/theme-defs/<theme_name>/syntax-styles/keyword",

docs/source/intro.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ The builtin themes are:
101101
`dracula <https://github.com/tstack/lnav/blob/master/src/themes/dracula.json>`_,
102102
`eldar <https://github.com/tstack/lnav/blob/master/src/themes/eldar.json>`_,
103103
`grayscale <https://github.com/tstack/lnav/blob/master/src/themes/grayscale.json>`_,
104+
`modus-operandi <https://github.com/tstack/lnav/blob/master/src/themes/modus-operandi.json>`_,
104105
`monocai <https://github.com/tstack/lnav/blob/master/src/themes/monocai.json>`_,
105106
`night-owl <https://github.com/tstack/lnav/blob/master/src/themes/night-owl.json>`_,
106107
`solarized-dark <https://github.com/tstack/lnav/blob/master/src/themes/solarized-dark.json>`_,

src/base/string_attr_type.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ enum class role_t : int32_t {
172172
VCR_SELECTED_TEXT,
173173
VCR_FUZZY_MATCH,
174174

175+
VCR_OBJECT_KEY,
176+
175177
VCR__MAX
176178
};
177179

src/lnav_config.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,10 @@ static const struct json_path_container theme_syntax_styles_handlers = {
943943
.with_description("Styling for quoted-code borders")
944944
.for_child(&lnav_theme::lt_style_code_border)
945945
.with_children(style_config_handlers),
946+
yajlpp::property_handler("object-key")
947+
.with_description("Styling for a key in an object")
948+
.for_child(&lnav_theme::lt_style_object_key)
949+
.with_children(style_config_handlers),
946950
yajlpp::property_handler("keyword")
947951
.with_description("Styling for keywords in source files")
948952
.for_child(&lnav_theme::lt_style_keyword)

src/log_format_impls.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,12 +2136,15 @@ class logfmt_format : public log_format {
21362136
auto value_lr
21372137
= line_range{value_frag.sf_begin, value_frag.sf_end};
21382138

2139+
auto known_field = false;
21392140
if (kvp.first.is_one_of(
21402141
"timestamp"_frag, "time"_frag, "ts"_frag, "t"_frag))
21412142
{
21422143
sa.emplace_back(value_lr, L_TIMESTAMP.value());
2144+
known_field = true;
21432145
} else if (kvp.first.is_one_of("level"_frag, "lvl"_frag)) {
21442146
sa.emplace_back(value_lr, L_LEVEL.value());
2147+
known_field = true;
21452148
} else if (kvp.first.is_one_of("msg"_frag, "message"_frag))
21462149
{
21472150
sa.emplace_back(value_lr, SA_BODY.value());
@@ -2162,7 +2165,15 @@ class logfmt_format : public log_format {
21622165
.with_struct_name(FIELDS_NAME);
21632166
values.lvv_values.emplace_back(lvm, value_frag);
21642167
}
2165-
2168+
if (known_field) {
2169+
auto key_with_eq = kvp.first;
2170+
key_with_eq.sf_end += 1;
2171+
sa.emplace_back(to_line_range(key_with_eq),
2172+
SA_REPLACED.value());
2173+
} else {
2174+
sa.emplace_back(to_line_range(kvp.first),
2175+
VC_ROLE.value(role_t::VCR_OBJECT_KEY));
2176+
}
21662177
return false;
21672178
},
21682179
[line_number, &sbr](const logfmt::parser::error& err) {

src/styling.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct lnav_theme {
135135
positioned_property<style_config> lt_style_inline_code;
136136
positioned_property<style_config> lt_style_quoted_code;
137137
positioned_property<style_config> lt_style_code_border;
138+
positioned_property<style_config> lt_style_object_key;
138139
positioned_property<style_config> lt_style_keyword;
139140
positioned_property<style_config> lt_style_string;
140141
positioned_property<style_config> lt_style_comment;

src/themes/default-theme.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@
205205
"code-border": {
206206
"color": "#444"
207207
},
208+
"object-key": {
209+
"color": "semantic()"
210+
},
208211
"keyword": {
209212
"color": "Navy"
210213
},

src/themes/dracula.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@
186186
"color": "#444",
187187
"background-color": "#121212"
188188
},
189+
"object-key": {
190+
"color": "semantic()"
191+
},
189192
"keyword": {
190193
"color": "$pink",
191194
"bold": true

src/themes/eldar.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@
171171
"color": "#444",
172172
"background-color": "#121212"
173173
},
174+
"object-key": {
175+
"color": "semantic()"
176+
},
174177
"keyword": {
175178
"color": "$yellow"
176179
},

src/themes/grayscale.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@
158158
}
159159
},
160160
"syntax-styles": {
161+
"object-key": {
162+
"bold": true
163+
},
161164
"comment": {
162165
"color": "#888"
163166
},

0 commit comments

Comments
 (0)