Skip to content

Commit 8f30282

Browse files
committed
prefer aec library over raw ANSI sequences
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent ac211e6 commit 8f30282

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

cmd/formatter/ansi.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121

2222
"github.com/acarl005/stripansi"
23+
"github.com/morikuni/aec"
2324
)
2425

2526
var disableAnsi bool
@@ -32,59 +33,61 @@ func saveCursor() {
3233
if disableAnsi {
3334
return
3435
}
35-
fmt.Print(ansi("7"))
36+
// see https://github.com/morikuni/aec/pull/5
37+
fmt.Print(ansi("7") + aec.Save.String())
3638
}
3739

3840
func restoreCursor() {
3941
if disableAnsi {
4042
return
4143
}
42-
fmt.Print(ansi("8"))
44+
// see https://github.com/morikuni/aec/pull/5
45+
fmt.Print(ansi("8") + aec.Restore.String())
4346
}
4447

4548
func showCursor() {
4649
if disableAnsi {
4750
return
4851
}
49-
fmt.Print(ansi("[?25h"))
52+
fmt.Print(aec.Show)
5053
}
5154

5255
func moveCursor(y, x int) {
5356
if disableAnsi {
5457
return
5558
}
56-
fmt.Print(ansi(fmt.Sprintf("[%d;%dH", y, x)))
59+
fmt.Print(aec.Position(uint(y), uint(x)))
5760
}
5861

5962
func carriageReturn() {
6063
if disableAnsi {
6164
return
6265
}
63-
fmt.Print(ansi(fmt.Sprintf("[%dG", 0)))
66+
fmt.Print(aec.Column(0))
6467
}
6568

6669
func clearLine() {
6770
if disableAnsi {
6871
return
6972
}
7073
// Does not move cursor from its current position
71-
fmt.Print(ansi("[2K"))
74+
fmt.Print(aec.EraseLine(aec.EraseModes.Tail))
7275
}
7376

7477
func moveCursorUp(lines int) {
7578
if disableAnsi {
7679
return
7780
}
7881
// Does not add new lines
79-
fmt.Print(ansi(fmt.Sprintf("[%dA", lines)))
82+
fmt.Print(aec.Up(uint(lines)))
8083
}
8184

8285
func moveCursorDown(lines int) {
8386
if disableAnsi {
8487
return
8588
}
8689
// Does not add new lines
87-
fmt.Print(ansi(fmt.Sprintf("[%dB", lines)))
90+
fmt.Print(aec.Down(uint(lines)))
8891
}
8992

9093
func newLine() {

0 commit comments

Comments
 (0)