ANSI reset bugfix and addition of missing attribute sequences. Fixes #1031, resolves #1032'

This commit is contained in:
Oliver 2024-10-30 23:29:54 +01:00
parent c5e4fb24af
commit e34b54cd4c
1 changed files with 25 additions and 1 deletions

26
ansi.go
View File

@ -93,7 +93,7 @@ func (a *ansi) Write(text []byte) (int, error) {
var background, foreground string
params := a.csiParameter.String()
fields := strings.Split(params, ";")
if len(params) == 0 || len(fields) == 1 && fields[0] == "0" {
if len(params) == 0 || fields[0] == "" || fields[0] == "0" {
// Reset.
a.attributes = ""
if _, err := a.buffer.WriteString("[-:-:-]"); err != nil {
@ -135,6 +135,10 @@ func (a *ansi) Write(text []byte) (int, error) {
if !strings.ContainsRune(a.attributes, 'd') {
a.attributes += "d"
}
case "3", "03":
if !strings.ContainsRune(a.attributes, 'i') {
a.attributes += "i"
}
case "4", "04":
if !strings.ContainsRune(a.attributes, 'u') {
a.attributes += "u"
@ -143,6 +147,14 @@ func (a *ansi) Write(text []byte) (int, error) {
if !strings.ContainsRune(a.attributes, 'l') {
a.attributes += "l"
}
case "7", "07":
if !strings.ContainsRune(a.attributes, 'r') {
a.attributes += "r"
}
case "9", "09":
if !strings.ContainsRune(a.attributes, 's') {
a.attributes += "s"
}
case "22":
if i := strings.IndexRune(a.attributes, 'b'); i >= 0 {
a.attributes = a.attributes[:i] + a.attributes[i+1:]
@ -150,6 +162,10 @@ func (a *ansi) Write(text []byte) (int, error) {
if i := strings.IndexRune(a.attributes, 'd'); i >= 0 {
a.attributes = a.attributes[:i] + a.attributes[i+1:]
}
case "23":
if i := strings.IndexRune(a.attributes, 'i'); i >= 0 {
a.attributes = a.attributes[:i] + a.attributes[i+1:]
}
case "24":
if i := strings.IndexRune(a.attributes, 'u'); i >= 0 {
a.attributes = a.attributes[:i] + a.attributes[i+1:]
@ -158,6 +174,14 @@ func (a *ansi) Write(text []byte) (int, error) {
if i := strings.IndexRune(a.attributes, 'l'); i >= 0 {
a.attributes = a.attributes[:i] + a.attributes[i+1:]
}
case "27":
if i := strings.IndexRune(a.attributes, 'r'); i >= 0 {
a.attributes = a.attributes[:i] + a.attributes[i+1:]
}
case "29":
if i := strings.IndexRune(a.attributes, 's'); i >= 0 {
a.attributes = a.attributes[:i] + a.attributes[i+1:]
}
case "30", "31", "32", "33", "34", "35", "36", "37":
colorNumber, _ := strconv.Atoi(field)
foreground = lookupColor(colorNumber - 30)