From 7cc68cfbd04dad889e0f70508a1f59f273b56c96 Mon Sep 17 00:00:00 2001 From: Jan Sende <44576417+jansende@users.noreply.github.com> Date: Sat, 20 Aug 2022 02:03:56 +0900 Subject: [PATCH] Fixed dim and bold not mixing well (#460) One single reset code controls both the dim and bold properties. Mixing both led to one of the properties being wrongly reset. Co-authored-by: Arthur Sonzogni --- src/ftxui/screen/screen.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/ftxui/screen/screen.cpp b/src/ftxui/screen/screen.cpp index 130d88f1..61be5979 100644 --- a/src/ftxui/screen/screen.cpp +++ b/src/ftxui/screen/screen.cpp @@ -55,23 +55,25 @@ void UpdatePixelStyle(std::stringstream& ss, if (next == previous) { return; } + + if ((!next.bold && previous.bold) || // + (!next.dim && previous.dim)) { + ss << "\x1B[22m"; // BOLD_RESET and DIM_RESET + // We might have wrongfully reset dim or bold because they share the same + // resetter. Take it into account so that the side effect will cause it to + // be set again below. + previous.bold = false; + previous.dim = false; + } if (next.bold && !previous.bold) { ss << "\x1B[1m"; // BOLD_SET } - if (!next.bold && previous.bold) { - ss << "\x1B[22m"; // BOLD_RESET - } - if (next.dim && !previous.dim) { ss << "\x1B[2m"; // DIM_SET } - if (!next.dim && previous.dim) { - ss << "\x1B[22m"; // DIM_RESET - } - if (next.underlined && !previous.underlined) { ss << "\x1B[4m"; // UNDERLINED_SET }