Merge pull request #110512 from dims/switch-to-released-tag-v1.0.0-for-github.com/daviddengcn/go-colortext

Switch to released tag v1.0.0 for github.com/daviddengcn/go-colortext
This commit is contained in:
Kubernetes Prow Robot
2022-06-10 18:02:18 -07:00
committed by GitHub
7 changed files with 38 additions and 18 deletions

View File

@@ -5,6 +5,11 @@ Under windows platform, the Console API is used. Under other systems, ANSI text
*/
package ct
import (
"io"
"os"
)
// Color is the type of color to be set.
type Color int
@@ -21,6 +26,9 @@ const (
White
)
// Writer is the io.Writer where ANSI escape codes will be written to
var Writer io.Writer = os.Stdout
// ResetColor resets the foreground and background to original colors
func ResetColor() {
resetColor()

View File

@@ -16,7 +16,7 @@ func resetColor() {
if isDumbTerm() {
return
}
fmt.Print("\x1b[0m")
fmt.Fprint(Writer, "\x1b[0m")
}
func ansiText(fg Color, fgBright bool, bg Color, bgBright bool) string {
@@ -32,6 +32,9 @@ func ansiText(fg Color, fgBright bool, bg Color, bgBright bool) string {
}
if bg != None {
s = strconv.AppendUint(append(s, ";"...), 40+(uint64)(bg-Black), 10)
if bgBright {
s = append(s, ";1"...)
}
}
s = append(s, "m"...)
return string(s)
@@ -44,5 +47,5 @@ func changeColor(fg Color, fgBright bool, bg Color, bgBright bool) {
if fg == None && bg == None {
return
}
fmt.Print(ansiText(fg, fgBright, bg, bgBright))
fmt.Fprint(Writer, ansiText(fg, fgBright, bg, bgBright))
}