diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 3d7b993..da4f711 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -105,6 +105,7 @@ packages: - Fix climate page not updating properly - 4.1.4 patch: - Supports new `weather.get_forecasts` introduced by Home Assistant 2023.12.0 + - Manual line break on multiline text with `\r`   ## Details of noteworthy changes diff --git a/nspanel_esphome_core.yaml b/nspanel_esphome_core.yaml index 9959780..721af5b 100644 --- a/nspanel_esphome_core.yaml +++ b/nspanel_esphome_core.yaml @@ -7,7 +7,7 @@ substitutions: ##### DON'T CHANGE THIS ##### - version: "4.1.3" + version: "4.1.4" ############################# #external_components: @@ -2094,23 +2094,27 @@ script: int startPos = 0; int endPos = 0; std::string wrappedText = ""; - while (startPos < text_to_display.length()) { - while (text_to_display[startPos] == ' ' and startPos < text_to_display.length()) { startPos++; } - int endPos = startPos + line_length_limit; - if (endPos >= text_to_display.length()) endPos = text_to_display.length(); - else - { - while (endPos > startPos && text_to_display[endPos] != ' ') { endPos--; } - if (endPos == startPos) endPos = startPos + line_length_limit; // Handle case of long word - } - wrappedText += text_to_display.substr(startPos, endPos-startPos); - if (endPos < text_to_display.length()) - { - while (text_to_display[endPos] == ' ') { endPos--; } - if (endPos >= startPos) wrappedText += "\\r"; - } - startPos = endPos + 1; // Skip the space - while (text_to_display[startPos] == ' ' and startPos < text_to_display.length()) { startPos++; } + if (text_to_display.find("\\r") != std::string::npos) { + wrappedText = text_to_display; + } else { + while (startPos < text_to_display.length()) { + while (text_to_display[startPos] == ' ' and startPos < text_to_display.length()) { startPos++; } + int endPos = startPos + line_length_limit; + if (endPos >= text_to_display.length()) endPos = text_to_display.length(); + else + { + while (endPos > startPos && text_to_display[endPos] != ' ') { endPos--; } + if (endPos == startPos) endPos = startPos + line_length_limit; // Handle case of long word + } + wrappedText += text_to_display.substr(startPos, endPos-startPos); + if (endPos < text_to_display.length()) + { + while (text_to_display[endPos] == ' ') { endPos--; } + if (endPos >= startPos) wrappedText += "\\r"; + } + startPos = endPos + 1; // Skip the space + while (text_to_display[startPos] == ' ' and startPos < text_to_display.length()) { startPos++; } + } } disp1->set_component_text_printf(component.c_str(), "%s", wrappedText.c_str());