~poldi1405/go-ansi

ref: 76d320c6afe7577b81dc9a9196484bbcad5057a9 go-ansi/cursor.go -rw-r--r-- 1.6 KiB
76d320c6 — Moritz Poldrack added function to remove all ANSI-Codes from a string 1 year, 5 months ago
                                                                                
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
package ansi

import "fmt"

// MoveCursor moves the cursor to position (x;y)
func MoveCursor(x, y int) string {
	return escape + fmt.Sprintf(position, x, y)
}

// Up moves the cursor up one row
func Up() string {
	return UpX(1)
}

// UpX moves the cursor up x rows
func UpX(x int) string {
	return escape + fmt.Sprintf(up, x)
}

// Down moves the cursor down one row
func Down() string {
	return DownX(1)
}

// DownX moves the cursor down x rows
func DownX(x int) string {
	return escape + fmt.Sprintf(down, x)
}

// Right moves the cursor right one row. As far as I am aware the correct term
// is "forward". Please be wary of potential implications in RTL context.
func Right() string {
	return RightX(1)
}

// RightX moves the cursor right x rows. As far as I am aware the correct term
// is "forward". Please be wary of potential implications in RTL context.
func RightX(x int) string {
	return escape + fmt.Sprintf(forward, x)
}

// Left moves the cursor Left one row. As far as I am aware the correct term
// is "backward". Please be wary of potential implications in RTL context.
func Left() string {
	return LeftX(1)
}

// LeftX moves the cursor Left x rows. As far as I am aware the correct term
// is "backward". Please be wary of potential implications in RTL context.
func LeftX(x int) string {
	return escape + fmt.Sprintf(backward, x)
}

// SavePos stores the current cursor position god knows where to allow
// restoring it.
func SavePos() string {
	return escape + save
}

// RestorePos restores the cursor position from the void. (see SavePos for
// more)
func RestorePos() string {
	return escape + restore
}