diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-07 04:48:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-07 04:48:35 +0000 |
commit | 207df6fc406e81bfeebdff7f404bd242ff3f099f (patch) | |
tree | a1a796b056909dd0a04ffec163db9363a8757808 /src/files_sub_source.cc | |
parent | Releasing progress-linux version 0.11.2-1~progress7.99u1. (diff) | |
download | lnav-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/files_sub_source.cc')
-rw-r--r-- | src/files_sub_source.cc | 317 |
1 files changed, 171 insertions, 146 deletions
diff --git a/src/files_sub_source.cc b/src/files_sub_source.cc index 03d0303..4f2fff2 100644 --- a/src/files_sub_source.cc +++ b/src/files_sub_source.cc @@ -30,6 +30,8 @@ #include "files_sub_source.hh" #include "base/ansi_scrubber.hh" +#include "base/attr_line.builder.hh" +#include "base/fs_util.hh" #include "base/humanize.hh" #include "base/humanize.network.hh" #include "base/opt_util.hh" @@ -37,6 +39,9 @@ #include "config.h" #include "lnav.hh" #include "mapbox/variant.hpp" +#include "sql_util.hh" + +using namespace lnav::roles::literals; namespace files_model { files_list_selection @@ -45,14 +50,18 @@ from_selection(vis_line_t sel_vis) auto& fc = lnav_data.ld_active_files; int sel = (int) sel_vis; - if (sel < fc.fc_name_to_errors.size()) { - auto iter = fc.fc_name_to_errors.begin(); + { + safe::ReadAccess<safe_name_to_errors> errs(*fc.fc_name_to_errors); - std::advance(iter, sel); - return error_selection::build(sel, iter); - } + if (sel < errs->size()) { + auto iter = errs->begin(); - sel -= fc.fc_name_to_errors.size(); + std::advance(iter, sel); + return error_selection::build(sel, iter->first); + } + + sel -= errs->size(); + } if (sel < fc.fc_other_files.size()) { auto iter = fc.fc_other_files.begin(); @@ -92,6 +101,7 @@ files_sub_source::list_input_handle_key(listview_curses& lv, int ch) auto& lss = lnav_data.ld_log_source; auto lf = *fs.sb_iter; + lf->set_indexing(true); lss.find_data(lf) | [](auto ld) { ld->set_visibility(true); lnav_data.ld_log_source.text_filters_changed(); @@ -131,6 +141,7 @@ files_sub_source::list_input_handle_key(listview_curses& lv, int ch) auto lf = *fs.sb_iter; lss.find_data(lf) | [](auto ld) { + ld->get_file_ptr()->set_indexing(!ld->ld_visible); ld->set_visibility(!ld->ld_visible); }; @@ -138,6 +149,10 @@ files_sub_source::list_input_handle_key(listview_curses& lv, int ch) auto tss = top_view->get_sub_source(); if (tss != nullptr) { + if (tss != &lss) { + lss.text_filters_changed(); + lnav_data.ld_views[LNV_LOG].reload_data(); + } tss->text_filters_changed(); top_view->reload_data(); } @@ -166,11 +181,11 @@ files_sub_source::list_input_handle_key(listview_curses& lv, int ch) [&](files_model::error_selection& es) { auto& fc = lnav_data.ld_active_files; - fc.fc_file_names.erase(es.sb_iter->first); + fc.fc_file_names.erase(es.sb_iter); auto name_iter = fc.fc_file_names.begin(); while (name_iter != fc.fc_file_names.end()) { - if (name_iter->first == es.sb_iter->first) { + if (name_iter->first == es.sb_iter) { name_iter = fc.fc_file_names.erase(name_iter); continue; } @@ -181,8 +196,7 @@ files_sub_source::list_input_handle_key(listview_curses& lv, int ch) if (rp_opt) { auto rp = *rp_opt; - if (fmt::to_string(rp.home()) == es.sb_iter->first) - { + if (fmt::to_string(rp.home()) == es.sb_iter) { fc.fc_other_files.erase(name_iter->first); name_iter = fc.fc_file_names.erase(name_iter); continue; @@ -191,7 +205,7 @@ files_sub_source::list_input_handle_key(listview_curses& lv, int ch) ++name_iter; } - fc.fc_name_to_errors.erase(es.sb_iter); + fc.fc_name_to_errors->writeAccess()->erase(es.sb_iter); fc.fc_invalidate_merge = true; lv.reload_data(); }, @@ -214,9 +228,10 @@ size_t files_sub_source::text_line_count() { const auto& fc = lnav_data.ld_active_files; + auto retval = fc.fc_name_to_errors->readAccess()->size() + + fc.fc_other_files.size() + fc.fc_files.size(); - return fc.fc_name_to_errors.size() + fc.fc_other_files.size() - + fc.fc_files.size(); + return retval; } size_t @@ -231,47 +246,83 @@ files_sub_source::text_value_for_line(textview_curses& tc, std::string& value_out, text_sub_source::line_flags_t flags) { + bool selected + = lnav_data.ld_mode == ln_mode_t::FILES && line == tc.get_selection(); const auto dim = tc.get_dimensions(); const auto& fc = lnav_data.ld_active_files; auto filename_width = std::min(fc.fc_largest_path_length, std::max((size_t) 40, (size_t) dim.second - 30)); - if (line < fc.fc_name_to_errors.size()) { - auto iter = fc.fc_name_to_errors.begin(); - std::advance(iter, line); - auto path = ghc::filesystem::path(iter->first); - auto fn = path.filename().string(); + this->fss_curr_line.clear(); + auto& al = this->fss_curr_line; + attr_line_builder alb(al); - truncate_to(fn, filename_width); - value_out = fmt::format(FMT_STRING(" {:<{}} {}"), - fn, - filename_width, - iter->second.fei_description); - return; + if (selected) { + al.append(" ", VC_GRAPHIC.value(ACS_RARROW)); + } else { + al.append(" "); } + { + safe::ReadAccess<safe_name_to_errors> errs(*fc.fc_name_to_errors); + + if (line < errs->size()) { + auto iter = std::next(errs->begin(), line); + auto path = ghc::filesystem::path(iter->first); + auto fn = fmt::to_string(path.filename()); + + truncate_to(fn, filename_width); + al.append(" "); + { + auto ag = alb.with_attr(VC_ROLE.value(role_t::VCR_ERROR)); + + al.appendf(FMT_STRING("{:<{}}"), fn, filename_width); + } + al.append(" ").append(iter->second.fei_description); + if (selected) { + al.with_attr_for_all( + VC_ROLE.value(role_t::VCR_DISABLED_FOCUSED)); + } + + value_out = al.get_string(); + return; + } - line -= fc.fc_name_to_errors.size(); + line -= errs->size(); + } if (line < fc.fc_other_files.size()) { - auto iter = fc.fc_other_files.begin(); - std::advance(iter, line); + auto iter = std::next(fc.fc_other_files.begin(), line); auto path = ghc::filesystem::path(iter->first); - auto fn = path.string(); + auto fn = fmt::to_string(path); truncate_to(fn, filename_width); - value_out = fmt::format(FMT_STRING(" {:<{}} {:14} {}"), - fn, - filename_width, - iter->second.ofd_format, - iter->second.ofd_description); + al.append(" "); + { + auto ag = alb.with_attr(VC_ROLE.value(role_t::VCR_FILE)); + + al.appendf(FMT_STRING("{:<{}}"), fn, filename_width); + } + al.append(" ") + .appendf(FMT_STRING("{:14}"), iter->second.ofd_format) + .append(" ") + .append(iter->second.ofd_description); + if (selected) { + al.with_attr_for_all(VC_ROLE.value(role_t::VCR_DISABLED_FOCUSED)); + } + if (line == fc.fc_other_files.size() - 1) { + al.with_attr_for_all(VC_STYLE.value(text_attrs{A_UNDERLINE})); + } + + value_out = al.get_string(); return; } line -= fc.fc_other_files.size(); const auto& lf = fc.fc_files[line]; - auto fn = lf->get_unique_path(); + auto ld_opt = lnav_data.ld_log_source.find_data(lf); + auto fn = fmt::to_string(ghc::filesystem::path(lf->get_unique_path())); char start_time[64] = "", end_time[64] = ""; std::vector<std::string> file_notes; @@ -283,14 +334,38 @@ files_sub_source::text_value_for_line(textview_curses& tc, for (const auto& pair : lf->get_notes()) { file_notes.push_back(pair.second); } - value_out = fmt::format(FMT_STRING(" {:<{}} {:>8} {} \u2014 {} {}"), - fn, - filename_width, - humanize::file_size(lf->get_index_size(), - humanize::alignment::columnar), - start_time, - end_time, - fmt::join(file_notes, "; ")); + + al.append(" "); + if (ld_opt) { + if (ld_opt.value()->ld_visible) { + al.append("\u25c6"_ok); + } else { + al.append("\u25c7"_comment); + } + } else { + al.append("\u25c6"_comment); + } + al.append(" "); + al.appendf(FMT_STRING("{:<{}}"), fn, filename_width); + al.append(" "); + { + auto ag = alb.with_attr(VC_ROLE.value(role_t::VCR_NUMBER)); + + al.appendf(FMT_STRING("{:>8}"), + humanize::file_size(lf->get_index_size(), + humanize::alignment::columnar)); + } + al.append(" ") + .append(start_time) + .append(" \u2014 ") + .append(end_time) + .append(" ") + .appendf(FMT_STRING("{}"), fmt::join(file_notes, "; ")); + if (selected) { + al.with_attr_for_all(VC_ROLE.value(role_t::VCR_FOCUSED)); + } + + value_out = al.get_string(); this->fss_last_line_len = filename_width + 23 + strlen(start_time) + strlen(end_time); } @@ -300,72 +375,7 @@ files_sub_source::text_attrs_for_line(textview_curses& tc, int line, string_attrs_t& value_out) { - bool selected - = lnav_data.ld_mode == ln_mode_t::FILES && line == tc.get_selection(); - const auto& fc = lnav_data.ld_active_files; - const auto dim = tc.get_dimensions(); - auto filename_width - = std::min(fc.fc_largest_path_length, - std::max((size_t) 40, (size_t) dim.second - 30)); - - if (selected) { - value_out.emplace_back(line_range{0, 1}, VC_GRAPHIC.value(ACS_RARROW)); - } - - if (line < fc.fc_name_to_errors.size()) { - if (selected) { - value_out.emplace_back(line_range{0, -1}, - VC_ROLE.value(role_t::VCR_DISABLED_FOCUSED)); - } - - value_out.emplace_back(line_range{4 + (int) filename_width, -1}, - VC_ROLE_FG.value(role_t::VCR_ERROR)); - return; - } - line -= fc.fc_name_to_errors.size(); - - if (line < fc.fc_other_files.size()) { - if (selected) { - value_out.emplace_back(line_range{0, -1}, - VC_ROLE.value(role_t::VCR_DISABLED_FOCUSED)); - } - if (line == fc.fc_other_files.size() - 1) { - value_out.emplace_back(line_range{0, -1}, - VC_STYLE.value(text_attrs{A_UNDERLINE})); - } - return; - } - - line -= fc.fc_other_files.size(); - - if (selected) { - value_out.emplace_back(line_range{0, -1}, - VC_ROLE.value(role_t::VCR_FOCUSED)); - } - - auto& lss = lnav_data.ld_log_source; - auto& lf = fc.fc_files[line]; - auto ld_opt = lss.find_data(lf); - - chtype visible = ACS_DIAMOND; - if (ld_opt && !ld_opt.value()->ld_visible) { - visible = ' '; - } - value_out.emplace_back(line_range{2, 3}, VC_GRAPHIC.value(visible)); - if (visible == ACS_DIAMOND) { - value_out.emplace_back(line_range{2, 3}, - VC_FOREGROUND.value(COLOR_GREEN)); - } - - auto lr = line_range{ - (int) filename_width + 3 + 4, - (int) filename_width + 3 + 10, - }; - value_out.emplace_back(lr, VC_STYLE.value(text_attrs{A_BOLD})); - - lr.lr_start = this->fss_last_line_len; - lr.lr_end = -1; - value_out.emplace_back(lr, VC_FOREGROUND.value(COLOR_YELLOW)); + value_out = this->fss_curr_line.get_attrs(); } size_t @@ -388,45 +398,60 @@ spinner_index() } bool -files_overlay_source::list_value_for_overlay(const listview_curses& lv, - int y, - int bottom, - vis_line_t line, - attr_line_t& value_out) +files_overlay_source::list_static_overlay(const listview_curses& lv, + int y, + int bottom, + attr_line_t& value_out) { - if (y == 0) { - static const char PROG[] = "-\\|/"; - constexpr size_t PROG_SIZE = sizeof(PROG) - 1; - - auto& fc = lnav_data.ld_active_files; - auto fc_prog = fc.fc_progress; - safe::WriteAccess<safe_scan_progress> sp(*fc_prog); - - if (!sp->sp_extractions.empty()) { - const auto& prog = sp->sp_extractions.front(); - - value_out.with_ansi_string(fmt::format( - "{} Extracting " ANSI_COLOR(COLOR_CYAN) "{}" ANSI_NORM - "... {:>8}/{}", - PROG[spinner_index() % PROG_SIZE], - prog.ep_path.filename().string(), - humanize::file_size(prog.ep_out_size, - humanize::alignment::none), - humanize::file_size(prog.ep_total_size, - humanize::alignment::none))); - return true; - } - if (!sp->sp_tailers.empty()) { - auto first_iter = sp->sp_tailers.begin(); - - value_out.with_ansi_string(fmt::format( - "{} Connecting to " ANSI_COLOR(COLOR_CYAN) "{}" ANSI_NORM - ": {}", - PROG[spinner_index() % PROG_SIZE], - first_iter->first, - first_iter->second.tp_message)); - return true; - } + if (y != 0) { + return false; + } + static const char PROG[] = "-\\|/"; + constexpr size_t PROG_SIZE = sizeof(PROG) - 1; + + auto& fc = lnav_data.ld_active_files; + auto fc_prog = fc.fc_progress; + safe::WriteAccess<safe_scan_progress> sp(*fc_prog); + + if (!sp->sp_extractions.empty()) { + const auto& prog = sp->sp_extractions.front(); + + value_out.with_ansi_string(fmt::format( + "{} Extracting " ANSI_COLOR(COLOR_CYAN) "{}" ANSI_NORM + "... {:>8}/{}", + PROG[spinner_index() % PROG_SIZE], + prog.ep_path.filename().string(), + humanize::file_size(prog.ep_out_size, humanize::alignment::none), + humanize::file_size(prog.ep_total_size, + humanize::alignment::none))); + return true; } + if (!sp->sp_tailers.empty()) { + auto first_iter = sp->sp_tailers.begin(); + + value_out.with_ansi_string(fmt::format( + "{} Connecting to " ANSI_COLOR(COLOR_CYAN) "{}" ANSI_NORM ": {}", + PROG[spinner_index() % PROG_SIZE], + first_iter->first, + first_iter->second.tp_message)); + return true; + } + + return false; +} + +bool +files_sub_source::text_handle_mouse( + textview_curses& tc, + const listview_curses::display_line_content_t&, + mouse_event& me) +{ + if (me.is_click_in(mouse_button_t::BUTTON_LEFT, 1, 3)) { + this->list_input_handle_key(tc, ' '); + } + if (me.is_double_click_in(mouse_button_t::BUTTON_LEFT, line_range{4, -1})) { + this->list_input_handle_key(tc, '\r'); + } + return false; } |