From dddaee03611c88c1d2d80ffeab0c4f369638b288 Mon Sep 17 00:00:00 2001 From: nojhan Date: Fri, 20 Jan 2023 10:58:33 +0100 Subject: [PATCH] fix(hfill): handle very narrow terminals --- clutchlog/clutchlog.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/clutchlog/clutchlog.h b/clutchlog/clutchlog.h index 3777faa..0096329 100644 --- a/clutchlog/clutchlog.h +++ b/clutchlog/clutchlog.h @@ -854,9 +854,17 @@ class clutchlog const size_t right_len = raw_row.size() - raw_hfill_pos - hfill_tag.size(); if(right_len+left_len > nb_columns) { // The right part would go over the terminal width: add a new row. - const std::string hfill(std::max((size_t)0, nb_columns-right_len), _hfill_char); - const std::string hfill_styled = _hfill_fmt(hfill); - row = replace(row, "\\{hfill\\}", "\n"+hfill_styled); + if(right_len < nb_columns) { + // There is room for the right part on a new line. + const std::string hfill(std::max((size_t)0, nb_columns-right_len), _hfill_char); + const std::string hfill_styled = _hfill_fmt(hfill); + row = replace(row, "\\{hfill\\}", "\n"+hfill_styled); + } else { + // Right part still goes over columns: let it go. + const std::string hfill(1, _hfill_char); + const std::string hfill_styled = _hfill_fmt(hfill); + row = replace(row, "\\{hfill\\}", "\n"+hfill_styled); + } } else { // There is some space in between left and right parts. const std::string hfill(std::max((size_t)0, nb_columns - (right_len+left_len)), _hfill_char);