From 2713f3564e8c218b153e02e8c4ef37336c185929 Mon Sep 17 00:00:00 2001 From: Timothy Stack Date: Thu, 8 Oct 2009 17:33:59 -0700 Subject: [PATCH] always restore the termios before exiting --- src/lnav.cc | 36 ++++++++++++++++++++++++++++++++++-- test/scripty.cc | 11 +++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/lnav.cc b/src/lnav.cc index 6a5e6b8e..432a0092 100644 --- a/src/lnav.cc +++ b/src/lnav.cc @@ -1013,13 +1013,21 @@ static void handle_paging_key(int ch) case 'I': { - time_t tt = lnav_data.ld_top_time; + time_t log_top = lnav_data.ld_top_time; + + time_t hist_top = + lnav_data.ld_hist_source.value_for_row(tc->get_top()); if (toggle_view(&lnav_data.ld_views[LNV_HISTOGRAM])) { hist_source &hs = lnav_data.ld_hist_source; tc = lnav_data.ld_view_stack.top(); - tc->set_top(hs.row_for_value(tt)); + tc->set_top(hs.row_for_value(log_top)); + } + else { + tc = lnav_data.ld_view_stack.top(); + tc->set_top(lss.find_from_time(hist_top)); + tc->set_needs_update(); } } break; @@ -2318,6 +2326,29 @@ private: pcrecpp::RE slt_regex; }; +class guard_termios { +public: + guard_termios(int fd) : gt_fd(fd) { + + if (isatty(this->gt_fd) && + tcgetattr(this->gt_fd, &this->gt_termios) == -1) { + perror("tcgetattr"); + } + + }; + + ~guard_termios() { + if (isatty(this->gt_fd) && + tcsetattr(this->gt_fd, TCSANOW, &this->gt_termios) == -1) { + perror("tcsetattr"); + } + }; + +private: + int gt_fd; + struct termios gt_termios; +}; + int main(int argc, char *argv[]) { int lpc, c, retval = EXIT_SUCCESS; @@ -2483,6 +2514,7 @@ int main(int argc, char *argv[]) lnav_data.ld_log_source.insert_file(lf); } + guard_termios gt(STDIN_FILENO); looper(); } catch (line_buffer::error & e) { diff --git a/test/scripty.cc b/test/scripty.cc index ce2bcc1b..60770c84 100644 --- a/test/scripty.cc +++ b/test/scripty.cc @@ -207,7 +207,6 @@ static char *hex2bits(const char *src) static void sigchld(int sig) { - scripty_data.sd_looping = false; } static void sigpass(int sig) @@ -224,7 +223,7 @@ static void usage(void) "\n" "Options:\n" " -h Print this message, then exit.\n" - " -t The file where any input send to the child process\n" + " -t The file where any input sent to the child process\n" " should be stored.\n" " -f The file where any output from the child process\n" " should be stored.\n"; @@ -522,6 +521,14 @@ int main(int argc, char *argv[]) rc = read(ct.get_fd(), buffer, sizeof(buffer)); if (rc <= 0) { scripty_data.sd_looping = false; + if (scripty_data.sd_from_child) { + fprintf(scripty_data.sd_from_child, "read "); + dump_memory(scripty_data.sd_from_child, + out_buffer, + out_len); + fprintf(scripty_data.sd_from_child, "\n"); + out_len = 0; + } } else { if (passout)