From daa63ba8799f8874e3c87b6cb7f81c4c4b80b800 Mon Sep 17 00:00:00 2001 From: nojhan Date: Mon, 5 Apr 2021 20:21:48 +0200 Subject: [PATCH 1/3] [feat] add ui_options: padding_char & padding_fill In some cases, it may be difficult to easily spot the area out of the buffer (bad color scheme, small font, superimposed windows). This patch adds two ncurses ui_options to bypass this problem: - `ncurses_padding_char`, to configure the padding character, - `ncurses_padding_fill`, to indicate whether to fill the padding line (or to display a single character). The default config is the legacy one (a single "~"). --- doc/pages/options.asciidoc | 9 +++++++++ src/ncurses_ui.cc | 25 ++++++++++++++++++++++++- src/ncurses_ui.hh | 3 +++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/doc/pages/options.asciidoc b/doc/pages/options.asciidoc index a63fe39a..c12c9721 100644 --- a/doc/pages/options.asciidoc +++ b/doc/pages/options.asciidoc @@ -353,6 +353,15 @@ are exclusively available to built-in options. Function key from which shifted function key start, if the terminal sends F13 for , this should be set to 12. + *ncurses_padding_char*::: + character used to indicate the area out of the displayed buffer + (defaults to '~') + + *ncurses_padding_fill*::: + if *yes* or *true*, fill the padding area with the padding character + instead of displaying a single character at the beginning of the + padding line (defaults to *false*) + [[startup-info]] *startup_info_version* `int`:: _default_ 0 + diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 17006c13..d2d93b0e 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -474,7 +474,14 @@ void NCursesUI::draw(const DisplayBuffer& display_buffer, while (line_index < dim.line + line_offset) { m_window.move_cursor(line_index++); - m_window.draw(m_palette, DisplayAtom("~"), face); + if (m_padding_fill) + { + ColumnCount column_index = 0; + while (column_index++ < dim.column) + m_window.draw(m_palette, m_padding_char, face); + } + else + m_window.draw(m_palette, m_padding_char, face); } m_dirty = true; @@ -1361,6 +1368,22 @@ void NCursesUI::set_ui_options(const Options& options) m_wheel_scroll_amount = wheel_scroll_amount_it != options.end() ? str_to_int_ifp(wheel_scroll_amount_it->value).value_or(3) : 3; } + + { + auto it = options.find("ncurses_padding_char"_sv); + if (it == options.end()) + m_padding_char = DisplayAtom("~"); + else if (it->value.length() < 1) + m_padding_char = DisplayAtom(" "); + else + m_padding_char = DisplayAtom(it->value); + } + + { + auto it = options.find("ncurses_padding_fill"_sv); + m_padding_fill = it != options.end() and + (it->value == "yes" or it->value == "true"); + } } } diff --git a/src/ncurses_ui.hh b/src/ncurses_ui.hh index 693e6608..4cc354cd 100644 --- a/src/ncurses_ui.hh +++ b/src/ncurses_ui.hh @@ -169,6 +169,9 @@ private: bool m_set_title = true; + DisplayAtom m_padding_char = DisplayAtom("~"); + bool m_padding_fill = false; + bool m_dirty = false; bool m_resize_pending = false; From a9d33a879696818b556fab00080fcabb8a120db9 Mon Sep 17 00:00:00 2001 From: nojhan Date: Tue, 27 Apr 2021 15:27:57 +0200 Subject: [PATCH 3/3] fix ncurses' padding option - Use less iterations when drawing padding fill with multiple characters. - Use column_length to handle null-width character as no character. --- src/ncurses_ui.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index d2d93b0e..86fcedec 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -477,8 +477,11 @@ void NCursesUI::draw(const DisplayBuffer& display_buffer, if (m_padding_fill) { ColumnCount column_index = 0; - while (column_index++ < dim.column) + while (column_index < dim.column) + { m_window.draw(m_palette, m_padding_char, face); + column_index += m_padding_char.length(); + } } else m_window.draw(m_palette, m_padding_char, face); @@ -1372,8 +1375,10 @@ void NCursesUI::set_ui_options(const Options& options) { auto it = options.find("ncurses_padding_char"_sv); if (it == options.end()) + // Defaults to tilde. m_padding_char = DisplayAtom("~"); - else if (it->value.length() < 1) + else if (it->value.column_length() < 1) + // Do not allow empty string, use space instead. m_padding_char = DisplayAtom(" "); else m_padding_char = DisplayAtom(it->value);