forked from c-bata/go-prompt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.go
162 lines (139 loc) · 4.28 KB
/
output.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
159
160
161
162
package prompt
import "sync"
var (
consoleWriterMu sync.Mutex
consoleWriter ConsoleWriter
)
func registerConsoleWriter(f ConsoleWriter) {
consoleWriterMu.Lock()
defer consoleWriterMu.Unlock()
consoleWriter = f
}
// DisplayAttribute represents display attributes like Blinking, Bold, Italic and so on.
type DisplayAttribute int
const (
// DisplayReset reset all display attributes.
DisplayReset DisplayAttribute = iota
// DisplayBold set bold or increases intensity.
DisplayBold
// DisplayLowIntensity decreases intensity. Not widely supported.
DisplayLowIntensity
// DisplayItalic set italic. Not widely supported.
DisplayItalic
// DisplayUnderline set underline.
DisplayUnderline
// DisplayBlink set blink (less than 150 per minute).
DisplayBlink
// DisplayRapidBlink set blink (more than 150 per minute). Not widely supported.
DisplayRapidBlink
// DisplayReverse swap foreground and background colors.
DisplayReverse
// DisplayInvisible set invisible. Not widely supported.
DisplayInvisible
// DisplayCrossedOut set characters legible, but marked for deletion. Not widely supported.
DisplayCrossedOut
// DisplayDefaultFont set primary(default) font.
DisplayDefaultFont
)
// Color represents color on terminal.
type Color int
const (
// DefaultColor represents a default color.
DefaultColor Color = iota
// Low intensity.
// Black represents a black.
Black
// DarkRed represents a dark red.
DarkRed
// DarkGreen represents a dark green.
DarkGreen
// Brown represents a brown.
Brown
// DarkBlue represents a dark blue.
DarkBlue
// Purple represents a purple.
Purple
// Cyan represents a cyan.
Cyan
// LightGray represents a light gray.
LightGray
// High intensity.
// DarkGray represents a dark gray.
DarkGray
// Red represents a red.
Red
// Green represents a green.
Green
// Yellow represents a yellow.
Yellow
// Blue represents a blue.
Blue
// Fuchsia represents a fuchsia.
Fuchsia
// Turquoise represents a turquoise.
Turquoise
// White represents a white.
White
)
// ConsoleWriter is an interface to abstract output layer.
type ConsoleWriter interface {
/* Write */
// WriteRaw to write raw byte array.
WriteRaw(data []byte)
// Write to write safety byte array by removing control sequences.
Write(data []byte)
// WriteStr to write raw string.
WriteRawStr(data string)
// WriteStr to write safety string by removing control sequences.
WriteStr(data string)
// Flush to flush buffer.
Flush() error
/* Erasing */
// EraseScreen erases the screen with the background colour and moves the cursor to home.
EraseScreen()
// EraseUp erases the screen from the current line up to the top of the screen.
EraseUp()
// EraseDown erases the screen from the current line down to the bottom of the screen.
EraseDown()
// EraseStartOfLine erases from the current cursor position to the start of the current line.
EraseStartOfLine()
// EraseEndOfLine erases from the current cursor position to the end of the current line.
EraseEndOfLine()
// EraseLine erases the entire current line.
EraseLine()
/* Cursor */
// ShowCursor stops blinking cursor and show.
ShowCursor()
// HideCursor hides cursor.
HideCursor()
// CursorGoTo sets the cursor position where subsequent text will begin.
CursorGoTo(row, col int)
// CursorUp moves the cursor up by 'n' rows; the default count is 1.
CursorUp(n int)
// CursorDown moves the cursor down by 'n' rows; the default count is 1.
CursorDown(n int)
// CursorForward moves the cursor forward by 'n' columns; the default count is 1.
CursorForward(n int)
// CursorBackward moves the cursor backward by 'n' columns; the default count is 1.
CursorBackward(n int)
// AskForCPR asks for a cursor position report (CPR).
AskForCPR()
// SaveCursor saves current cursor position.
SaveCursor()
// UnSaveCursor restores cursor position after a Save Cursor.
UnSaveCursor()
/* Scrolling */
// ScrollDown scrolls display down one line.
ScrollDown()
// ScrollUp scroll display up one line.
ScrollUp()
/* Title */
// SetTitle sets a title of terminal window.
SetTitle(title string)
// ClearTitle clears a title of terminal window.
ClearTitle()
/* Font */
// SetColor sets text and background colors. and specify whether text is bold.
SetColor(fg, bg Color, bold bool)
SetDisplayAttributes(fg, bg Color, attrs ...DisplayAttribute)
}