File: terminal.go

package info (click to toggle)
golang-github-liamg-clinch 1.5.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 5,576 kB
  • sloc: makefile: 2
file content (72 lines) | stat: -rw-r--r-- 1,613 bytes parent folder | download
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
package terminal

import (
	"fmt"
)

// Reset terminal to it's initial state, destroying scroll buffer
func Reset() {
	fmt.Println("\x1b[3J")
}

// Clear current terminal screen (keeps scroll buffer intact)
func Clear() {
	fmt.Printf("\x1b[2J")
}

// SetAltBuffer switches to the alternate screen buffer
func SetAltBuffer() {
	fmt.Printf("\x1b[?1049h")
}

// SetMainBuffer switches to the main screen buffer
func SetMainBuffer() {
	fmt.Printf("\x1b[?1049l")
}

// SaveCursor saves the position of the cursor
func SaveCursor() {
	fmt.Printf("\033[s")
}

// RestoreCursor restores the position of the cursor to the last position saved with SaveCursor
func RestoreCursor() {
	fmt.Printf("\033[u")
}

// ShowCursor makes the cursor position highlighted
func ShowCursor() {
	fmt.Printf("\033[?25h")
}

// HideCursor hides the cursor
func HideCursor() {
	fmt.Printf("\033[?25l")
}

// MoveCursorToColumn moves the cursor to the given column (zero indexed)
func MoveCursorToColumn(column int) {
	fmt.Printf("\033[%dG", column+1)
}

// MoveCursorTo moves the cursor to the given position (zero indexed)
func MoveCursorTo(column int, row int) {
	fmt.Printf("\033[%d;%dH", row+1, column+1)
}

// MoveCursorDown moves the cursor down by the given number of rows
func MoveCursorDown(rows int) {
	fmt.Printf("\033[%dB", rows)
}

// MoveCursorUp moves the cursor up by the given number of rows
func MoveCursorUp(rows int) {
	if rows > 0 {
		fmt.Printf("\033[%dA", rows)
	}
}

// ClearLine removes all content from the current line and moves the cursor to the beginning of the line
func ClearLine() {
	fmt.Printf("\033[2K\r")
}