Fix filename column width and attributes

Display the basename instead of the whole path for each file when
the filename column is displayed. Make the column the same width all
the time, taking the maximum basename width of all loaded files and
padding with spaces.

Also fix the attributes when the filename column is displayed.  Insert
the correct filename-matching color for as many characters as we add for
the filename column.  Use the full filename when looking up the color
because we don't want files in different paths to have the same color,
and we don't want the color to change based on whether we are displaying
the base or the whole filename.
pull/507/head
Phil Hord 6 years ago
parent 9ffbc1ac46
commit 81974c6bdc

@ -193,13 +193,15 @@ 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);
} else {
// Insert space for the file/search-hit markers.
value_out.insert(0, 1, ' ');
value_out.insert(0, this->lss_token_file->get_filename());
}
// Insert space for the file/search-hit markers.
value_out.insert(0, 1, ' ');
if (this->lss_flags & F_TIME_OFFSET) {
int64_t start_millis, curr_millis;
@ -336,6 +338,15 @@ void logfile_sub_source::text_attrs_for_line(textview_curses &lv,
lr, &view_curses::VC_STYLE, A_REVERSE));
}
}
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())));
@ -473,6 +484,7 @@ bool logfile_sub_source::rebuild_index(bool force)
this->lss_index.clear();
this->lss_filtered_index.clear();
this->lss_longest_line = 0;
this->lss_basename_width = 0;
}
if (retval || force) {
@ -487,6 +499,8 @@ bool logfile_sub_source::rebuild_index(bool force)
}
this->lss_longest_line = std::max(
this->lss_longest_line, lf->get_longest_line_length());
this->lss_basename_width = std::max(
this->lss_basename_width, lf->get_basename().size());;
}
if (full_sort) {

@ -625,6 +625,7 @@ private:
ll <= this->lss_max_log_time);
};
size_t lss_basename_width = 0;
unsigned long lss_flags;
bool lss_force_rebuild;
std::vector<logfile_data *> lss_files;

Loading…
Cancel
Save