Skip to content

Commit

Permalink
don't use ansi espace sequence when disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Apr 3, 2024
1 parent ff20b64 commit d71d8bc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cmd/formatter/ansi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down
1 change: 1 addition & 0 deletions cmd/formatter/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func SetANSIMode(streams api.Streams, ansi string) {
nextColor = func() colorFunc {
return monochrome
}
disableAnsi = true
}
}

Expand Down

0 comments on commit d71d8bc

Please sign in to comment.