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.
This commit is contained in:
nojhan 2021-04-27 15:27:57 +02:00
parent 2d263d3bd7
commit a9d33a8796

View File

@ -477,8 +477,11 @@ void NCursesUI::draw(const DisplayBuffer& display_buffer,
if (m_padding_fill) if (m_padding_fill)
{ {
ColumnCount column_index = 0; ColumnCount column_index = 0;
while (column_index++ < dim.column) while (column_index < dim.column)
{
m_window.draw(m_palette, m_padding_char, face); m_window.draw(m_palette, m_padding_char, face);
column_index += m_padding_char.length();
}
} }
else else
m_window.draw(m_palette, m_padding_char, face); 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); auto it = options.find("ncurses_padding_char"_sv);
if (it == options.end()) if (it == options.end())
// Defaults to tilde.
m_padding_char = DisplayAtom("~"); 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(" "); m_padding_char = DisplayAtom(" ");
else else
m_padding_char = DisplayAtom(it->value); m_padding_char = DisplayAtom(it->value);