rivo / tview

Terminal UI library with rich, interactive widgets — written in Golang
MIT License
11.13k stars 575 forks source link

Colors don't reset when using Bolt or Italic #1031

Closed sruehl closed 3 weeks ago

sruehl commented 1 month ago

Colors don't reset when using Bolt or Italic from https://github.com/fatih/color for example. Here is a testcase demonstration the current issue:

package tview

import (
    "github.com/fatih/color"
    "testing"
)

func TestTranslateANSIBroken(t *testing.T) {
    info := color.New(color.FgGreen, color.Bold).Sprint
    info2 := color.New(color.FgGreen, color.Italic).Sprint
    color.NoColor = false
    greenText := info("this should be colored green and bolt")
    t.Log(greenText)
    greenText2 := info2("this should be colored green and italic")
    t.Log(greenText2)
    t.Log(TranslateANSI(greenText + " uncolored " + greenText2))
}

image

the offending line is this one if len(params) == 0 || len(fields) == 0 && fields[0] == "0" {

With the above code corrected the output is like that: image

rivo commented 3 weeks ago

Thanks. The latest commit fixes this and some other issues in the ANSI translation code.