From 4d4ac9b8b0eb891d66336af6e247036ebd113334 Mon Sep 17 00:00:00 2001 From: Phil Hord Date: Tue, 27 Mar 2018 15:58:44 -0700 Subject: [PATCH] Add another filename mode to show file path Add a separate BASENAME bit to distinguish from the FILENAME bit. When BASENAME is active show the base filename in the filename column. When FILENAME is active show the whole path for each filename. Cycle through the three modes with toggle_filename() still. Note that we are never in both FILENAME and BASENAME mode. The user can cycle through the three modes by pressing the hotkey an extra time. First press shows the basename, second press shows the full path (filename), and the third press hides the filename column again. --- src/logfile_sub_source.cc | 41 ++++++++++++++++++++++++++------------- src/logfile_sub_source.hh | 19 +++++++++++++++++- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/logfile_sub_source.cc b/src/logfile_sub_source.cc index acd33b3e..10ed09a1 100644 --- a/src/logfile_sub_source.cc +++ b/src/logfile_sub_source.cc @@ -192,11 +192,18 @@ void logfile_sub_source::text_value_for_line(textview_curses &tc, } } - if (this->lss_flags & F_FILENAME) { - auto file_offset_end = this->lss_basename_width + 1; - auto const & basename = this->lss_token_file->get_basename(); - value_out.insert(0, file_offset_end - basename.size(), ' '); - value_out.insert(0, basename); + if (this->lss_flags & F_FILENAME || this->lss_flags & F_BASENAME) { + size_t file_offset_end; + std::string name; + if (this->lss_flags & F_FILENAME) { + file_offset_end = this->lss_filename_width; + name = this->lss_token_file->get_filename(); + } else { + file_offset_end = this->lss_basename_width; + name = this->lss_token_file->get_basename(); + } + value_out.insert(0, file_offset_end - name.size() + 1, ' '); + value_out.insert(0, name); } else { // Insert space for the file/search-hit markers. value_out.insert(0, 1, ' '); @@ -339,17 +346,22 @@ void logfile_sub_source::text_attrs_for_line(textview_curses &lv, } } - if (this->lss_flags & F_FILENAME) { - auto file_offset_end = this->lss_basename_width; - - shift_string_attrs(value_out, 0, file_offset_end ); - lr.lr_start = 0; - lr.lr_end = file_offset_end + 1; - } - value_out.push_back(string_attr(lr, &view_curses::VC_STYLE, vc.attrs_for_ident( this->lss_token_file->get_filename()))); + if (this->lss_flags & F_FILENAME || this->lss_flags & F_BASENAME) { + size_t file_offset_end = (this->lss_flags & F_FILENAME) ? + this->lss_filename_width : + this->lss_basename_width ; + + shift_string_attrs(value_out, 0, file_offset_end); + + lr.lr_start = 0; + lr.lr_end = file_offset_end + 1; + value_out.push_back(string_attr(lr, &view_curses::VC_STYLE, vc.attrs_for_ident( + this->lss_token_file->get_filename()))); + } + if (this->lss_flags & F_TIME_OFFSET) { time_offset_end = 13; lr.lr_start = 0; @@ -485,6 +497,7 @@ bool logfile_sub_source::rebuild_index(bool force) this->lss_filtered_index.clear(); this->lss_longest_line = 0; this->lss_basename_width = 0; + this->lss_filename_width = 0; } if (retval || force) { @@ -501,6 +514,8 @@ bool logfile_sub_source::rebuild_index(bool force) this->lss_longest_line, lf->get_longest_line_length()); this->lss_basename_width = std::max( this->lss_basename_width, lf->get_basename().size());; + this->lss_filename_width = std::max( + this->lss_filename_width, lf->get_filename().size());; } if (full_sort) { diff --git a/src/logfile_sub_source.hh b/src/logfile_sub_source.hh index de2bd974..33ddb9c4 100644 --- a/src/logfile_sub_source.hh +++ b/src/logfile_sub_source.hh @@ -98,7 +98,17 @@ public: }; void toggle_filename(void) { - this->lss_flags ^= F_FILENAME; + // NONE -> F_BASENAME -> F_FILENAME -> NONE ... + if (this->lss_flags & F_BASENAME) { + // F_BASENAME -> F_FILENAME + this->lss_flags ^= F_BASENAME | F_FILENAME; + } else if (this->lss_flags & F_FILENAME) { + // F_FILENAME -> NONE + this->lss_flags ^= F_FILENAME; + } else { + // NONE -> F_BASENAME + this->lss_flags ^= F_BASENAME; + } this->clear_line_size_cache(); }; @@ -118,6 +128,10 @@ public: return (bool) (this->lss_flags & F_FILENAME); }; + bool is_basename_enabled(void) const { + return (bool) (this->lss_flags & F_BASENAME); + }; + logline::level_t get_min_log_level(void) const { return this->lss_min_log_level; }; @@ -501,12 +515,14 @@ private: B_SCRUB, B_TIME_OFFSET, B_FILENAME, + B_BASENAME, }; enum { F_SCRUB = (1L << B_SCRUB), F_TIME_OFFSET = (1L << B_TIME_OFFSET), F_FILENAME = (1L << B_FILENAME), + F_BASENAME = (1L << B_BASENAME), }; struct __attribute__((__packed__)) indexed_content { @@ -626,6 +642,7 @@ private: }; size_t lss_basename_width = 0; + size_t lss_filename_width = 0; unsigned long lss_flags; bool lss_force_rebuild; std::vector lss_files;