@@ -13,63 +13,53 @@ type VT100Writer struct {
13
13
// WriteRaw to write raw byte array
14
14
func (w * VT100Writer ) WriteRaw (data []byte ) {
15
15
w .buffer = append (w .buffer , data ... )
16
- return
17
16
}
18
17
19
18
// Write to write safety byte array by removing control sequences.
20
19
func (w * VT100Writer ) Write (data []byte ) {
21
20
w .WriteRaw (bytes .Replace (data , []byte {0x1b }, []byte {'?' }, - 1 ))
22
- return
23
21
}
24
22
25
23
// WriteRawStr to write raw string
26
24
func (w * VT100Writer ) WriteRawStr (data string ) {
27
25
w .WriteRaw ([]byte (data ))
28
- return
29
26
}
30
27
31
28
// WriteStr to write safety string by removing control sequences.
32
29
func (w * VT100Writer ) WriteStr (data string ) {
33
30
w .Write ([]byte (data ))
34
- return
35
31
}
36
32
37
33
/* Erase */
38
34
39
35
// EraseScreen erases the screen with the background colour and moves the cursor to home.
40
36
func (w * VT100Writer ) EraseScreen () {
41
37
w .WriteRaw ([]byte {0x1b , '[' , '2' , 'J' })
42
- return
43
38
}
44
39
45
40
// EraseUp erases the screen from the current line up to the top of the screen.
46
41
func (w * VT100Writer ) EraseUp () {
47
42
w .WriteRaw ([]byte {0x1b , '[' , '1' , 'J' })
48
- return
49
43
}
50
44
51
45
// EraseDown erases the screen from the current line down to the bottom of the screen.
52
46
func (w * VT100Writer ) EraseDown () {
53
47
w .WriteRaw ([]byte {0x1b , '[' , 'J' })
54
- return
55
48
}
56
49
57
50
// EraseStartOfLine erases from the current cursor position to the start of the current line.
58
51
func (w * VT100Writer ) EraseStartOfLine () {
59
52
w .WriteRaw ([]byte {0x1b , '[' , '1' , 'K' })
60
- return
61
53
}
62
54
63
55
// EraseEndOfLine erases from the current cursor position to the end of the current line.
64
56
func (w * VT100Writer ) EraseEndOfLine () {
65
57
w .WriteRaw ([]byte {0x1b , '[' , 'K' })
66
- return
67
58
}
68
59
69
60
// EraseLine erases the entire current line.
70
61
func (w * VT100Writer ) EraseLine () {
71
62
w .WriteRaw ([]byte {0x1b , '[' , '2' , 'K' })
72
- return
73
63
}
74
64
75
65
/* Cursor */
@@ -82,7 +72,6 @@ func (w *VT100Writer) ShowCursor() {
82
72
// HideCursor hides cursor.
83
73
func (w * VT100Writer ) HideCursor () {
84
74
w .WriteRaw ([]byte {0x1b , '[' , '?' , '2' , '5' , 'l' })
85
- return
86
75
}
87
76
88
77
// CursorGoTo sets the cursor position where subsequent text will begin.
@@ -99,7 +88,6 @@ func (w *VT100Writer) CursorGoTo(row, col int) {
99
88
w .WriteRaw ([]byte {';' })
100
89
w .WriteRaw ([]byte (c ))
101
90
w .WriteRaw ([]byte {'H' })
102
- return
103
91
}
104
92
105
93
// CursorUp moves the cursor up by 'n' rows; the default count is 1.
@@ -114,7 +102,6 @@ func (w *VT100Writer) CursorUp(n int) {
114
102
w .WriteRaw ([]byte {0x1b , '[' })
115
103
w .WriteRaw ([]byte (s ))
116
104
w .WriteRaw ([]byte {'A' })
117
- return
118
105
}
119
106
120
107
// CursorDown moves the cursor down by 'n' rows; the default count is 1.
@@ -129,7 +116,6 @@ func (w *VT100Writer) CursorDown(n int) {
129
116
w .WriteRaw ([]byte {0x1b , '[' })
130
117
w .WriteRaw ([]byte (s ))
131
118
w .WriteRaw ([]byte {'B' })
132
- return
133
119
}
134
120
135
121
// CursorForward moves the cursor forward by 'n' columns; the default count is 1.
@@ -144,7 +130,6 @@ func (w *VT100Writer) CursorForward(n int) {
144
130
w .WriteRaw ([]byte {0x1b , '[' })
145
131
w .WriteRaw ([]byte (s ))
146
132
w .WriteRaw ([]byte {'C' })
147
- return
148
133
}
149
134
150
135
// CursorBackward moves the cursor backward by 'n' columns; the default count is 1.
@@ -159,40 +144,34 @@ func (w *VT100Writer) CursorBackward(n int) {
159
144
w .WriteRaw ([]byte {0x1b , '[' })
160
145
w .WriteRaw ([]byte (s ))
161
146
w .WriteRaw ([]byte {'D' })
162
- return
163
147
}
164
148
165
149
// AskForCPR asks for a cursor position report (CPR).
166
150
func (w * VT100Writer ) AskForCPR () {
167
151
// CPR: Cursor Position Request.
168
152
w .WriteRaw ([]byte {0x1b , '[' , '6' , 'n' })
169
- return
170
153
}
171
154
172
155
// SaveCursor saves current cursor position.
173
156
func (w * VT100Writer ) SaveCursor () {
174
157
w .WriteRaw ([]byte {0x1b , '[' , 's' })
175
- return
176
158
}
177
159
178
160
// UnSaveCursor restores cursor position after a Save Cursor.
179
161
func (w * VT100Writer ) UnSaveCursor () {
180
162
w .WriteRaw ([]byte {0x1b , '[' , 'u' })
181
- return
182
163
}
183
164
184
165
/* Scrolling */
185
166
186
167
// ScrollDown scrolls display down one line.
187
168
func (w * VT100Writer ) ScrollDown () {
188
169
w .WriteRaw ([]byte {0x1b , 'D' })
189
- return
190
170
}
191
171
192
172
// ScrollUp scroll display up one line.
193
173
func (w * VT100Writer ) ScrollUp () {
194
174
w .WriteRaw ([]byte {0x1b , 'M' })
195
- return
196
175
}
197
176
198
177
/* Title */
@@ -220,13 +199,11 @@ func (w *VT100Writer) SetTitle(title string) {
220
199
w .WriteRaw ([]byte {0x1b , ']' , '2' , ';' })
221
200
w .WriteRaw (titleBytes )
222
201
w .WriteRaw ([]byte {0x07 })
223
- return
224
202
}
225
203
226
204
// ClearTitle clears a title of terminal window.
227
205
func (w * VT100Writer ) ClearTitle () {
228
206
w .WriteRaw ([]byte {0x1b , ']' , '2' , ';' , 0x07 })
229
- return
230
207
}
231
208
232
209
/* Font */
@@ -240,7 +217,6 @@ func (w *VT100Writer) SetColor(fg, bg Color, bold bool) {
240
217
// Details are https://github.com/c-bata/go-prompt/pull/85
241
218
w .SetDisplayAttributes (fg , bg , DisplayReset )
242
219
}
243
- return
244
220
}
245
221
246
222
// SetDisplayAttributes to set VT100 display attributes.
@@ -269,7 +245,6 @@ func (w *VT100Writer) SetDisplayAttributes(fg, bg Color, attrs ...DisplayAttribu
269
245
b = backgroundANSIColors [DefaultColor ]
270
246
}
271
247
w .WriteRaw (b )
272
- return
273
248
}
274
249
275
250
var displayAttributeParameters = map [DisplayAttribute ][]byte {
0 commit comments