Skip to content

Commit d71d8bc

Browse files
committed
don't use ansi espace sequence when disabled
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent ff20b64 commit d71d8bc

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

cmd/formatter/ansi.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,65 @@ import (
2222
"github.com/acarl005/stripansi"
2323
)
2424

25+
var disableAnsi bool
26+
2527
func ansi(code string) string {
2628
return fmt.Sprintf("\033%s", code)
2729
}
2830
func SaveCursor() {
31+
if disableAnsi {
32+
return
33+
}
2934
fmt.Print(ansi("7"))
3035
}
3136
func RestoreCursor() {
37+
if disableAnsi {
38+
return
39+
}
3240
fmt.Print(ansi("8"))
3341
}
3442
func HideCursor() {
43+
if disableAnsi {
44+
return
45+
}
3546
fmt.Print(ansi("[?25l"))
3647
}
3748
func ShowCursor() {
49+
if disableAnsi {
50+
return
51+
}
3852
fmt.Print(ansi("[?25h"))
3953
}
4054
func MoveCursor(y, x int) {
55+
if disableAnsi {
56+
return
57+
}
4158
fmt.Print(ansi(fmt.Sprintf("[%d;%dH", y, x)))
4259
}
4360
func MoveCursorX(pos int) {
61+
if disableAnsi {
62+
return
63+
}
4464
fmt.Print(ansi(fmt.Sprintf("[%dG", pos)))
4565
}
4666
func ClearLine() {
67+
if disableAnsi {
68+
return
69+
}
4770
// Does not move cursor from its current position
4871
fmt.Print(ansi("[2K"))
4972
}
5073
func MoveCursorUp(lines int) {
74+
if disableAnsi {
75+
return
76+
}
5177
// Does not add new lines
5278
fmt.Print(ansi(fmt.Sprintf("[%dA", lines)))
5379
}
5480
func MoveCursorDown(lines int) {
81+
if disableAnsi {
82+
return
83+
}
5584
// Does not add new lines
5685
fmt.Print(ansi(fmt.Sprintf("[%dB", lines)))
5786
}

cmd/formatter/colors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func SetANSIMode(streams api.Streams, ansi string) {
6464
nextColor = func() colorFunc {
6565
return monochrome
6666
}
67+
disableAnsi = true
6768
}
6869
}
6970

0 commit comments

Comments
 (0)