[yajlpp] add for_child() helper

This commit is contained in:
Timothy Stack 2022-06-22 11:25:11 -07:00
parent 464cda8b82
commit a3b9314ff7
11 changed files with 93 additions and 255 deletions

View File

@ -114,8 +114,7 @@ bottom_status_source::update_percent(listview_curses* lc)
lc->get_dimensions(height, width);
if (lc->get_inner_height() > 0) {
bottom = std::min(top + height - vis_line_t(1),
vis_line_t(lc->get_inner_height() - 1));
bottom = std::min(top + height - 1_vl, lc->get_inner_height() - 1_vl);
percent = (double) (bottom + 1);
percent /= (double) lc->get_inner_height();
percent *= 100.0;

View File

@ -494,109 +494,64 @@ static const struct json_path_container style_config_handlers =
static const struct json_path_container theme_styles_handlers = {
yajlpp::property_handler("identifier")
.with_description("Styling for identifiers in logs")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_identifier;
})
.for_child(&lnav_theme::lt_style_identifier)
.with_children(style_config_handlers),
yajlpp::property_handler("text")
.with_description("Styling for plain text")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_text;
})
.for_child(&lnav_theme::lt_style_text)
.with_children(style_config_handlers),
yajlpp::property_handler("alt-text")
.with_description("Styling for plain text when alternating")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_alt_text;
})
.for_child(&lnav_theme::lt_style_alt_text)
.with_children(style_config_handlers),
yajlpp::property_handler("error")
.with_description("Styling for error messages")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_error;
})
.for_child(&lnav_theme::lt_style_error)
.with_children(style_config_handlers),
yajlpp::property_handler("ok")
.with_description("Styling for success messages")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_ok;
})
.for_child(&lnav_theme::lt_style_ok)
.with_children(style_config_handlers),
yajlpp::property_handler("warning")
.with_description("Styling for warning messages")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_warning;
})
.for_child(&lnav_theme::lt_style_warning)
.with_children(style_config_handlers),
yajlpp::property_handler("hidden")
.with_description("Styling for hidden fields in logs")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_hidden;
})
.for_child(&lnav_theme::lt_style_hidden)
.with_children(style_config_handlers),
yajlpp::property_handler("adjusted-time")
.with_description("Styling for timestamps that have been adjusted")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_adjusted_time;
})
.for_child(&lnav_theme::lt_style_adjusted_time)
.with_children(style_config_handlers),
yajlpp::property_handler("skewed-time")
.with_description(
"Styling for timestamps that are different from the received time")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_skewed_time;
})
.for_child(&lnav_theme::lt_style_skewed_time)
.with_children(style_config_handlers),
yajlpp::property_handler("offset-time")
.with_description("Styling for hidden fields")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_offset_time;
})
.for_child(&lnav_theme::lt_style_offset_time)
.with_children(style_config_handlers),
yajlpp::property_handler("invalid-msg")
.with_description("Styling for invalid log messages")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_invalid_msg;
})
.for_child(&lnav_theme::lt_style_invalid_msg)
.with_children(style_config_handlers),
yajlpp::property_handler("popup")
.with_description("Styling for popup windows")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_popup;
})
.for_child(&lnav_theme::lt_style_popup)
.with_children(style_config_handlers),
yajlpp::property_handler("focused")
.with_description("Styling for a focused row in a list view")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_focused;
})
.for_child(&lnav_theme::lt_style_focused)
.with_children(style_config_handlers),
yajlpp::property_handler("disabled-focused")
.with_description("Styling for a disabled focused row in a list view")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_disabled_focused;
})
.for_child(&lnav_theme::lt_style_disabled_focused)
.with_children(style_config_handlers),
yajlpp::property_handler("scrollbar")
.with_description("Styling for scrollbars")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_scrollbar;
})
.for_child(&lnav_theme::lt_style_scrollbar)
.with_children(style_config_handlers),
yajlpp::property_handler("h1")
.with_description("Styling for top-level headers")
@ -642,271 +597,160 @@ static const struct json_path_container theme_styles_handlers = {
.with_children(style_config_handlers),
yajlpp::property_handler("hr")
.with_description("Styling for horizontal rules")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_hr;
})
.for_child(&lnav_theme::lt_style_hr)
.with_children(style_config_handlers),
yajlpp::property_handler("hyperlink")
.with_description("Styling for hyperlinks")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_hyperlink;
})
.for_child(&lnav_theme::lt_style_hyperlink)
.with_children(style_config_handlers),
yajlpp::property_handler("list-glyph")
.with_description("Styling for glyphs that prefix a list item")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_list_glyph;
})
.for_child(&lnav_theme::lt_style_list_glyph)
.with_children(style_config_handlers),
yajlpp::property_handler("breadcrumb")
.with_description("Styling for the separator between breadcrumbs")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_breadcrumb;
})
.for_child(&lnav_theme::lt_style_breadcrumb)
.with_children(style_config_handlers),
yajlpp::property_handler("table-border")
.with_description("Styling for table borders")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_table_border;
})
.for_child(&lnav_theme::lt_style_table_border)
.with_children(style_config_handlers),
yajlpp::property_handler("table-header")
.with_description("Styling for table headers")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_table_header;
})
.for_child(&lnav_theme::lt_style_table_header)
.with_children(style_config_handlers),
yajlpp::property_handler("quote-border")
.with_description("Styling for quoted-block borders")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_quote_border;
})
.for_child(&lnav_theme::lt_style_quote_border)
.with_children(style_config_handlers),
yajlpp::property_handler("quoted-text")
.with_description("Styling for quoted text blocks")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_quoted_text;
})
.for_child(&lnav_theme::lt_style_quoted_text)
.with_children(style_config_handlers),
yajlpp::property_handler("footnote-border")
.with_description("Styling for footnote borders")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_footnote_border;
})
.for_child(&lnav_theme::lt_style_footnote_border)
.with_children(style_config_handlers),
yajlpp::property_handler("footnote-text")
.with_description("Styling for footnote text")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_footnote_text;
})
.for_child(&lnav_theme::lt_style_footnote_text)
.with_children(style_config_handlers),
yajlpp::property_handler("snippet-border")
.with_description("Styling for snippet borders")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_snippet_border;
})
.for_child(&lnav_theme::lt_style_snippet_border)
.with_children(style_config_handlers),
};
static const struct json_path_container theme_syntax_styles_handlers = {
yajlpp::property_handler("quoted-code")
.with_description("Styling for quoted code blocks")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_quoted_code;
})
.for_child(&lnav_theme::lt_style_quoted_code)
.with_children(style_config_handlers),
yajlpp::property_handler("code-border")
.with_description("Styling for quoted-code borders")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_code_border;
})
.for_child(&lnav_theme::lt_style_code_border)
.with_children(style_config_handlers),
yajlpp::property_handler("keyword")
.with_description("Styling for keywords in source files")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_keyword;
})
.for_child(&lnav_theme::lt_style_keyword)
.with_children(style_config_handlers),
yajlpp::property_handler("string")
.with_description("Styling for single/double-quoted strings in text")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_string;
})
.for_child(&lnav_theme::lt_style_string)
.with_children(style_config_handlers),
yajlpp::property_handler("comment")
.with_description("Styling for comments in source files")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_comment;
})
.for_child(&lnav_theme::lt_style_comment)
.with_children(style_config_handlers),
yajlpp::property_handler("doc-directive")
.with_description(
"Styling for documentation directives in source files")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_doc_directive;
})
.for_child(&lnav_theme::lt_style_doc_directive)
.with_children(style_config_handlers),
yajlpp::property_handler("variable")
.with_description("Styling for variables in text")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_variable;
})
.for_child(&lnav_theme::lt_style_variable)
.with_children(style_config_handlers),
yajlpp::property_handler("symbol")
.with_description("Styling for symbols in source files")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_symbol;
})
.for_child(&lnav_theme::lt_style_symbol)
.with_children(style_config_handlers),
yajlpp::property_handler("number")
.with_description("Styling for numbers in source files")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_number;
})
.for_child(&lnav_theme::lt_style_number)
.with_children(style_config_handlers),
yajlpp::property_handler("re-special")
.with_description(
"Styling for special characters in regular expressions")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_re_special;
})
.for_child(&lnav_theme::lt_style_re_special)
.with_children(style_config_handlers),
yajlpp::property_handler("re-repeat")
.with_description("Styling for repeats in regular expressions")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_re_repeat;
})
.for_child(&lnav_theme::lt_style_re_repeat)
.with_children(style_config_handlers),
yajlpp::property_handler("diff-delete")
.with_description("Styling for deleted lines in diffs")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_diff_delete;
})
.for_child(&lnav_theme::lt_style_diff_delete)
.with_children(style_config_handlers),
yajlpp::property_handler("diff-add")
.with_description("Styling for added lines in diffs")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_diff_add;
})
.for_child(&lnav_theme::lt_style_diff_add)
.with_children(style_config_handlers),
yajlpp::property_handler("diff-section")
.with_description("Styling for diffs")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_diff_section;
})
.for_child(&lnav_theme::lt_style_diff_section)
.with_children(style_config_handlers),
yajlpp::property_handler("file")
.with_description("Styling for file names in source files")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_file;
})
.for_child(&lnav_theme::lt_style_file)
.with_children(style_config_handlers),
};
static const struct json_path_container theme_status_styles_handlers = {
yajlpp::property_handler("text")
.with_description("Styling for status bars")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_status;
})
.for_child(&lnav_theme::lt_style_status)
.with_children(style_config_handlers),
yajlpp::property_handler("warn")
.with_description("Styling for warnings in status bars")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_warn_status;
})
.for_child(&lnav_theme::lt_style_warn_status)
.with_children(style_config_handlers),
yajlpp::property_handler("alert")
.with_description("Styling for alerts in status bars")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_alert_status;
})
.for_child(&lnav_theme::lt_style_alert_status)
.with_children(style_config_handlers),
yajlpp::property_handler("active")
.with_description("Styling for activity in status bars")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_active_status;
})
.for_child(&lnav_theme::lt_style_active_status)
.with_children(style_config_handlers),
yajlpp::property_handler("inactive-alert")
.with_description("Styling for inactive alert status bars")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_inactive_alert_status;
})
.for_child(&lnav_theme::lt_style_inactive_alert_status)
.with_children(style_config_handlers),
yajlpp::property_handler("inactive")
.with_description("Styling for inactive status bars")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_inactive_status;
})
.for_child(&lnav_theme::lt_style_inactive_status)
.with_children(style_config_handlers),
yajlpp::property_handler("title-hotkey")
.with_description("Styling for hotkey highlights in titles")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_status_title_hotkey;
})
.for_child(&lnav_theme::lt_style_status_title_hotkey)
.with_children(style_config_handlers),
yajlpp::property_handler("title")
.with_description("Styling for title sections of status bars")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_status_title;
})
.for_child(&lnav_theme::lt_style_status_title)
.with_children(style_config_handlers),
yajlpp::property_handler("disabled-title")
.with_description("Styling for title sections of status bars")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_status_disabled_title;
})
.for_child(&lnav_theme::lt_style_status_disabled_title)
.with_children(style_config_handlers),
yajlpp::property_handler("subtitle")
.with_description("Styling for subtitle sections of status bars")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_status_subtitle;
})
.for_child(&lnav_theme::lt_style_status_subtitle)
.with_children(style_config_handlers),
yajlpp::property_handler("hotkey")
.with_description("Styling for hotkey highlights of status bars")
.with_obj_provider<style_config, lnav_theme>(
[](const yajlpp_provider_context& ypc, lnav_theme* root) {
return &root->lt_style_status_hotkey;
})
.for_child(&lnav_theme::lt_style_status_hotkey)
.with_children(style_config_handlers),
};
@ -939,10 +783,7 @@ static const struct json_path_container highlighter_handlers = {
yajlpp::property_handler("style")
.with_description(
"The styling for the text that matches the associated pattern")
.with_obj_provider<style_config, highlighter_config>(
[](const yajlpp_provider_context& ypc, highlighter_config* root) {
return &root->hc_style;
})
.for_child(&highlighter_config::hc_style)
.with_children(style_config_handlers),
};
@ -1188,17 +1029,11 @@ static const struct json_path_container sysclip_impl_handlers = {
.for_field(&sysclip::clipboard::c_test_command),
yajlpp::property_handler("general")
.with_description("Commands to work with the general clipboard")
.with_obj_provider<sysclip::clip_commands, sysclip::clipboard>(
[](const yajlpp_provider_context& ypc, sysclip::clipboard* root) {
return &root->c_general;
})
.for_child(&sysclip::clipboard::c_general)
.with_children(sysclip_impl_cmd_handlers),
yajlpp::property_handler("find")
.with_description("Commands to work with the find clipboard")
.with_obj_provider<sysclip::clip_commands, sysclip::clipboard>(
[](const yajlpp_provider_context& ypc, sysclip::clipboard* root) {
return &root->c_find;
})
.for_child(&sysclip::clipboard::c_find)
.with_children(sysclip_impl_cmd_handlers),
};

View File

@ -314,10 +314,7 @@ static const json_path_container snippet_handlers = {
yajlpp::property_handler("line").for_field(
&console::snippet::s_location, &source_location::sl_line_number),
yajlpp::property_handler("content")
.with_obj_provider<attr_line_t, console::snippet>(
[](const yajlpp_provider_context& ypc, console::snippet* snip) {
return &snip->s_content;
})
.for_child(&console::snippet::s_content)
.with_children(attr_line_handlers),
};
@ -337,22 +334,16 @@ static const typed_json_path_container<console::user_message>
.with_enum_values(LEVEL_ENUM)
.for_field(&console::user_message::um_level),
yajlpp::property_handler("message")
.with_obj_provider<attr_line_t, console::user_message>(
[](const yajlpp_provider_context& ypc,
console::user_message* root) { return &root->um_message; })
.for_child(&console::user_message::um_message)
.with_children(attr_line_handlers),
yajlpp::property_handler("reason")
.with_obj_provider<attr_line_t, console::user_message>(
[](const yajlpp_provider_context& ypc,
console::user_message* root) { return &root->um_reason; })
.for_child(&console::user_message::um_reason)
.with_children(attr_line_handlers),
yajlpp::property_handler("snippets#")
.for_field(&console::user_message::um_snippets)
.with_children(snippet_handlers),
yajlpp::property_handler("help")
.with_obj_provider<attr_line_t, console::user_message>(
[](const yajlpp_provider_context& ypc,
console::user_message* root) { return &root->um_help; })
.for_child(&console::user_message::um_help)
.with_children(attr_line_handlers),
};

View File

@ -162,7 +162,7 @@ action_delegate::text_handle_mouse(textview_curses& tc, mouse_event& me)
switch (me.me_state) {
case mouse_button_state_t::BUTTON_STATE_PRESSED:
if (mouse_line >= vis_line_t(0) && mouse_line <= tc.get_bottom()) {
if (mouse_line >= 0_vl && mouse_line <= tc.get_bottom()) {
size_t line_end_index = 0;
int x_offset;

View File

@ -117,11 +117,11 @@ log_data_table::get_columns_int()
bool
log_data_table::next(log_cursor& lc, logfile_sub_source& lss)
{
if (lc.lc_curr_line == vis_line_t(-1)) {
if (lc.lc_curr_line == -1_vl) {
this->ldt_instance = -1;
}
lc.lc_curr_line = lc.lc_curr_line + vis_line_t(1);
lc.lc_curr_line = lc.lc_curr_line + 1_vl;
lc.lc_sub_index = 0;
if (lc.lc_curr_line == (int) lss.text_line_count()) {

View File

@ -1471,7 +1471,7 @@ log_vtab_manager::unregister_vtab(intern_string_t name)
bool
log_format_vtab_impl::next(log_cursor& lc, logfile_sub_source& lss)
{
lc.lc_curr_line = lc.lc_curr_line + vis_line_t(1);
lc.lc_curr_line = lc.lc_curr_line + 1_vl;
lc.lc_sub_index = 0;
if (lc.is_eof()) {

View File

@ -76,7 +76,7 @@ struct log_cursor {
void update(unsigned char op, vis_line_t vl, constraint_t cons);
void set_eof() { this->lc_curr_line = this->lc_end_line = vis_line_t(0); }
void set_eof() { this->lc_curr_line = this->lc_end_line = 0_vl; }
bool is_eof() const { return this->lc_curr_line >= this->lc_end_line; }
};
@ -94,7 +94,9 @@ public:
const std::string comment = "",
unsigned int subtype = 0)
: vc_name(name), vc_type(type), vc_collator(collator),
vc_hidden(hidden), vc_comment(comment), vc_subtype(subtype){};
vc_hidden(hidden), vc_comment(comment), vc_subtype(subtype)
{
}
vtab_column& with_comment(const std::string comment)
{
@ -132,7 +134,7 @@ public:
virtual bool next(log_cursor& lc, logfile_sub_source& lss) = 0;
virtual void get_columns(std::vector<vtab_column>& cols) const {};
virtual void get_columns(std::vector<vtab_column>& cols) const {}
virtual void get_foreign_keys(std::vector<std::string>& keys_inout) const;
@ -235,4 +237,5 @@ private:
logfile_sub_source& vm_source;
std::map<intern_string_t, std::shared_ptr<log_vtab_impl>> vm_impls;
};
#endif

View File

@ -49,8 +49,7 @@ static const struct json_path_container term_color_handler = {
yajlpp::property_handler("name").for_field(&term_color::xc_name),
yajlpp::property_handler("hexString").for_field(&term_color::xc_hex),
yajlpp::property_handler("rgb")
.with_obj_provider<rgb_color, term_color>(
[](const auto& pc, term_color* xc) { return &xc->xc_color; })
.for_child(&term_color::xc_color)
.with_children(term_color_rgb_handler),
};
@ -59,7 +58,9 @@ static const struct json_path_container root_color_handler = {
.with_obj_provider<term_color, std::vector<term_color>>(
[](const yajlpp_provider_context& ypc,
std::vector<term_color>* palette) {
palette->resize(ypc.ypc_index + 1);
if (ypc.ypc_index >= palette->size()) {
palette->resize(ypc.ypc_index + 1);
}
return &((*palette)[ypc.ypc_index]);
})
.with_children(term_color_handler),

View File

@ -437,7 +437,7 @@ open_pretty_view()
pts->replace_with(full_text);
pretty_tc->set_sub_source(pts);
if (lnav_data.ld_last_pretty_print_top != log_tc->get_top()) {
pretty_tc->set_top(vis_line_t(0));
pretty_tc->set_top(0_vl);
}
lnav_data.ld_last_pretty_print_top = log_tc->get_top();
pretty_tc->redo_search();

View File

@ -419,12 +419,6 @@ public:
private:
static const yajl_callbacks DEFAULT_CALLBACKS;
size_t index_for_provider() const
{
return this->ypc_array_index.empty() ? static_cast<size_t>(-1)
: this->ypc_array_index.back();
}
static int map_start(void* ctx);
static int map_key(void* ctx, const unsigned char* key, size_t len);
static int map_end(void* ctx);
@ -435,7 +429,7 @@ private:
class yajlpp_generator {
public:
yajlpp_generator(yajl_gen handle) : yg_handle(handle){};
yajlpp_generator(yajl_gen handle) : yg_handle(handle) {}
yajl_gen_status operator()(const std::string& str)
{
@ -516,7 +510,7 @@ private:
class yajlpp_container_base {
public:
yajlpp_container_base(yajl_gen handle) : gen(handle), ycb_handle(handle){};
yajlpp_container_base(yajl_gen handle) : gen(handle), ycb_handle(handle) {}
yajlpp_generator gen;
@ -554,7 +548,9 @@ class yajlpp_gen_context {
public:
yajlpp_gen_context(yajl_gen handle,
const struct json_path_container& handlers)
: ygc_handle(handle), ygc_depth(0), ygc_handlers(&handlers){};
: ygc_handle(handle), ygc_depth(0), ygc_handlers(&handlers)
{
}
template<typename T>
yajlpp_gen_context& with_default_obj(T& obj)

View File

@ -632,6 +632,19 @@ struct json_path_handler : public json_path_handler_base {
return *this;
}
template<typename... Args>
json_path_handler& for_child(Args... args)
{
this->jph_obj_provider = [args...](const yajlpp_provider_context& ypc,
void* root) -> void* {
auto& child = json_path_handler::get_field(root, args...);
return &child;
};
return *this;
}
template<typename... Args,
std::enable_if_t<
LastIs<std::map<std::string, std::string>, Args...>::value,