diff options
| author | Maxime Coste <mawww@kakoune.org> | 2019-09-09 19:39:53 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2019-09-16 07:38:24 +1000 |
| commit | f43ac3d78b910e1523915ece68db0a3f1e5425b4 (patch) | |
| tree | 00a0655843045632cf31dfb86e750ba3ae32f6c0 /src | |
| parent | e52b93b31a64ba08d2cd883de0a99509f67c8638 (diff) | |
Fix broken input after suspend
Diffstat (limited to 'src')
| -rw-r--r-- | src/ncurses_ui.cc | 31 | ||||
| -rw-r--r-- | src/ncurses_ui.hh | 2 |
2 files changed, 23 insertions, 10 deletions
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<Key> 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 |
