-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcursor.go
110 lines (90 loc) · 2.59 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Package cursor provides ANSI Escape sequences
// introduced in VT-100 terminals for cursor and screen
// manipulation operations.
package cursor
import "fmt"
var Esc = "\x1b"
func escape(format string, args ...interface{}) string {
return fmt.Sprintf("%s%s", Esc, fmt.Sprintf(format, args...))
}
// Show returns ANSI escape sequence to show the cursor
func Show() string {
return escape("[?25h")
}
// Hide returns ANSI escape sequence to hide the cursor
func Hide() string {
return escape("[?25l")
}
// MoveTo returns ANSI escape sequence to move cursor
// to specified position on screen.
func MoveTo(line, col int) string {
return escape("[%d;%dH", line, col)
}
// MoveUp returns ANSI escape sequence to move cursor
// up n lines.
func MoveUp(n int) string {
return escape("[%dA", n)
}
// MoveDown returns ANSI escape sequence to move cursor
// down n lines.
func MoveDown(n int) string {
return escape("[%dB", n)
}
// MoveRight returns ANSI escape sequence to move cursor
// right n columns.
func MoveRight(n int) string {
return escape("[%dC", n)
}
// MoveLeft returns ANSI escape sequence to move cursor
// left n columns.
func MoveLeft(n int) string {
return escape("[%dD", n)
}
// MoveUpperLeft returns ANSI escape sequence to move cursor
// to upper left corner of screen.
func MoveUpperLeft(n int) string {
return escape("[%dH", n)
}
// MoveNextLine returns ANSI escape sequence to move cursor
// to next line.
func MoveNextLine() string {
return escape("E")
}
// ClearLineRight returns ANSI escape sequence to clear line
// from right of the cursor.
func ClearLineRight() string {
return escape("[0K")
}
// ClearLineLeft returns ANSI escape sequence to clear line
// from left of the cursor.
func ClearLineLeft() string {
return escape("[1K")
}
// ClearEntireLine returns ANSI escape sequence to clear current line.
func ClearEntireLine() string {
return escape("[2K")
}
// ClearScreenDown returns ANSI escape sequence to clear screen below.
// the cursor.
func ClearScreenDown() string {
return escape("[0J")
}
// ClearScreenUp returns ANSI escape sequence to clear screen above.
// the cursor.
func ClearScreenUp() string {
return escape("[1J")
}
// ClearEntireScreen returns ANSI escape sequence to clear the screen.
func ClearEntireScreen() string {
return escape("[2J")
}
// SaveAttributes returns ANSI escape sequence to save current position
// and attributes of the cursor.
func SaveAttributes() string {
return escape("7")
}
// RestoreAttributes returns ANSI escape sequence to restore saved position
// and attributes of the cursor.
func RestoreAttributes() string {
return escape("8")
}