From e805ca8a8a541d6c18635a4d74120e559e40a562 Mon Sep 17 00:00:00 2001 From: Tim Stack Date: Fri, 19 Apr 2024 09:18:21 -0700 Subject: [PATCH] [mouse] move scrollbar on double click and handle mouse in spectro --- NEWS.md | 74 +++++++++++++++++++++++++++--------------- docs/source/ui.rst | 30 +++++++++++++---- src/listview_curses.cc | 10 ++++++ src/spectro_source.cc | 29 +++++++++++++++++ src/spectro_source.hh | 7 +++- 5 files changed, 115 insertions(+), 35 deletions(-) diff --git a/NEWS.md b/NEWS.md index 24f19b3a..911f2aa6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,53 @@ ## lnav v0.12.2 Features: +* Added mouse support that can be toggled with `F2` or enabled + by default with: `:config /ui/mouse/mode enabled`. With + mouse support enabled, many of the UI elements will respond to + mouse inputs: + - clicking on the main view will move the cursor to the given + row and dragging will scroll the view as needed; + - shift + clicking/dragging in the main view will highlight + lines and then toggle their bookmark status on release; + - double-clicking in the main view will select the underlying + text and drag-selecting within a line will select the given + text; + - when double-clicking text: if the mouse pointer is inside + a quoted string, the contents of the string will be selected; + if the mouse pointer is on the quote, the quote will be included + in the selection; if the mouse pointer is over a bracket + (e.g. [],{},()) where the matching bracket is on the same line, + the selection will span from one bracket to the other; + - when text is selected, a menu will pop up that can be used + to filter based on the current text, search for it, or copy + it to the clipboard; + - right-clicking the start of a log message in the main view + will open the parser details overlay; + - the parser details now displays a diamond next to fields to + indicate whether they are shown/hidden and this can be + clicked to toggle the state; + - the parser details will show a bar chart icon for fields with + values which, when clicked, will open either the spectrogram + view for the given field or open the DB query prompt with a + PRQL query to generate a histogram of the field values; + - clicking in the scroll area will move the view by a page, + double-clicking will move the view to that area, and + dragging the scrollbar will move the view to the given spot; + - clicking on the breadcrumb bar will select a crumb and + selecting a possibility from the popup will move to that + location in the view; + - clicking on portions of the bottom status bar will trigger + a relevant action (e.g. clicking the line number will open + the command prompt with `:goto `); + - clicking on the configuration panel tabs (i.e. Files/Filters) + will open the selected panel and clicking parts of the + display in there will perform the relevant action (e.g. + clicking the diamond will enable/disable the file/filter); + - clicking in a prompt will move the cursor to the location; + - clicking on a column in the spectrogram view will select it. + + (Note that this is new work, so there are likely to be some + glitches.) * Added a `journald://` URL handler that will call `journalctl` and pass any query parameters as options. For example, the following command: @@ -22,33 +69,6 @@ Features: of archive contents. * Added `humanize_id` SQL function that colorizes a string using ANSI escape codes. -* Added mouse support that can be toggled with `F2` or enabled - by default with: `:config /ui/mouse/mode enabled`. With - mouse support enabled, many of the UI elements will respond to - mouse inputs: - - clicking on the main view will move the cursor to the given - row and dragging will scroll the view as needed; - - shift + clicking/dragging in the main view will highlight - lines and then toggle their bookmark status on release; - - double-clicking will select the underlying token and - drag-selecting within a line will select the given text; - - when text is selected, a menu will pop up that can be used - to filter based on the current text, search for it, or copy - it to the clipboard; - - clicking in the scroll area will move the view by a page and - dragging the scrollbar will move the view to the given spot; - - clicking on the breadcrumb bar will select a crumb and - selecting a possibility from the popup will move to that - location in the view; - - clicking on portions of the bottom status bar will trigger - a relevant action (e.g. clicking the line number will open - the command prompt with `:goto `); - - clicking on the configuration panel tabs (i.e. Files/Filters) - will open the selected panel and clicking parts of the - display in there will perform the relevant action (e.g. - clicking the diamond will enable/disable the file/filter); - - clicking in a prompt will move the cursor to the location. - This is new work, so there are likely to be some glitches. * Added a `selected_text` column to the `lnav_views` table that reports information about text that was selected with a mouse. This makes it possible to script operations that use the diff --git a/docs/source/ui.rst b/docs/source/ui.rst index e745a551..b2de5b79 100644 --- a/docs/source/ui.rst +++ b/docs/source/ui.rst @@ -428,26 +428,42 @@ elements will respond to mouse inputs: * clicking on the main view will move the cursor to the given row and dragging will scroll the view as needed; -* shift + clicking/dragging in the main view will highlight - lines and then toggle their bookmark status on release; -* double-clicking will select the underlying token and - drag-selecting within a line will select the given text; +* double-clicking in the main view will select the underlying + text and drag-selecting within a line will select the given + text; +* when double-clicking text: if the mouse pointer is inside + a quoted string, the contents of the string will be selected; + if the mouse pointer is on the quote, the quote will be included + in the selection; if the mouse pointer is over a bracket + (e.g. [],{},()) where the matching bracket is on the same line, + the selection will span from one bracket to the other; * when text is selected, a menu will pop up that can be used to filter based on the current text, search for it, or copy it to the clipboard; -* clicking in the scroll area will move the view by a page and +* right-clicking the start of a log message in the main view + will open the parser details overlay; +* the parser details now displays a diamond next to fields to + indicate whether they are shown/hidden and this can be + clicked to toggle the state; +* the parser details will show a bar chart icon for fields with + values which, when clicked, will open either the spectrogram + view for the given field or open the DB query prompt with a + PRQL query to generate a histogram of the field values; +* clicking in the scroll area will move the view by a page, + double-clicking will move the view to that area, and dragging the scrollbar will move the view to the given spot; * clicking on the breadcrumb bar will select a crumb and selecting a possibility from the popup will move to that location in the view; * clicking on portions of the bottom status bar will trigger a relevant action (e.g. clicking the line number will open - the command prompt with `:goto `); + the command prompt with :code:`:goto `); * clicking on the configuration panel tabs (i.e. Files/Filters) will open the selected panel and clicking parts of the display in there will perform the relevant action (e.g. clicking the diamond will enable/disable the file/filter); -* clicking in a prompt will move the cursor to the location. +* clicking in a prompt will move the cursor to the location; +* clicking on a column in the spectrogram view will select it. .. note:: diff --git a/src/listview_curses.cc b/src/listview_curses.cc index 867df34a..7274bdcd 100644 --- a/src/listview_curses.cc +++ b/src/listview_curses.cc @@ -849,6 +849,16 @@ listview_curses::handle_mouse(mouse_event& me) return false; } + if (me.is_double_click_in(mouse_button_t::BUTTON_LEFT, + line_range{(int) width - 2, (int) width})) + { + auto pct = (double) inner_height / (double) height; + auto new_top = (int) floor(((double) me.me_y * pct) + 0.5); + this->set_top(vis_line_t(new_top), true); + this->lv_mouse_mode = lv_mode_t::NONE; + return true; + } + switch (this->lv_mouse_mode) { case lv_mode_t::NONE: { if (me.me_x < (int) (width - 2)) { diff --git a/src/spectro_source.cc b/src/spectro_source.cc index d892e7a9..5a694dc3 100644 --- a/src/spectro_source.cc +++ b/src/spectro_source.cc @@ -177,6 +177,35 @@ spectrogram_source::list_input_handle_key(listview_curses& lv, int ch) } } +bool +spectrogram_source::text_handle_mouse( + textview_curses& tc, + const listview_curses::display_line_content_t&, + mouse_event& me) +{ + auto sel = tc.get_selection(); + const auto& s_row = this->load_row(tc, sel); + + for (int lpc = 0; lpc <= (int) s_row.sr_width; lpc++) { + int col_value = s_row.sr_values[lpc].rb_counter; + + if (col_value == 0) { + continue; + } + + auto lr = line_range{lpc, lpc + 1}; + if (me.is_click_in(mouse_button_t::BUTTON_LEFT, lr)) { + this->ss_cursor_column = lr.lr_start; + this->ss_details_source.reset(); + + tc.reload_data(); + return true; + } + } + + return false; +} + void spectrogram_source::list_value_for_overlay(const listview_curses& lv, vis_line_t row, diff --git a/src/spectro_source.hh b/src/spectro_source.hh index 9fd778c9..d861b5bd 100644 --- a/src/spectro_source.hh +++ b/src/spectro_source.hh @@ -117,7 +117,8 @@ class spectrogram_source : public text_sub_source , public text_time_translator , public list_overlay_source - , public list_input_delegate { + , public list_input_delegate + , public text_delegate { public: ~spectrogram_source() override = default; @@ -130,6 +131,10 @@ public: bool list_input_handle_key(listview_curses& lv, int ch) override; + bool text_handle_mouse(textview_curses& tc, + const listview_curses::display_line_content_t&, + mouse_event& me) override; + bool list_static_overlay(const listview_curses& lv, int y, int bottom,