From 7f141e83ce260d299ff08f724a0cdc598dc73b95 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 17 Sep 2019 19:24:19 +1000 Subject: [PATCH] Additional NCursesUI code cleanups --- src/ncurses_ui.cc | 22 ++++++---------------- src/ncurses_ui.hh | 3 --- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 7196f3448..0fc4642b3 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -38,11 +38,6 @@ void NCursesUI::Window::create(const DisplayCoord& p, const DisplayCoord& s) void NCursesUI::Window::destroy() { delwin(win); - invalidate(); -} - -void NCursesUI::Window::invalidate() -{ win = nullptr; pos = DisplayCoord{}; size = DisplayCoord{}; @@ -101,25 +96,19 @@ void NCursesUI::Window::draw(Palette& palette, ConstArrayView atoms ColumnCount column = 0; for (const DisplayAtom& atom : atoms) { - set_face(atom.face); - - StringView content = atom.content(); + StringView content = atom.content().substr(0_col, max_width - column); if (content.empty()) continue; - const auto remaining_columns = max_width - column; - if (content.back() == '\n' and - content.column_length() - 1 < remaining_columns) + set_face(atom.face); + if (content.back() == '\n') { add_str(content.substr(0, content.length()-1)); waddch(win, ' '); } else - { - content = content.substr(0_col, remaining_columns); add_str(content); - column += content.column_length(); - } + column += content.column_length(); } if (column < max_width) wclrtoeol(win); @@ -579,7 +568,8 @@ Optional NCursesUI::get_next_key() { set_signal_handler(SIGWINCH, SIG_DFL); set_signal_handler(SIGCONT, SIG_DFL); - m_window.invalidate(); + if (m_window) + m_window.destroy(); m_stdin_watcher.disable(); return {}; } diff --git a/src/ncurses_ui.hh b/src/ncurses_ui.hh index ee695fc35..9f2e97528 100644 --- a/src/ncurses_ui.hh +++ b/src/ncurses_ui.hh @@ -99,7 +99,6 @@ private: { void create(const DisplayCoord& pos, const DisplayCoord& size); void destroy(); - void invalidate(); void refresh(bool force); void move_cursor(DisplayCoord coord); void mark_dirty(LineCount pos, LineCount count); @@ -119,8 +118,6 @@ private: void set_raw_mode() const; - void mark_dirty(const Window& win); - struct Menu : Window { Vector items;