summaryrefslogtreecommitdiffstats
path: root/src/textview_curses.hh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-07 04:48:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-07 04:48:35 +0000
commit207df6fc406e81bfeebdff7f404bd242ff3f099f (patch)
treea1a796b056909dd0a04ffec163db9363a8757808 /src/textview_curses.hh
parentReleasing progress-linux version 0.11.2-1~progress7.99u1. (diff)
downloadlnav-207df6fc406e81bfeebdff7f404bd242ff3f099f.tar.xz
lnav-207df6fc406e81bfeebdff7f404bd242ff3f099f.zip
Merging upstream version 0.12.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/textview_curses.hh')
-rw-r--r--src/textview_curses.hh183
1 files changed, 142 insertions, 41 deletions
diff --git a/src/textview_curses.hh b/src/textview_curses.hh
index 1fea398..4f80a01 100644
--- a/src/textview_curses.hh
+++ b/src/textview_curses.hh
@@ -43,6 +43,7 @@
#include "highlighter.hh"
#include "listview_curses.hh"
#include "lnav_config_fwd.hh"
+#include "log_accel.hh"
#include "logfile_fwd.hh"
#include "ring_span.hh"
#include "text_format.hh"
@@ -88,13 +89,8 @@ enum class filter_lang_t : int {
class text_filter {
public:
typedef enum {
- MAYBE,
INCLUDE,
EXCLUDE,
-
- LFT__MAX,
-
- LFT__MASK = (MAYBE | INCLUDE | EXCLUDE)
} type_t;
text_filter(type_t type, filter_lang_t lang, std::string id, size_t index)
@@ -123,8 +119,12 @@ public:
void end_of_message(logfile_filter_state& lfs);
- virtual bool matches(const logfile& lf,
- logfile_const_iterator ll,
+ struct line_source {
+ const logfile& ls_file;
+ logfile_const_iterator ls_line;
+ };
+
+ virtual bool matches(nonstd::optional<line_source> ls,
const shared_buffer_ref& line)
= 0;
@@ -149,13 +149,44 @@ public:
{
}
- bool matches(const logfile& lf,
- logfile_const_iterator ll,
+ bool matches(nonstd::optional<line_source> ls,
const shared_buffer_ref& line) override;
std::string to_command() const override;
};
+class pcre_filter : public text_filter {
+public:
+ pcre_filter(type_t type,
+ const std::string& id,
+ size_t index,
+ std::shared_ptr<lnav::pcre2pp::code> code)
+ : text_filter(type, filter_lang_t::REGEX, id, index),
+ pf_pcre(std::move(code))
+ {
+ }
+
+ ~pcre_filter() override = default;
+
+ bool matches(nonstd::optional<line_source> ls,
+ const shared_buffer_ref& line) override
+ {
+ return this->pf_pcre->find_in(line.to_string_fragment())
+ .ignore_error()
+ .has_value();
+ }
+
+ std::string to_command() const override
+ {
+ return (this->lf_type == text_filter::INCLUDE ? "filter-in "
+ : "filter-out ")
+ + this->lf_id;
+ }
+
+protected:
+ std::shared_ptr<lnav::pcre2pp::code> pf_pcre;
+};
+
class filter_stack {
public:
using iterator = std::vector<std::shared_ptr<text_filter>>::iterator;
@@ -219,22 +250,69 @@ private:
class text_time_translator {
public:
+ struct row_info {
+ struct timeval ri_time {
+ 0, 0
+ };
+ int64_t ri_id{-1};
+ };
+
virtual ~text_time_translator() = default;
virtual nonstd::optional<vis_line_t> row_for_time(
struct timeval time_bucket)
= 0;
- virtual nonstd::optional<struct timeval> time_for_row(vis_line_t row) = 0;
+ virtual nonstd::optional<vis_line_t> row_for(const row_info& ri)
+ {
+ return this->row_for_time(ri.ri_time);
+ }
- void scroll_invoked(textview_curses* tc);
+ virtual nonstd::optional<row_info> time_for_row(vis_line_t row) = 0;
void data_reloaded(textview_curses* tc);
+ void ttt_scroll_invoked(textview_curses* tc);
+
protected:
- struct timeval ttt_top_time {
- 0, 0
- };
+ nonstd::optional<row_info> ttt_top_row_info;
+};
+
+class text_accel_source {
+public:
+ virtual ~text_accel_source() = default;
+
+ virtual log_accel::direction_t get_line_accel_direction(vis_line_t vl);
+
+ void toggle_time_offset()
+ {
+ this->tas_display_time_offset = !this->tas_display_time_offset;
+ this->text_accel_display_changed();
+ }
+
+ void set_time_offset(bool enabled)
+ {
+ if (this->tas_display_time_offset != enabled) {
+ this->tas_display_time_offset = enabled;
+ this->text_accel_display_changed();
+ }
+ }
+
+ bool is_time_offset_enabled() const
+ {
+ return this->tas_display_time_offset;
+ }
+
+ virtual bool is_time_offset_supported() const { return true; }
+
+ virtual logline* text_accel_get_line(vis_line_t vl) = 0;
+
+ std::string get_time_offset_for_line(textview_curses& tc, vis_line_t vl);
+
+protected:
+ virtual void text_accel_display_changed() {}
+
+ bool tas_display_time_offset{false};
};
class text_anchors {
@@ -246,6 +324,17 @@ public:
virtual nonstd::optional<vis_line_t> row_for_anchor(const std::string& id)
= 0;
+ enum class direction {
+ prev,
+ next,
+ };
+
+ virtual nonstd::optional<vis_line_t> adjacent_anchor(vis_line_t vl,
+ direction dir)
+ {
+ return nonstd::nullopt;
+ }
+
virtual nonstd::optional<std::string> anchor_for_row(vis_line_t vl) = 0;
virtual std::unordered_set<std::string> get_anchors() = 0;
@@ -296,7 +385,7 @@ public:
{
}
- void register_view(textview_curses* tc) { this->tss_view = tc; }
+ virtual void register_view(textview_curses* tc) { this->tss_view = tc; }
/**
* @return The total number of lines available from the source.
@@ -417,6 +506,8 @@ public:
virtual void quiesce() {}
+ virtual void scroll_invoked(textview_curses* tc);
+
bool tss_supports_filtering{false};
bool tss_apply_filters{true};
@@ -460,9 +551,10 @@ class text_delegate {
public:
virtual ~text_delegate() = default;
- virtual void text_overlay(textview_curses& tc) {}
-
- virtual bool text_handle_mouse(textview_curses& tc, mouse_event& me)
+ virtual bool text_handle_mouse(
+ textview_curses& tc,
+ const listview_curses::display_line_content_t&,
+ mouse_event& me)
{
return false;
}
@@ -485,6 +577,7 @@ public:
const static bookmark_type_t BM_USER_EXPR;
const static bookmark_type_t BM_SEARCH;
const static bookmark_type_t BM_META;
+ const static bookmark_type_t BM_PARTITION;
textview_curses();
@@ -516,6 +609,12 @@ public:
text_sub_source* get_sub_source() const { return this->tc_sub_source; }
+ textview_curses& set_supports_marks(bool m)
+ {
+ this->tc_supports_marks = m;
+ return *this;
+ }
+
textview_curses& set_delegate(std::shared_ptr<text_delegate> del)
{
this->tc_delegate = del;
@@ -634,14 +733,6 @@ public:
void reload_data();
- void do_update()
- {
- this->listview_curses::do_update();
- if (this->tc_delegate != nullptr) {
- this->tc_delegate->text_overlay(*this);
- }
- }
-
bool toggle_hide_fields()
{
bool retval = this->tc_hide_fields;
@@ -653,6 +744,14 @@ public:
bool get_hide_fields() const { return this->tc_hide_fields; }
+ void set_hide_fields(bool val)
+ {
+ if (this->tc_hide_fields != val) {
+ this->tc_hide_fields = val;
+ this->set_needs_update();
+ }
+ }
+
void execute_search(const std::string& regex_orig);
void redo_search();
@@ -687,18 +786,7 @@ public:
void revert_search() { this->execute_search(this->tc_previous_search); }
- void invoke_scroll()
- {
- if (this->tc_sub_source != nullptr) {
- auto ttt = dynamic_cast<text_time_translator*>(this->tc_sub_source);
-
- if (ttt != nullptr) {
- ttt->scroll_invoked(this);
- }
- }
-
- listview_curses::invoke_scroll();
- }
+ void invoke_scroll();
textview_curses& set_reload_config_delegate(
std::function<void(textview_curses&)> func)
@@ -713,6 +801,19 @@ public:
std::function<void(textview_curses&)> tc_state_event_handler;
nonstd::optional<role_t> tc_cursor_role;
+ nonstd::optional<role_t> tc_disabled_cursor_role;
+
+ struct selected_text_info {
+ int sti_x;
+ int64_t sti_line;
+ line_range sti_range;
+ std::string sti_value;
+ };
+
+ nonstd::optional<selected_text_info> tc_selected_text;
+ bool tc_text_selection_active{false};
+ display_line_content_t tc_press_line;
+ int tc_press_left{0};
protected:
class grep_highlighter {
@@ -760,11 +861,11 @@ protected:
highlight_map_t tc_highlights;
std::set<highlight_source_t> tc_disabled_highlights;
- vis_line_t tc_selection_start{-1_vl};
- vis_line_t tc_selection_last{-1_vl};
- bool tc_selection_cleared{false};
+ nonstd::optional<vis_line_t> tc_selection_start;
+ mouse_event tc_press_event;
bool tc_hide_fields{true};
bool tc_paused{false};
+ bool tc_supports_marks{false};
std::string tc_current_search;
std::string tc_previous_search;