generated from atomicgo/template
-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
cursor_other.go
67 lines (56 loc) · 1.8 KB
/
cursor_other.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
//go:build !windows
// +build !windows
package cursor
import (
"fmt"
)
// Up moves the cursor n lines up relative to the current position.
func (c *Cursor) Up(n int) {
if n > 0 {
fmt.Fprintf(c.writer, "\x1b[%dA", n)
}
}
// Down moves the cursor n lines down relative to the current position.
func (c *Cursor) Down(n int) {
if n > 0 {
fmt.Fprintf(c.writer, "\x1b[%dB", n)
}
}
// Right moves the cursor n characters to the right relative to the current position.
func (c *Cursor) Right(n int) {
if n > 0 {
fmt.Fprintf(c.writer, "\x1b[%dC", n)
}
}
// Left moves the cursor n characters to the left relative to the current position.
func (c *Cursor) Left(n int) {
if n > 0 {
fmt.Fprintf(c.writer, "\x1b[%dD", n)
}
}
// HorizontalAbsolute moves the cursor to n horizontally.
// The position n is absolute to the start of the line.
func (c *Cursor) HorizontalAbsolute(n int) {
n++ // Moves the line to the character after n
fmt.Fprintf(c.writer, "\x1b[%dG", n)
}
// Show the cursor if it was hidden previously.
// Don't forget to show the cursor at least at the end of your application.
// Otherwise the user might have a terminal with a permanently hidden cursor, until they reopen the terminal.
func (c *Cursor) Show() {
fmt.Fprint(c.writer, "\x1b[?25h")
}
// Hide the cursor.
// Don't forget to show the cursor at least at the end of your application with Show.
// Otherwise the user might have a terminal with a permanently hidden cursor, until they reopen the terminal.
func (c *Cursor) Hide() {
fmt.Fprintf(c.writer, "\x1b[?25l")
}
// ClearLine clears the current line and moves the cursor to it's start position.
func (c *Cursor) ClearLine() {
fmt.Fprintf(c.writer, "\x1b[2K")
}
// Clear clears the current position and moves the cursor to the left.
func (c *Cursor) Clear() {
fmt.Fprintf(c.writer, "\x1b[K")
}