[views_vtab] programmatic control of the overlay toggle

pull/1161/merge
Tim Stack 10 months ago
parent 3e49915ef2
commit c464827737

@ -71,6 +71,8 @@ Features:
* `text-decoration` with `underline`
* `border-left` and `border-right` with the `solid`,
`dashed` and `dotted` line styles and colors.
* Added an `options` column to the `lnav_views` table
to allow more control over overlays.
Bug Fixes:
* Binary data piped into stdin should now be treated the same

@ -169,6 +169,7 @@ available in this table:
:top_meta: A JSON object that contains metadata related to the top line
in the view.
:selection: The number of the line that is focused for selection.
:options: A JSON object that contains optional settings for this view.
lnav_views_echo
---------------

@ -297,9 +297,12 @@ db_overlay_source::list_value_for_overlay(const listview_curses& lv,
return;
}
if (row != lv.get_selection()) {
return;
}
auto& vc = view_colors::singleton();
auto top = lv.get_top();
const auto& cols = this->dos_labels->dls_rows[top];
const auto& cols = this->dos_labels->dls_rows[row];
unsigned long width;
vis_line_t height;

@ -139,6 +139,16 @@ public:
vis_line_t line,
std::vector<attr_line_t>& value_out) override;
void set_show_details_in_overlay(bool val) override
{
this->dos_active = val;
}
bool get_show_details_in_overlay() const override
{
return this->dos_active;
}
bool dos_active{false};
db_label_source* dos_labels{nullptr};
};

@ -42,7 +42,7 @@ class field_overlay_source : public list_overlay_source {
public:
explicit field_overlay_source(logfile_sub_source& lss,
textfile_sub_source& tss)
: fos_lss(lss), fos_tss(tss), fos_log_helper(lss)
: fos_lss(lss), fos_log_helper(lss)
{
}
@ -67,6 +67,16 @@ public:
std::vector<attr_line_t>& dst,
vis_line_t row);
void set_show_details_in_overlay(bool val) override
{
this->fos_contexts.top().c_show = val;
}
bool get_show_details_in_overlay() const override
{
return this->fos_contexts.top().c_show;
}
struct context {
context(std::string prefix, bool show, bool show_discovered)
: c_prefix(std::move(prefix)), c_show(show),
@ -79,10 +89,8 @@ public:
bool c_show_discovered{true};
};
bool fos_show_status{true};
std::stack<context> fos_contexts;
logfile_sub_source& fos_lss;
textfile_sub_source& fos_tss;
log_data_helper fos_log_helper;
int fos_known_key_size{0};
int fos_unknown_key_size{0};

@ -202,6 +202,12 @@ handle_paging_key(int ch)
text_sub_source* tc_tss = tc->get_sub_source();
bookmarks<vis_line_t>::type& bm = tc->get_bookmarks();
if (tc->get_overlay_selection()) {
if (tc->handle_key(ch)) {
return true;
}
}
auto keyseq = fmt::format(FMT_STRING("x{:02x}"), ch);
if (handle_keyseq(keyseq.c_str())) {
return true;
@ -701,27 +707,6 @@ handle_paging_key(int ch)
}
break;
case 'p':
if (tc == &lnav_data.ld_views[LNV_LOG]) {
auto* fos = dynamic_cast<field_overlay_source*>(
tc->get_overlay_source());
auto& top_context = fos->fos_contexts.top();
top_context.c_show = !top_context.c_show;
if (!top_context.c_show) {
tc->set_overlay_selection(nonstd::nullopt);
}
tc->set_sync_selection_and_top(top_context.c_show);
tc->set_needs_update();
} else if (tc == &lnav_data.ld_views[LNV_DB]) {
auto* dos = dynamic_cast<db_overlay_source*>(
tc->get_overlay_source());
dos->dos_active = !dos->dos_active;
tc->set_sync_selection_and_top(dos->dos_active);
tc->set_needs_update();
}
break;
case 't':
if (lnav_data.ld_text_source.current_file() == nullptr) {
alerter::singleton().chime("No text files loaded");

@ -131,6 +131,9 @@
"command": ":next-mark search",
"alt-msg": "${keymap_def_scroll_horiz}"
},
"x70": {
"command": ";UPDATE lnav_views SET options = json_set(options, '$.show-details', CASE jget(options, '/show-details', 'hide') WHEN 'hide' THEN 'show' ELSE 'hide' END) WHERE name = (SELECT name FROM lnav_top_view)"
},
"x75": {
"command": ":next-mark",
"alt-msg": "${keymap_def_next_mark}"

@ -1044,5 +1044,6 @@ listview_curses::set_overlay_selection(nonstd::optional<vis_line_t> sel)
this->lv_focused_overlay_top = 0_vl;
this->lv_focused_overlay_selection = 0_vl;
}
this->lv_source->listview_selection_changed(*this);
this->set_needs_update();
}

@ -125,6 +125,10 @@ public:
std::vector<attr_line_t>& value_out)
{
}
virtual void set_show_details_in_overlay(bool val) {}
virtual bool get_show_details_in_overlay() const { return false; }
};
class list_input_delegate {
@ -180,7 +184,7 @@ public:
}
/** @return The overlay source delegate. */
list_overlay_source* get_overlay_source()
list_overlay_source* get_overlay_source() const
{
return this->lv_overlay_source;
}
@ -283,7 +287,7 @@ public:
vis_line_t rows_available(vis_line_t line, row_direction_t dir) const;
template<typename F>
auto map_top_row(F func) ->
auto map_top_row(F func) const ->
typename std::result_of<F(const attr_line_t&)>::type
{
if (this->lv_top >= this->get_inner_height()) {

@ -473,7 +473,6 @@ handle_rl_key(int ch)
handle_paging_key(ch);
break;
case KEY_ESCAPE:
case KEY_CTRL(']'):
lnav_data.ld_rl_view->abort();
break;
@ -2700,9 +2699,6 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%'
.set_word_wrap(false);
auto log_fos = new field_overlay_source(lnav_data.ld_log_source,
lnav_data.ld_text_source);
if (lnav_data.ld_flags & LNF_HEADLESS) {
log_fos->fos_show_status = false;
}
log_fos->fos_contexts.emplace("", false, true);
lnav_data.ld_views[LNV_LOG]
.set_sub_source(&lnav_data.ld_log_source)

@ -173,6 +173,37 @@ static const typed_json_path_container<top_line_meta> top_line_meta_handlers = {
.with_children(breadcrumb_crumb_handlers),
};
enum class row_details_t {
hide,
show,
};
struct view_options {
nonstd::optional<row_details_t> vo_row_details;
nonstd::optional<int32_t> vo_overlay_focus;
bool empty() const
{
return !this->vo_row_details.has_value()
&& !this->vo_overlay_focus.has_value();
}
};
static const json_path_handler_base::enum_value_t ROW_DETAILS_ENUM[] = {
{"hide", row_details_t::hide},
{"show", row_details_t::show},
json_path_handler_base::ENUM_TERMINATOR,
};
static const typed_json_path_container<view_options> view_options_handlers = {
yajlpp::property_handler("show-details")
.with_enum_values(ROW_DETAILS_ENUM)
.for_field(&view_options::vo_row_details),
yajlpp::property_handler("overlay-focused-line")
.for_field(&view_options::vo_overlay_focus),
};
struct lnav_views : public tvt_iterator_cursor<lnav_views> {
static constexpr const char* NAME = "lnav_views";
static constexpr const char* CREATE_STMT = R"(
@ -190,7 +221,8 @@ CREATE TABLE lnav_views (
filtering INTEGER, -- Indicates if the view is applying filters.
movement TEXT, -- The movement mode, either 'top' or 'cursor'.
top_meta TEXT, -- A JSON object that contains metadata related to the top line in the view.
selection INTEGER -- The number of the line that is focused for selection.
selection INTEGER, -- The number of the line that is focused for selection.
options TEXT -- A JSON object that contains optional settings for this view.
);
)";
@ -204,7 +236,7 @@ CREATE TABLE lnav_views (
{
lnav_view_t view_index = (lnav_view_t) std::distance(
std::begin(lnav_data.ld_views), vc.iter);
textview_curses& tc = *vc.iter;
const auto& tc = *vc.iter;
unsigned long width;
vis_line_t height;
@ -344,6 +376,28 @@ CREATE TABLE lnav_views (
case 12:
sqlite3_result_int(ctx, (int) tc.get_selection());
break;
case 13: {
auto vo = view_options{};
if (tc.get_overlay_source()) {
auto ov_sel = tc.get_overlay_selection();
vo.vo_row_details
= tc.get_overlay_source()->get_show_details_in_overlay()
? row_details_t::show
: row_details_t::hide;
if (ov_sel) {
vo.vo_overlay_focus = ov_sel.value();
}
}
if (vo.empty()) {
sqlite3_result_null(ctx);
} else {
to_sqlite(ctx, view_options_handlers.to_json_string(vo));
}
break;
}
}
return SQLITE_OK;
@ -377,11 +431,29 @@ CREATE TABLE lnav_views (
bool do_filtering,
string_fragment movement,
const char* top_meta,
int64_t selection)
int64_t selection,
nonstd::optional<string_fragment> options)
{
auto& tc = lnav_data.ld_views[index];
auto* time_source
= dynamic_cast<text_time_translator*>(tc.get_sub_source());
view_options vo;
if (options) {
static const intern_string_t OPTIONS_SRC
= intern_string::lookup("options");
auto parse_res = view_options_handlers.parser_for(OPTIONS_SRC)
.of(options.value());
if (parse_res.isErr()) {
auto errmsg = parse_res.unwrapErr();
set_vtable_errmsg(tab, errmsg[0]);
return SQLITE_ERROR;
}
vo = parse_res.unwrap();
}
if (tc.get_top() != top_row) {
log_debug(
@ -507,6 +579,14 @@ CREATE TABLE lnav_views (
tc.set_selection(cur_bot);
}
}
if (vo.vo_row_details && tc.get_overlay_source()) {
tc.get_overlay_source()->set_show_details_in_overlay(
vo.vo_row_details.value() == row_details_t::show);
tc.set_needs_update();
}
if (vo.vo_overlay_focus && tc.get_overlay_source()) {
tc.set_overlay_selection(vis_line_t(vo.vo_overlay_focus.value()));
}
tc.set_left(left);
tc.set_paused(is_paused);
tc.execute_search(search);

@ -3867,6 +3867,10 @@
"command": ":next-mark search",
"alt-msg": "${keymap_def_scroll_horiz}"
},
"x70": {
"command": ";UPDATE lnav_views SET options = json_set(options, '$.show-details', CASE jget(options, '/show-details', 'hide') WHEN 'hide' THEN 'show' ELSE 'hide' END) WHERE name = (SELECT name FROM lnav_top_view)",
"alt-msg": ""
},
"x71": {
"command": "|lnav-pop-view ${keyseq}",
"alt-msg": ""

@ -90,16 +90,16 @@
/ui/keymap-defs/default/x3a/command -> default-keymap.json:88
/ui/keymap-defs/default/x3b/command -> default-keymap.json:97
/ui/keymap-defs/default/x3d/command -> default-keymap.json:82
/ui/keymap-defs/default/x3f/command -> default-keymap.json:150
/ui/keymap-defs/default/x3f/command -> default-keymap.json:153
/ui/keymap-defs/default/x40/command -> default-keymap.json:49
/ui/keymap-defs/default/x45/alt-msg -> default-keymap.json:101
/ui/keymap-defs/default/x45/command -> default-keymap.json:100
/ui/keymap-defs/default/x4e/alt-msg -> default-keymap.json:128
/ui/keymap-defs/default/x4e/command -> default-keymap.json:127
/ui/keymap-defs/default/x50/alt-msg -> default-keymap.json:158
/ui/keymap-defs/default/x50/command -> default-keymap.json:157
/ui/keymap-defs/default/x51/command -> default-keymap.json:167
/ui/keymap-defs/default/x55/command -> default-keymap.json:139
/ui/keymap-defs/default/x50/alt-msg -> default-keymap.json:161
/ui/keymap-defs/default/x50/command -> default-keymap.json:160
/ui/keymap-defs/default/x51/command -> default-keymap.json:170
/ui/keymap-defs/default/x55/command -> default-keymap.json:142
/ui/keymap-defs/default/x57/alt-msg -> default-keymap.json:109
/ui/keymap-defs/default/x57/command -> default-keymap.json:108
/ui/keymap-defs/default/x58/command -> default-keymap.json:85
@ -109,23 +109,24 @@
/ui/keymap-defs/default/x65/alt-msg -> default-keymap.json:105
/ui/keymap-defs/default/x65/command -> default-keymap.json:104
/ui/keymap-defs/default/x67/command -> default-keymap.json:120
/ui/keymap-defs/default/x69/alt-msg -> default-keymap.json:154
/ui/keymap-defs/default/x69/command -> default-keymap.json:153
/ui/keymap-defs/default/x69/alt-msg -> default-keymap.json:157
/ui/keymap-defs/default/x69/command -> default-keymap.json:156
/ui/keymap-defs/default/x6d/alt-msg -> default-keymap.json:124
/ui/keymap-defs/default/x6d/command -> default-keymap.json:123
/ui/keymap-defs/default/x6e/alt-msg -> default-keymap.json:132
/ui/keymap-defs/default/x6e/command -> default-keymap.json:131
/ui/keymap-defs/default/x71/command -> default-keymap.json:164
/ui/keymap-defs/default/x75/alt-msg -> default-keymap.json:136
/ui/keymap-defs/default/x75/command -> default-keymap.json:135
/ui/keymap-defs/default/x76/command -> default-keymap.json:161
/ui/keymap-defs/default/x70/command -> default-keymap.json:135
/ui/keymap-defs/default/x71/command -> default-keymap.json:167
/ui/keymap-defs/default/x75/alt-msg -> default-keymap.json:139
/ui/keymap-defs/default/x75/command -> default-keymap.json:138
/ui/keymap-defs/default/x76/command -> default-keymap.json:164
/ui/keymap-defs/default/x77/alt-msg -> default-keymap.json:113
/ui/keymap-defs/default/x77/command -> default-keymap.json:112
/ui/keymap-defs/default/x7b/alt-msg -> default-keymap.json:147
/ui/keymap-defs/default/x7b/command -> default-keymap.json:146
/ui/keymap-defs/default/x7b/alt-msg -> default-keymap.json:150
/ui/keymap-defs/default/x7b/command -> default-keymap.json:149
/ui/keymap-defs/default/x7c/command -> default-keymap.json:91
/ui/keymap-defs/default/x7d/alt-msg -> default-keymap.json:143
/ui/keymap-defs/default/x7d/command -> default-keymap.json:142
/ui/keymap-defs/default/x7d/alt-msg -> default-keymap.json:146
/ui/keymap-defs/default/x7d/command -> default-keymap.json:145
/ui/keymap-defs/fr/x22/command -> fr-keymap.json:13
/ui/keymap-defs/fr/x26/command -> fr-keymap.json:7
/ui/keymap-defs/fr/x27/command -> fr-keymap.json:16

Loading…
Cancel
Save