I am using a Text Template and LVGL to be able to enter a text string on the ESPHome webpage (or to set it with Home Assistant) and, when the string value is changed, it is then used to set a new value for an LVGL Label widget.
Along the way, I need to be able to handle escaped characters. For instance, if I change the text in the Text Template to
Warning: Laser in use
it’ll display fine on the LCD, but if I want to make a 2 line label, like:
Warning: Laser in use
Put on safety goggles
before entering
I can’t split it into different lines. If, in the YAML file, I use double quotes and use escaped characters like “\n”, they will be handled during compile time. But if I want to change the value of the text in the Label widget later, I don’t see a way to automatically do that when setting the value of the Label.
How can I take the state, or text string, from a Text Template, change occurrences of escaped characters like “\n” and change them to a newline character? I know, in C++, there’s a function replace(), so I could use std::replace, but that only replaces one character with one other.
But I haven’t used C++ in 15-20 years and I’m not sure if the files I need to do this are included during compiling or how to do this in a lambda when I get the text string value from the Text Component.
Is this possible to do? If so, how would I do it?