diff --git a/src/main.cc b/src/main.cc index a9abba6f..1026b4f9 100644 --- a/src/main.cc +++ b/src/main.cc @@ -107,8 +107,8 @@ struct startup_error : runtime_error using runtime_error::runtime_error; }; -inline void write_stdout(StringView str) { try { write(1, str); } catch (runtime_error&) {} } -inline void write_stderr(StringView str) { try { write(2, str); } catch (runtime_error&) {} } +inline void write_stdout(StringView str) { try { write(STDOUT_FILENO, str); } catch (runtime_error&) {} } +inline void write_stderr(StringView str) { try { write(STDERR_FILENO, str); } catch (runtime_error&) {} } String runtime_directory() { diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 9cae305c..bc8a54cb 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -16,7 +16,6 @@ #include #include #include -#include #include constexpr char control(char c) { return c & 037; } @@ -352,7 +351,7 @@ static void signal_handler(int) NCursesUI::NCursesUI() : m_cursor{CursorMode::Buffer, {}}, - m_stdin_watcher{0, FdEvents::Read, + m_stdin_watcher{STDIN_FILENO, FdEvents::Read, [this](FDWatcher&, FdEvents, EventMode) { if (not m_on_key) return; @@ -362,26 +361,27 @@ 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(); - raw(); - noecho(); - nonl(); curs_set(0); start_color(); use_default_colors(); - set_escdelay(25); - intrflush(nullptr, false); - meta(nullptr, true); - - enable_mouse(true); - - fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) | O_NONBLOCK); set_signal_handler(SIGWINCH, &signal_handler<&resize_pending>); set_signal_handler(SIGHUP, &signal_handler<&sighup_raised>); check_resize(true); - redraw(false); } @@ -394,6 +394,7 @@ NCursesUI::~NCursesUI() fflush(stdout); } endwin(); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &m_original_termios); set_signal_handler(SIGWINCH, SIG_DFL); set_signal_handler(SIGCONT, SIG_DFL); } @@ -584,7 +585,7 @@ Optional NCursesUI::get_next_key() static auto get_char = []() -> Optional { unsigned char c = 0; - if (read(0, &c, 1) == 1) + if (read(STDIN_FILENO, &c, 1) == 1) return c; return {}; }; diff --git a/src/ncurses_ui.hh b/src/ncurses_ui.hh index ae25361c..548307cf 100644 --- a/src/ncurses_ui.hh +++ b/src/ncurses_ui.hh @@ -10,6 +10,8 @@ #include "string.hh" #include "user_interface.hh" +#include + namespace Kakoune { @@ -115,6 +117,7 @@ private: Window m_window; DisplayCoord m_dimensions; + termios m_original_termios; void mark_dirty(const Window& win);