From d71d8bce24def7c8869a72d6f3b7bdff4ea6d786 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Wed, 3 Apr 2024 12:18:30 +0200 Subject: [PATCH] don't use ansi espace sequence when disabled Signed-off-by: Nicolas De Loof --- cmd/formatter/ansi.go | 29 +++++++++++++++++++++++++++++ cmd/formatter/colors.go | 1 + 2 files changed, 30 insertions(+) diff --git a/cmd/formatter/ansi.go b/cmd/formatter/ansi.go index bcb03173cf..c6e4d33a3b 100644 --- a/cmd/formatter/ansi.go +++ b/cmd/formatter/ansi.go @@ -22,36 +22,65 @@ import ( "github.com/acarl005/stripansi" ) +var disableAnsi bool + func ansi(code string) string { return fmt.Sprintf("\033%s", code) } func SaveCursor() { + if disableAnsi { + return + } fmt.Print(ansi("7")) } func RestoreCursor() { + if disableAnsi { + return + } fmt.Print(ansi("8")) } func HideCursor() { + if disableAnsi { + return + } fmt.Print(ansi("[?25l")) } func ShowCursor() { + if disableAnsi { + return + } fmt.Print(ansi("[?25h")) } func MoveCursor(y, x int) { + if disableAnsi { + return + } fmt.Print(ansi(fmt.Sprintf("[%d;%dH", y, x))) } func MoveCursorX(pos int) { + if disableAnsi { + return + } fmt.Print(ansi(fmt.Sprintf("[%dG", pos))) } func ClearLine() { + if disableAnsi { + return + } // Does not move cursor from its current position fmt.Print(ansi("[2K")) } func MoveCursorUp(lines int) { + if disableAnsi { + return + } // Does not add new lines fmt.Print(ansi(fmt.Sprintf("[%dA", lines))) } func MoveCursorDown(lines int) { + if disableAnsi { + return + } // Does not add new lines fmt.Print(ansi(fmt.Sprintf("[%dB", lines))) } diff --git a/cmd/formatter/colors.go b/cmd/formatter/colors.go index cf6a4b56c3..8b2ed5246d 100644 --- a/cmd/formatter/colors.go +++ b/cmd/formatter/colors.go @@ -64,6 +64,7 @@ func SetANSIMode(streams api.Streams, ansi string) { nextColor = func() colorFunc { return monochrome } + disableAnsi = true } }