From 1705b669479721be75e47aa7a883122de67470d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kotowski?= Date: Sun, 15 Dec 2024 21:26:04 +0100 Subject: [PATCH] fix(compat): more accurate behavior of SGR 21 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ECMA-48 and most common terminal emulators implement SGR 21 as double underline, which predates SGR 4 underline style extension. This behavior is much more common than "no bold" one. Signed-off-by: MichaƂ Kotowski --- ansi/sgr.go | 2 +- ansi/style.go | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ansi/sgr.go b/ansi/sgr.go index 1a18c98e..683a9a1b 100644 --- a/ansi/sgr.go +++ b/ansi/sgr.go @@ -46,7 +46,7 @@ var attrStrings = map[int]string{ ReverseAttr: "7", ConcealAttr: "8", StrikethroughAttr: "9", - NoBoldAttr: "21", + DoubleUnderlineAttr: "21", NormalIntensityAttr: "22", NoItalicAttr: "23", NoUnderlineAttr: "24", diff --git a/ansi/style.go b/ansi/style.go index 7f391156..39bff95a 100644 --- a/ansi/style.go +++ b/ansi/style.go @@ -127,9 +127,12 @@ func (s Style) Strikethrough() Style { return append(s, strikethroughAttr) } -// NoBold appends the no bold style attribute to the style. -func (s Style) NoBold() Style { - return append(s, noBoldAttr) +// EcmaDoubleUnderline appends the double underline style attribute to the style. +// Differs from UnderlineStyle(DoubleUnderlineStyle) by using ECMA-compliant +// SGR 21 instead of SGR 4 subparameter extension. +// Some terminals may interpret this as "no bold" attribute. +func (s Style) EcmaDoubleUnderline() Style { + return append(s, doubleUnderlineAttr) } // NormalIntensity appends the normal intensity style attribute to the style. @@ -236,7 +239,7 @@ const ( ReverseAttr Attr = 7 ConcealAttr Attr = 8 StrikethroughAttr Attr = 9 - NoBoldAttr Attr = 21 // Some terminals treat this as double underline. + DoubleUnderlineAttr Attr = 21 // Some terminals treat this as no bold. NormalIntensityAttr Attr = 22 NoItalicAttr Attr = 23 NoUnderlineAttr Attr = 24 @@ -298,7 +301,7 @@ const ( reverseAttr = "7" concealAttr = "8" strikethroughAttr = "9" - noBoldAttr = "21" + doubleUnderlineAttr = "21" normalIntensityAttr = "22" noItalicAttr = "23" noUnderlineAttr = "24"