Additional NCursesUI code cleanups

This commit is contained in:
Maxime Coste 2019-09-17 19:24:19 +10:00
parent 2eccbbbe6f
commit 7f141e83ce
2 changed files with 6 additions and 19 deletions

View File

@ -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,26 +96,20 @@ void NCursesUI::Window::draw(Palette& palette, ConstArrayView<DisplayAtom> 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();
}
}
if (column < max_width)
wclrtoeol(win);
}
@ -579,7 +568,8 @@ Optional<Key> 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 {};
}

View File

@ -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<DisplayLine, MemoryDomain::Display> items;