/
cursor.go
55 lines (44 loc) · 1.16 KB
/
cursor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ansi
import (
"strconv"
)
// HideCursor hides the cursor
func HideCursor() string {
return Esc + "[?25l"
}
// ShowCursor shows the cursor
func ShowCursor() string {
return Esc + "[?25h"
}
// CursorUp moves the cursor up by `n` lines
func CursorUp(n int) string {
return Esc + "[" + strconv.Itoa(n) + "A"
}
// CursorDown moves the cursor down by `n` lines
func CursorDown(n int) string {
return Esc + "[" + strconv.Itoa(n) + "B"
}
// CursorForward moves the cursor forward by `n` columns
func CursorForward(n int) string {
return Esc + "[" + strconv.Itoa(n) + "C"
}
// CursorBackward moves the cursor backwards by `n` columns
func CursorBackward(n int) string {
return Esc + "[" + strconv.Itoa(n) + "D"
}
// CursorStart moves the cursor to column `n`
func CursorStart(n int) string {
return Esc + "[" + strconv.Itoa(n) + "G"
}
// SaveCursorPosition saves the current cursor position
func SaveCursorPosition() string {
return Esc + "[s"
}
// RestoreCursorPosition restores the cursor position
func RestoreCursorPosition() string {
return Esc + "[u"
}
// GetCursorPosition retrieves the cursor position
func GetCursorPosition() string {
return Esc + "[6n"
}