New SGR codes to turn off bold/dim independently

Allows for robust patching of formatting into already formatted
text. Without this it is not possible to turn off bold without
affecting existing dim and vice versa.
This commit is contained in:
Kovid Goyal
2023-03-22 13:41:54 +05:30
parent e46a7c39c3
commit 88bd3ee9ca
5 changed files with 123 additions and 80 deletions

View File

@@ -311,8 +311,8 @@ func (self url_code) is_empty() bool {
func (self *sgr_code) update() {
p := make([]string, 0, 1)
s := make([]string, 0, 1)
p, s = self.bold.as_sgr("1", "22", p, s)
p, s = self.dim.as_sgr("2", "22", p, s)
p, s = self.bold.as_sgr("1", "221", p, s)
p, s = self.dim.as_sgr("2", "222", p, s)
p, s = self.italic.as_sgr("3", "23", p, s)
p, s = self.reverse.as_sgr("7", "27", p, s)
p, s = self.strikethrough.as_sgr("9", "29", p, s)

View File

@@ -33,8 +33,8 @@ func TestANSIStyleSprint(t *testing.T) {
}
test("", "", "")
test("bold", "\x1b[1m", "\x1b[22m")
test("bold fg=red u=curly", "\x1b[1;4:3;31m", "\x1b[22;4:0;39m")
test("bold", "\x1b[1m", "\x1b[221m")
test("bold fg=red u=curly", "\x1b[1;4:3;31m", "\x1b[221;4:0;39m")
test("fg=123", "\x1b[38:5:123m", "\x1b[39m")
test("fg=15", "\x1b[97m", "\x1b[39m")
test("bg=15", "\x1b[107m", "\x1b[49m")