[rescan] automatically pop the text view when the last text file is promoted

This commit is contained in:
Timothy Stack 2022-04-04 21:54:20 -07:00
parent 292724d7ad
commit 1019714409
8 changed files with 51 additions and 17 deletions

View File

@ -97,7 +97,6 @@ line_filter_observer::clear_deleted_filter_state()
{
uint32_t used_mask = 0;
log_debug("filter stack %p", &this->lfo_filter_stack);
for (auto& filter : this->lfo_filter_stack) {
if (filter->lf_deleted) {
log_debug("skipping deleted %p %d %d",

View File

@ -314,6 +314,7 @@ handle_paging_key(int ch)
if (!tss.empty()) {
tss.rotate_left();
}
tc->reload_data();
}
break;
@ -327,6 +328,7 @@ handle_paging_key(int ch)
if (!tss.empty()) {
tss.rotate_right();
}
tc->reload_data();
}
break;

View File

@ -61,6 +61,7 @@ listview_curses::reload_data()
}
}
this->vc_needs_update = true;
this->invoke_scroll();
}
bool

View File

@ -1467,7 +1467,7 @@ looper()
sb.push_back(
bind_mem(&term_extra::update_title, injector::get<term_extra*>()));
vsb.push_back([](listview_curses* lv) {
auto tc = static_cast<textview_curses*>(lv);
auto* tc = dynamic_cast<textview_curses*>(lv);
tc->tc_state_event_handler(*tc);
});
@ -1664,7 +1664,6 @@ looper()
}
active_copy.clear();
active_copy.merge(lnav_data.ld_active_files);
rescan_future = std::future<file_collection>{};
next_rescan_time = ui_clock::now() + 333ms;
}
@ -1672,6 +1671,8 @@ looper()
if (!rescan_future.valid()
&& (session_stage < 2 || ui_clock::now() >= next_rescan_time))
{
active_copy.clear();
active_copy.merge(lnav_data.ld_active_files);
rescan_future = std::async(std::launch::async,
&file_collection::rescan_files,
std::move(active_copy),
@ -1687,10 +1688,21 @@ looper()
auto ui_now = ui_clock::now();
if (initial_rescan_completed) {
if (ui_now >= next_rebuild_time) {
auto text_file_count = lnav_data.ld_text_source.size();
changes += rebuild_indexes(loop_deadline);
if (!changes && ui_clock::now() < loop_deadline) {
next_rebuild_time = ui_clock::now() + 333ms;
}
if (changes && text_file_count
&& lnav_data.ld_text_source.empty()
&& lnav_data.ld_view_stack.top().value_or(nullptr)
== &lnav_data.ld_views[LNV_TEXT])
{
do {
lnav_data.ld_view_stack.pop_back();
} while (lnav_data.ld_view_stack.top().value_or(nullptr)
!= &lnav_data.ld_views[LNV_LOG]);
}
}
} else {
lnav_data.ld_files_view.set_overlay_needs_update();
@ -1849,6 +1861,8 @@ looper()
[](auto tc) { lnav_data.ld_bottom_source.update_hits(tc); };
auto old_mode = lnav_data.ld_mode;
auto old_file_names_size
= lnav_data.ld_active_files.fc_file_names.size();
rlc.check_poll_set(pollfds);
lnav_data.ld_filter_source.fss_editor.check_poll_set(pollfds);
lnav_data.ld_filter_view.check_poll_set(pollfds);
@ -1866,6 +1880,12 @@ looper()
break;
}
}
if (old_file_names_size
!= lnav_data.ld_active_files.fc_file_names.size()) {
next_rescan_time = ui_clock::now();
next_rebuild_time = next_rescan_time;
next_status_update_time = next_rescan_time;
}
}
if (timer.time_to_update(overlay_counter)) {

View File

@ -2226,15 +2226,20 @@ com_open(exec_context& ec, std::string cmdline, std::vector<std::string>& args)
if (args.empty()) {
args.emplace_back("filename");
return Ok(std::string());
} else if (lnav_data.ld_flags & LNF_SECURE_MODE) {
}
if (lnav_data.ld_flags & LNF_SECURE_MODE) {
return ec.make_error("{} -- unavailable in secure mode", args[0]);
} else if (args.size() < 2) {
}
if (args.size() < 2) {
return ec.make_error("expecting file name to open");
}
std::vector<std::string> word_exp;
size_t colon_index;
std::string pat;
file_collection fc;
pat = trim(remaining_args(cmdline, args));
@ -2249,7 +2254,6 @@ com_open(exec_context& ec, std::string cmdline, std::vector<std::string>& args)
return ec.make_error("unable to parse arguments");
}
std::map<std::string, logfile_open_options> file_names;
std::vector<std::pair<std::string, int>> files_to_front;
std::vector<std::string> closed_files;
@ -2312,11 +2316,11 @@ com_open(exec_context& ec, std::string cmdline, std::vector<std::string>& args)
}
#endif
} else if (is_glob(fn.c_str())) {
file_names.emplace(fn, logfile_open_options());
fc.fc_file_names.emplace(fn, logfile_open_options());
retval = "info: watching -- " + fn;
} else if (stat(fn.c_str(), &st) == -1) {
if (fn.find(':') != std::string::npos) {
file_names.emplace(fn, logfile_open_options());
fc.fc_file_names.emplace(fn, logfile_open_options());
retval = "info: watching -- " + fn;
} else {
return ec.make_error(
@ -2361,7 +2365,8 @@ com_open(exec_context& ec, std::string cmdline, std::vector<std::string>& args)
if (dir_wild[dir_wild.size() - 1] == '/') {
dir_wild.resize(dir_wild.size() - 1);
}
file_names.emplace(dir_wild + "/*", logfile_open_options());
fc.fc_file_names.emplace(dir_wild + "/*",
logfile_open_options());
retval = "info: watching -- " + dir_wild;
} else if (!S_ISREG(st.st_mode)) {
return ec.make_error("not a regular file or directory -- {}",
@ -2371,7 +2376,7 @@ com_open(exec_context& ec, std::string cmdline, std::vector<std::string>& args)
"cannot read file {} -- {}", fn, strerror(errno));
} else {
fn = abspath.in();
file_names.emplace(fn, logfile_open_options());
fc.fc_file_names.emplace(fn, logfile_open_options());
retval = "info: opened -- " + fn;
files_to_front.emplace_back(fn, top);
@ -2386,8 +2391,8 @@ com_open(exec_context& ec, std::string cmdline, std::vector<std::string>& args)
if (ec.ec_dry_run) {
lnav_data.ld_preview_source.clear();
if (!file_names.empty()) {
auto iter = file_names.begin();
if (!fc.fc_file_names.empty()) {
auto iter = fc.fc_file_names.begin();
std::string fn = iter->first;
auto_fd preview_fd;
@ -2467,12 +2472,11 @@ com_open(exec_context& ec, std::string cmdline, std::vector<std::string>& args)
lnav_data.ld_files_to_front.insert(lnav_data.ld_files_to_front.end(),
files_to_front.begin(),
files_to_front.end());
lnav_data.ld_active_files.fc_file_names.insert(
std::make_move_iterator(file_names.begin()),
std::make_move_iterator(file_names.end()));
for (const auto& fn : closed_files) {
lnav_data.ld_active_files.fc_closed_files.erase(fn);
fc.fc_closed_files.erase(fn);
}
lnav_data.ld_active_files.merge(fc);
}
return Ok(retval);

View File

@ -504,8 +504,9 @@ view_colors::init()
}
for (int fg = 0; fg < 8; fg++) {
for (int bg = 0; bg < 8; bg++) {
if (fg == 0 && bg == 0)
if (fg == 0 && bg == 0) {
continue;
}
if (lnav_config.lc_ui_default_colors
&& ansi_colors_to_curses[fg] == COLOR_WHITE

View File

@ -548,6 +548,11 @@ public:
this->set_needs_update();
}
iterator find(T* view) const
{
return std::find(this->begin(), this->end(), view);
}
iterator begin()
{
return this->vs_views.begin();

View File

@ -202,6 +202,7 @@ run_test ${lnav_test} -n -d /tmp/lnav.err \
${test_dir}/logfile_access_log.0
check_output "disable after :filter-in is not working" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:26 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
EOF
@ -214,6 +215,7 @@ run_test ${lnav_test} -n -d /tmp/lnav.err \
${test_dir}/logfile_access_log.0
check_output "filter-in vmk is not working" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:26 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
EOF