From a0a9e48f85f84f80d850da6f349cc754739e62d6 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 13 Aug 2025 15:19:31 -0400 Subject: StdIo: Fix Terminal abstraction to avoid unnecessary VT100 escape sequences Fix commit 329d755dbd (StdIo: Add a Terminal abstraction to print color text, 2025-05-06, v4.1.0-rc1~151^2~3) to avoid printing a VT100 escape sequence for normal text if we did not print any sequence initially. We already use this approach for Windows Console text attributes. Issue: #26924 --- Source/cmStdIoTerminal.cxx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/cmStdIoTerminal.cxx b/Source/cmStdIoTerminal.cxx index 5baff5e..428f7c7 100644 --- a/Source/cmStdIoTerminal.cxx +++ b/Source/cmStdIoTerminal.cxx @@ -141,9 +141,13 @@ void Print(OStream& os, TermAttrSet const& attrs, f(os.IOS()); break; case TermKind::VT100: - SetVT100Attrs(os.IOS(), attrs); - f(os.IOS()); - SetVT100Attrs(os.IOS(), TermAttr::Normal); + if (!attrs.empty()) { + SetVT100Attrs(os.IOS(), attrs); + f(os.IOS()); + SetVT100Attrs(os.IOS(), TermAttr::Normal); + } else { + f(os.IOS()); + } break; #ifdef _WIN32 case TermKind::Console: { -- cgit v0.12 From 914803bf3123770cc36c51950c725dadf4608b14 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 13 Aug 2025 15:24:50 -0400 Subject: Makefile: Fix regression that prints unnecessary VT100 escape sequences Since commit 509c424472 (StdIo: Replace uses of KWSys Terminal with StdIo::Print, 2025-05-08, v4.1.0-rc1~151^2~2) we print unnecessary VT100 escape sequences to establish normal text even when not intending to print color. In combination with `CLICOLOR_FORCE=1`, this breaks detection of implicit link information from compiler driver output. Fixes: #27137 --- Source/cmcmd.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 69f64af..66efbd3 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1874,7 +1874,7 @@ int cmcmd::ExecuteEchoColor(std::vector const& args) bool enabled = true; static cm::StdIo::TermAttrSet const noAttrs; - cm::StdIo::TermAttrSet attrs = cm::StdIo::TermAttr::Normal; + cm::StdIo::TermAttrSet attrs; bool newline = true; std::string progressDir; for (auto const& arg : cmMakeRange(args).advance(2)) { @@ -1910,6 +1910,9 @@ int cmcmd::ExecuteEchoColor(std::vector const& args) } else if (arg == "--white") { attrs = cm::StdIo::TermAttr::ForegroundWhite; } else if (arg == "--bold") { + if (attrs.empty()) { + attrs = cm::StdIo::TermAttr::Normal; + } attrs |= cm::StdIo::TermAttr::ForegroundBold; } else if (arg == "--no-newline") { newline = false; -- cgit v0.12