-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexported_functions.go
158 lines (134 loc) · 5.06 KB
/
exported_functions.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Package termtools provides basic functionality to style console output on Linux
//
// v1.0.0
//
// Copyright 2021 Dmitry Fedotov
//
// See package README for usage examples: github.com/dmfed/termtools
//
// General note concerning module usage:
// Whenever color value of type interface{} is required by signature
// of a method or function, either string or int may be supplied.
// Valid color names (to be passed as string) are: "black", "blue", "cyan", "green", "magenta",
// "red", "white", "yellow", "brightblack", "brightblue", "brightcyan",
// "brightgreen", "brightmagenta", "brightred", "brightwhite", "brightyellow".
// Valid color IDs (to be passed as int) are from 0 to 255 inclusive.
//
package termtools
import (
"fmt"
)
// GetColorCode accepts color identifier (string or int) and returns ANSI escape sequence
// for requested color. If color is invalid the function will return
// empty string and an error.
func GetColorCode(color interface{}) (string, error) {
return getColorCode(color)
}
// GetBackgroundCode accepts color identifier (string or int) and returns ANSI escape sequence
// for requested background color. If color is invalid the function will return
// empty string and an error.
func GetBackgroundCode(color interface{}) (string, error) {
return getBackgroundCode(color)
}
// Csprint formats using the default formats for its operands and returns the resulting string.
// It accepts color color identifier (string or int). If color is invalid the function will return
// fmt.Sprint(a).
func Csprint(color interface{}, a ...interface{}) string {
return colorSprint(color, a...)
}
// Csprintf formats according to a format specifier and returns the resulting string.
// It accepts color color identifier (string or int). If color is invalid the function will return
// fmt.Sprintf(format, a).
func Csprintf(color interface{}, format string, a ...interface{}) string {
return colorSprintf(color, format, a...)
}
// ClearScreen clears screen
func ClearScreen() {
fmt.Print(Clear)
}
// ClearScreenUp clears screen from current cursor position up
func ClearScreenUp() {
fmt.Print(ClearUp)
}
// ClearScreenDown clears screen from current cursor position down
func ClearScreenDown() {
fmt.Print(ClearDown)
}
// ClearLine deletes the whole line of text
func ClearLine() {
fmt.Print(ClearL)
}
// ClearLineLeft deletes line left of cursor position
func ClearLineLeft() {
fmt.Print(ClearLLeft)
}
// ClearLineRight deletes line right of cursor position
func ClearLineRight() {
fmt.Print(ClearLRight)
}
// GetTermSize returns current terminal size (number of columns and rows).
// It may fail to get correct values and will return -1, -1 in
// this case. If you're relying on output to precisely position cursor on screen
// always check error.
func GetTermSize() (columns int, rows int, err error) {
return getTermSize()
}
// MoveCursorTo moves cursor to the specified position in terminal. (0, 0) is upper left.
// Will do nothing if x or y are out of bounds or we can not get size of terminal.
func MoveCursorTo(column, row int) {
moveCursorTo(column, row)
}
// MoveCursorHome moves cursor to the upper left corner of the screen.
// Essentially the same as MoveCursorTo(0, 0).
func MoveCursorHome() {
moveCursorHome()
}
// MoveCursorUp moves cursor up specified number of rows
func MoveCursorUp(rows int) {
moveCursorUp(rows)
}
// MoveCursorDown moves cursor down specified number of rows
func MoveCursorDown(rows int) {
moveCursorDown(rows)
}
// MoveCursorLeft moves cursor left specified number of columns
func MoveCursorLeft(columns int) {
moveCursorLeft(columns)
}
// MoveCursorRight moves cursor left specified number of columns
func MoveCursorRight(columns int) {
moveCursorRight(columns)
}
// MoveCursorToNextRow moves cursor to next row
func MoveCursorToNextRow() {
moveCursorToNextRow()
}
// MoveCursorToRow places cursor at the beginning of specified row
func MoveCursorToRow(row int) {
moveCursorToRow(row)
}
// SaveCursorPosition saves current cursor position and attributes.
// Call RestoreCursorPosition() to return
func SaveCursorPosition() {
saveCursorPosition()
}
// RestoreCursorPosition places cursor to original position when
// SaveCursorPosition was called and restores attributes.
func RestoreCursorPosition() {
restoreCursorPosition()
}
// PrintAtPositionAndReturn moves cursor in the current terminal to the specified position, prints, and
// then returns cursor to the inital position.
// Will print at current cursor position if terminal size is unavailable or supplied column and row
// are out of range.
func PrintAtPositionAndReturn(column, row int, a ...interface{}) {
printAtPositionAndReturn(column, row, a...)
}
// PrintAtPosition moves cursor in the current terminal to the specified position and prints.
// It does not return the cursor to the initial position so subsequent call to
// Print/Println etc. will output immediately after the previous output.
// Will print at current cursor position if terminal size is unavailable or supplied column and row
// are out of range.
func PrintAtPosition(column, row int, a ...interface{}) {
printAtPosition(column, row, a...)
}