|
@@ -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)))
|
|
|
}
|