diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-09-07 23:29:01 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-09-07 23:29:01 +0100 |
| commit | 29b508a894f565afbfdb4f170fe0bce80525bd58 (patch) | |
| tree | 5bac8f6201fd91a6d0e45de9ece658b9d9b37a19 | |
| parent | 53b65401f8c4f03265b7d97240600b121dcc2aef (diff) | |
Avoid wrapping lines with negative max width
| -rw-r--r-- | src/ncurses_ui.cc | 6 | ||||
| -rw-r--r-- | src/string.cc | 3 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 0a5f807b..5d2001eb 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -779,14 +779,18 @@ String make_info_box(StringView title, StringView message, CharCount max_width, if (not assistant.empty()) assistant_size = { (int)assistant.size(), assistant[0].char_length() }; + String result; + const CharCount max_bubble_width = max_width - assistant_size.column - 6; + if (max_bubble_width < 4) + return result; + Vector<StringView> lines = wrap_lines(message, max_bubble_width); CharCount bubble_width = title.char_length() + 2; for (auto& line : lines) bubble_width = max(bubble_width, line.char_length()); - String result; auto line_count = max(assistant_size.line-1, LineCount{(int)lines.size()} + 2); for (LineCount i = 0; i < line_count; ++i) diff --git a/src/string.cc b/src/string.cc index 682a6947..45264898 100644 --- a/src/string.cc +++ b/src/string.cc @@ -218,6 +218,9 @@ String expand_tabs(StringView line, CharCount tabstop, CharCount col) Vector<StringView> wrap_lines(StringView text, CharCount max_width) { + if (max_width <= 0) + throw runtime_error("Invalid max width"); + using Utf8It = utf8::iterator<const char*>; Utf8It word_begin{text.begin()}; Utf8It word_end{word_begin}; |
