-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathstd.go
60 lines (49 loc) · 1.29 KB
/
std.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
56
57
58
59
60
package term
import "fmt"
// Direction constants are to be used with CursorMove.
type Direction string
const (
// Up moves the cursor up.
Up Direction = "A"
// Down moves the cursor down.
Down Direction = "B"
// Forward moves the cursor forward.
Forward Direction = "C"
// Backward moves the cursor backward.
Backward Direction = "D"
// NextLine cursor to beginning of the line next line.
NextLine Direction = "E"
// PreviousLine cursor to beginning of the line previous line.
PreviousLine Direction = "F"
// HorizontalAbsolute the cursor to the specified column.
HorizontalAbsolute Direction = "G"
)
const csi = "\033["
// HideCursor hides cursor.
func HideCursor() {
print(csi + "?25l")
}
// ShowCursor shows cursor.
func ShowCursor() {
print(csi + "?25h")
}
// Clear clears the screen.
func Clear() {
print(csi + "H\033[2J")
}
// CursorPosition moves cursor to row, col.
func CursorPosition(row, col int) {
fmt.Printf("%s%d;%dH", csi, row, col)
}
// CursorMove moves the cursor n times in the direction d.
func CursorMove(d Direction, n int) {
fmt.Printf("%s%d%s", csi, n, d)
}
// CursorSavePosition saves the cursor position/state.
func CursorSavePosition() {
print(csi + "s")
}
// CursorRestorePosition restores the cursor position/state.
func CursorRestorePosition() {
print(csi + "u")
}