diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index bc8a54cb..c6e67fb1 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -361,23 +361,16 @@ NCursesUI::NCursesUI() }}, m_assistant(assistant_clippy) { - fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) | O_NONBLOCK); - tcgetattr(STDIN_FILENO, &m_original_termios); - termios attr = m_original_termios; - attr.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); - attr.c_oflag &= ~OPOST; - attr.c_cflag |= CS8; - attr.c_lflag &= ~(ECHO | ICANON | ISIG | IEXTEN); - attr.c_lflag |= NOFLSH; - tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr); - enable_mouse(true); initscr(); curs_set(0); start_color(); use_default_colors(); + set_raw_mode(); + enable_mouse(true); + set_signal_handler(SIGWINCH, &signal_handler<&resize_pending>); set_signal_handler(SIGHUP, &signal_handler<&sighup_raised>); @@ -399,6 +392,22 @@ NCursesUI::~NCursesUI() set_signal_handler(SIGCONT, SIG_DFL); } +void NCursesUI::set_raw_mode() const +{ + fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) | O_NONBLOCK); + + termios attr = m_original_termios; + attr.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); + attr.c_oflag &= ~OPOST; + attr.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); + attr.c_lflag |= NOFLSH; + attr.c_cflag &= ~(CSIZE | PARENB); + attr.c_cflag |= CS8; + attr.c_cc[VMIN] = attr.c_cc[VTIME] = 0; + + tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr); +} + void NCursesUI::redraw(bool force) { m_window.refresh(force); @@ -605,10 +614,12 @@ Optional NCursesUI::get_next_key() { bool mouse_enabled = m_mouse_enabled; enable_mouse(false); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &m_original_termios); kill(0, SIGTSTP); // We suspend at this line check_resize(true); + set_raw_mode(); enable_mouse(mouse_enabled); return {}; } diff --git a/src/ncurses_ui.hh b/src/ncurses_ui.hh index 548307cf..ad4ccacc 100644 --- a/src/ncurses_ui.hh +++ b/src/ncurses_ui.hh @@ -119,6 +119,8 @@ private: DisplayCoord m_dimensions; termios m_original_termios; + void set_raw_mode() const; + void mark_dirty(const Window& win); struct Menu : Window