From 5d2739eee0a770b9da6723325011e5ab7bafcf78 Mon Sep 17 00:00:00 2001 From: Tim Siegel Date: Thu, 5 May 2022 14:52:33 -0400 Subject: [PATCH] [command-prompt] word-wrap response text Fixes #2079 --- plugins/command-prompt.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/plugins/command-prompt.cpp b/plugins/command-prompt.cpp index 0bfe31dc9..ba2fe0e87 100644 --- a/plugins/command-prompt.cpp +++ b/plugins/command-prompt.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -11,6 +12,7 @@ #include #include +#include #include #include @@ -159,13 +161,18 @@ void viewscreen_commandpromptst::render() parent->render(); if (is_response) { - auto it = responses.begin(); - for (int i = 0; i < dim.y && it != responses.end(); i++, it++) + int y = 0; + for (auto &response : responses) { - Screen::fillRect(Screen::Pen(' ', 7, 0), 0, i, dim.x, i); - std::string cur_line = it->second; - Screen::paintString(Screen::Pen(' ', it->first, 0), 0, i, - cur_line.substr(0, cur_line.size() - 1)); + std::vector lines; + word_wrap(&lines, response.second, dim.x); + for (auto &line : lines) + { + Screen::fillRect(Screen::Pen(' ', 7, 0), 0, y, dim.x, y); + Screen::paintString(Screen::Pen(' ', response.first, 0), 0, y, line); + if (++y >= dim.y) + return; + } } } else