[ui] handle resizes during sql execution

Also, fix reporting of init command errors
This commit is contained in:
Tim Stack 2022-08-03 16:05:37 -07:00
parent a4fadb56f6
commit c5b8bd0ba4
4 changed files with 116 additions and 55 deletions

View File

@ -156,6 +156,10 @@ sql_progress(const struct log_cursor& lc)
lnav_data.ld_status[LNS_TOP].do_update();
lnav_data.ld_status[LNS_BOTTOM].do_update();
lnav_data.ld_rl_view->do_update();
if (handle_winch()) {
layout_views();
lnav_data.ld_view_stack.do_update();
}
refresh();
}
@ -841,45 +845,87 @@ execute_init_commands(
return;
}
nonstd::optional<exec_context::output_t> ec_out;
auto_fd fd_copy;
if (!(lnav_data.ld_flags & LNF_HEADLESS)) {
auto_mem<FILE> tmpout(fclose);
tmpout = std::tmpfile();
if (!tmpout) {
msgs.emplace_back(Err(lnav::console::user_message::error(
"Unable to open temporary output file")
.with_errno_reason()),
"");
return;
}
fd_copy = auto_fd::dup_of(fileno(tmpout));
ec_out = std::make_pair(tmpout.release(), fclose);
}
auto& dls = lnav_data.ld_db_row_source;
int option_index = 1;
log_info("Executing initial commands");
for (auto& cmd : lnav_data.ld_commands) {
static const auto COMMAND_OPTION_SRC
= intern_string::lookup("command-option");
{
log_info("Executing initial commands");
exec_context::output_guard og(ec, "tmp", ec_out);
std::string alt_msg;
for (auto& cmd : lnav_data.ld_commands) {
static const auto COMMAND_OPTION_SRC
= intern_string::lookup("command-option");
wait_for_children();
std::string alt_msg;
{
auto _sg = ec.enter_source(COMMAND_OPTION_SRC, option_index++, cmd);
switch (cmd.at(0)) {
case ':':
msgs.emplace_back(execute_command(ec, cmd.substr(1)),
alt_msg);
break;
case '/':
execute_search(cmd.substr(1));
break;
case ';':
setup_logline_table(ec);
msgs.emplace_back(execute_sql(ec, cmd.substr(1), alt_msg),
alt_msg);
break;
case '|':
msgs.emplace_back(execute_file(ec, cmd.substr(1)), alt_msg);
break;
wait_for_children();
log_debug("init cmd: %s", cmd.c_str());
{
auto _sg
= ec.enter_source(COMMAND_OPTION_SRC, option_index++, cmd);
switch (cmd.at(0)) {
case ':':
msgs.emplace_back(execute_command(ec, cmd.substr(1)),
alt_msg);
break;
case '/':
execute_search(cmd.substr(1));
break;
case ';':
setup_logline_table(ec);
msgs.emplace_back(
execute_sql(ec, cmd.substr(1), alt_msg), alt_msg);
break;
case '|':
msgs.emplace_back(execute_file(ec, cmd.substr(1)),
alt_msg);
break;
}
rescan_files();
rebuild_indexes_repeatedly();
}
if (dls.dls_rows.size() > 1) {
ensure_view(LNV_DB);
}
rescan_files();
rebuild_indexes_repeatedly();
}
}
lnav_data.ld_commands.clear();
if (dls.dls_rows.size() > 1) {
ensure_view(&lnav_data.ld_views[LNV_DB]);
struct stat st;
if (ec_out && fstat(fd_copy, &st) != -1 && st.st_size > 0) {
static const auto OUTPUT_NAME = std::string("Initial command output");
lnav_data.ld_active_files.fc_file_names[OUTPUT_NAME]
.with_fd(std::move(fd_copy))
.with_include_in_session(false)
.with_detect_format(false);
lnav_data.ld_files_to_front.emplace_back(OUTPUT_NAME, 0);
if (lnav_data.ld_rl_view != nullptr) {
lnav_data.ld_rl_view->set_alt_value(
HELP_MSG_1(X, "to close the file"));
}
}
lnav_data.ld_cmd_init_done = true;

View File

@ -1773,9 +1773,8 @@ UPDATE lnav_views_echo
lnav_data.ld_rl_view->set_value(
last_cmd_result.first.unwrap());
} else {
lnav_data.ld_rl_view->set_attr_value(
last_cmd_result.first.unwrapErr()
.to_attr_line());
ec.ec_error_callback_stack.back()(
last_cmd_result.first.unwrapErr());
}
lnav_data.ld_rl_view->set_alt_value(
last_cmd_result.second);
@ -1823,29 +1822,7 @@ UPDATE lnav_views_echo
}
}
if (lnav_data.ld_winched) {
struct winsize size;
lnav_data.ld_winched = false;
if (ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) {
resizeterm(size.ws_row, size.ws_col);
}
rlc->do_update();
rlc->window_change();
filter_source->fss_editor->window_change();
for (auto& sc : lnav_data.ld_status) {
sc.window_change();
}
lnav_data.ld_view_stack.set_needs_update();
lnav_data.ld_doc_view.set_needs_update();
lnav_data.ld_example_view.set_needs_update();
lnav_data.ld_match_view.set_needs_update();
lnav_data.ld_filter_view.set_needs_update();
lnav_data.ld_files_view.set_needs_update();
lnav_data.ld_spectro_details_view.set_needs_update();
lnav_data.ld_user_message_view.set_needs_update();
}
handle_winch();
if (lnav_data.ld_child_terminated) {
lnav_data.ld_child_terminated = false;

View File

@ -34,6 +34,7 @@
#include "config.h"
#include "document.sections.hh"
#include "environ_vtab.hh"
#include "filter_sub_source.hh"
#include "help-md.h"
#include "intervaltree/IntervalTree.h"
#include "lnav.hh"
@ -522,6 +523,42 @@ build_all_help_text()
lnav_data.ld_views[LNV_HELP].redo_search();
}
bool
handle_winch()
{
static auto* filter_source = injector::get<filter_sub_source*>();
if (!lnav_data.ld_winched) {
return false;
}
struct winsize size;
lnav_data.ld_winched = false;
if (ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) {
resizeterm(size.ws_row, size.ws_col);
}
if (lnav_data.ld_rl_view != nullptr) {
lnav_data.ld_rl_view->do_update();
lnav_data.ld_rl_view->window_change();
}
filter_source->fss_editor->window_change();
for (auto& sc : lnav_data.ld_status) {
sc.window_change();
}
lnav_data.ld_view_stack.set_needs_update();
lnav_data.ld_doc_view.set_needs_update();
lnav_data.ld_example_view.set_needs_update();
lnav_data.ld_match_view.set_needs_update();
lnav_data.ld_filter_view.set_needs_update();
lnav_data.ld_files_view.set_needs_update();
lnav_data.ld_spectro_details_view.set_needs_update();
lnav_data.ld_user_message_view.set_needs_update();
return true;
}
void
layout_views()
{

View File

@ -82,6 +82,7 @@ nonstd::optional<lnav_view_t> view_from_string(const char* name);
bool ensure_view(textview_curses* expected_tc);
bool ensure_view(lnav_view_t expected);
bool toggle_view(textview_curses* toggle_tc);
bool handle_winch();
void layout_views();
void update_hits(textview_curses* tc);