diff --git a/src/ftxui/screen/screen.cpp b/src/ftxui/screen/screen.cpp index e2b83ad1..f98cc506 100644 --- a/src/ftxui/screen/screen.cpp +++ b/src/ftxui/screen/screen.cpp @@ -164,8 +164,15 @@ std::string Screen::ToString() { auto& pixel = pixels_[y][x]; wchar_t c = pixel.character; UpdatePixelStyle(ss, previous_pixel, pixel); + + auto width = wchar_width(c); + if (width <= 0) { + // Avoid an infinite loop for non-printable characters + c = L' '; + width = 1; + } ss << c; - x += wchar_width(c); + x += width; } }