1 package termenv
2
3 import (
4 "fmt"
5 "strings"
6 )
7
8
9 const (
10
11 CursorUpSeq = "%dA"
12 CursorDownSeq = "%dB"
13 CursorForwardSeq = "%dC"
14 CursorBackSeq = "%dD"
15 CursorNextLineSeq = "%dE"
16 CursorPreviousLineSeq = "%dF"
17 CursorHorizontalSeq = "%dG"
18 CursorPositionSeq = "%d;%dH"
19 EraseDisplaySeq = "%dJ"
20 EraseLineSeq = "%dK"
21 ScrollUpSeq = "%dS"
22 ScrollDownSeq = "%dT"
23 SaveCursorPositionSeq = "s"
24 RestoreCursorPositionSeq = "u"
25 ChangeScrollingRegionSeq = "%d;%dr"
26 InsertLineSeq = "%dL"
27 DeleteLineSeq = "%dM"
28
29
30 EraseLineRightSeq = "0K"
31 EraseLineLeftSeq = "1K"
32 EraseEntireLineSeq = "2K"
33
34
35 EnableMousePressSeq = "?9h"
36 DisableMousePressSeq = "?9l"
37 EnableMouseSeq = "?1000h"
38 DisableMouseSeq = "?1000l"
39 EnableMouseHiliteSeq = "?1001h"
40 DisableMouseHiliteSeq = "?1001l"
41 EnableMouseCellMotionSeq = "?1002h"
42 DisableMouseCellMotionSeq = "?1002l"
43 EnableMouseAllMotionSeq = "?1003h"
44 DisableMouseAllMotionSeq = "?1003l"
45 EnableMouseExtendedModeSeq = "?1006h"
46 DisableMouseExtendedModeSeq = "?1006l"
47 EnableMousePixelsModeSeq = "?1016h"
48 DisableMousePixelsModeSeq = "?1016l"
49
50
51 RestoreScreenSeq = "?47l"
52 SaveScreenSeq = "?47h"
53 AltScreenSeq = "?1049h"
54 ExitAltScreenSeq = "?1049l"
55
56
57
58 EnableBracketedPasteSeq = "?2004h"
59 DisableBracketedPasteSeq = "?2004l"
60 StartBracketedPasteSeq = "200~"
61 EndBracketedPasteSeq = "201~"
62
63
64 SetWindowTitleSeq = "2;%s" + string(BEL)
65 SetForegroundColorSeq = "10;%s" + string(BEL)
66 SetBackgroundColorSeq = "11;%s" + string(BEL)
67 SetCursorColorSeq = "12;%s" + string(BEL)
68 ShowCursorSeq = "?25h"
69 HideCursorSeq = "?25l"
70 )
71
72
73 func (o Output) Reset() {
74 fmt.Fprint(o.tty, CSI+ResetSeq+"m")
75 }
76
77
78 func (o Output) SetForegroundColor(color Color) {
79 fmt.Fprintf(o.tty, OSC+SetForegroundColorSeq, color)
80 }
81
82
83 func (o Output) SetBackgroundColor(color Color) {
84 fmt.Fprintf(o.tty, OSC+SetBackgroundColorSeq, color)
85 }
86
87
88 func (o Output) SetCursorColor(color Color) {
89 fmt.Fprintf(o.tty, OSC+SetCursorColorSeq, color)
90 }
91
92
93 func (o Output) RestoreScreen() {
94 fmt.Fprint(o.tty, CSI+RestoreScreenSeq)
95 }
96
97
98 func (o Output) SaveScreen() {
99 fmt.Fprint(o.tty, CSI+SaveScreenSeq)
100 }
101
102
103
104 func (o Output) AltScreen() {
105 fmt.Fprint(o.tty, CSI+AltScreenSeq)
106 }
107
108
109
110 func (o Output) ExitAltScreen() {
111 fmt.Fprint(o.tty, CSI+ExitAltScreenSeq)
112 }
113
114
115 func (o Output) ClearScreen() {
116 fmt.Fprintf(o.tty, CSI+EraseDisplaySeq, 2)
117 o.MoveCursor(1, 1)
118 }
119
120
121 func (o Output) MoveCursor(row int, column int) {
122 fmt.Fprintf(o.tty, CSI+CursorPositionSeq, row, column)
123 }
124
125
126 func (o Output) HideCursor() {
127 fmt.Fprint(o.tty, CSI+HideCursorSeq)
128 }
129
130
131 func (o Output) ShowCursor() {
132 fmt.Fprint(o.tty, CSI+ShowCursorSeq)
133 }
134
135
136 func (o Output) SaveCursorPosition() {
137 fmt.Fprint(o.tty, CSI+SaveCursorPositionSeq)
138 }
139
140
141 func (o Output) RestoreCursorPosition() {
142 fmt.Fprint(o.tty, CSI+RestoreCursorPositionSeq)
143 }
144
145
146 func (o Output) CursorUp(n int) {
147 fmt.Fprintf(o.tty, CSI+CursorUpSeq, n)
148 }
149
150
151 func (o Output) CursorDown(n int) {
152 fmt.Fprintf(o.tty, CSI+CursorDownSeq, n)
153 }
154
155
156 func (o Output) CursorForward(n int) {
157 fmt.Fprintf(o.tty, CSI+CursorForwardSeq, n)
158 }
159
160
161 func (o Output) CursorBack(n int) {
162 fmt.Fprintf(o.tty, CSI+CursorBackSeq, n)
163 }
164
165
166
167 func (o Output) CursorNextLine(n int) {
168 fmt.Fprintf(o.tty, CSI+CursorNextLineSeq, n)
169 }
170
171
172
173 func (o Output) CursorPrevLine(n int) {
174 fmt.Fprintf(o.tty, CSI+CursorPreviousLineSeq, n)
175 }
176
177
178 func (o Output) ClearLine() {
179 fmt.Fprint(o.tty, CSI+EraseEntireLineSeq)
180 }
181
182
183 func (o Output) ClearLineLeft() {
184 fmt.Fprint(o.tty, CSI+EraseLineLeftSeq)
185 }
186
187
188 func (o Output) ClearLineRight() {
189 fmt.Fprint(o.tty, CSI+EraseLineRightSeq)
190 }
191
192
193 func (o Output) ClearLines(n int) {
194 clearLine := fmt.Sprintf(CSI+EraseLineSeq, 2)
195 cursorUp := fmt.Sprintf(CSI+CursorUpSeq, 1)
196 fmt.Fprint(o.tty, clearLine+strings.Repeat(cursorUp+clearLine, n))
197 }
198
199
200 func (o Output) ChangeScrollingRegion(top, bottom int) {
201 fmt.Fprintf(o.tty, CSI+ChangeScrollingRegionSeq, top, bottom)
202 }
203
204
205
206 func (o Output) InsertLines(n int) {
207 fmt.Fprintf(o.tty, CSI+InsertLineSeq, n)
208 }
209
210
211
212 func (o Output) DeleteLines(n int) {
213 fmt.Fprintf(o.tty, CSI+DeleteLineSeq, n)
214 }
215
216
217 func (o Output) EnableMousePress() {
218 fmt.Fprint(o.tty, CSI+EnableMousePressSeq)
219 }
220
221
222 func (o Output) DisableMousePress() {
223 fmt.Fprint(o.tty, CSI+DisableMousePressSeq)
224 }
225
226
227 func (o Output) EnableMouse() {
228 fmt.Fprint(o.tty, CSI+EnableMouseSeq)
229 }
230
231
232 func (o Output) DisableMouse() {
233 fmt.Fprint(o.tty, CSI+DisableMouseSeq)
234 }
235
236
237 func (o Output) EnableMouseHilite() {
238 fmt.Fprint(o.tty, CSI+EnableMouseHiliteSeq)
239 }
240
241
242 func (o Output) DisableMouseHilite() {
243 fmt.Fprint(o.tty, CSI+DisableMouseHiliteSeq)
244 }
245
246
247 func (o Output) EnableMouseCellMotion() {
248 fmt.Fprint(o.tty, CSI+EnableMouseCellMotionSeq)
249 }
250
251
252 func (o Output) DisableMouseCellMotion() {
253 fmt.Fprint(o.tty, CSI+DisableMouseCellMotionSeq)
254 }
255
256
257 func (o Output) EnableMouseAllMotion() {
258 fmt.Fprint(o.tty, CSI+EnableMouseAllMotionSeq)
259 }
260
261
262 func (o Output) DisableMouseAllMotion() {
263 fmt.Fprint(o.tty, CSI+DisableMouseAllMotionSeq)
264 }
265
266
267
268 func (o Output) EnableMouseExtendedMode() {
269 fmt.Fprint(o.tty, CSI+EnableMouseExtendedModeSeq)
270 }
271
272
273 func (o Output) DisableMouseExtendedMode() {
274 fmt.Fprint(o.tty, CSI+DisableMouseExtendedModeSeq)
275 }
276
277
278
279
280 func (o Output) EnableMousePixelsMode() {
281 fmt.Fprint(o.tty, CSI+EnableMousePixelsModeSeq)
282 }
283
284
285 func (o Output) DisableMousePixelsMode() {
286 fmt.Fprint(o.tty, CSI+DisableMousePixelsModeSeq)
287 }
288
289
290 func (o Output) SetWindowTitle(title string) {
291 fmt.Fprintf(o.tty, OSC+SetWindowTitleSeq, title)
292 }
293
294
295 func (o Output) EnableBracketedPaste() {
296 fmt.Fprintf(o.tty, CSI+EnableBracketedPasteSeq)
297 }
298
299
300 func (o Output) DisableBracketedPaste() {
301 fmt.Fprintf(o.tty, CSI+DisableBracketedPasteSeq)
302 }
303
304
305
306
307
308
309 func Reset() {
310 output.Reset()
311 }
312
313
314
315
316 func SetForegroundColor(color Color) {
317 output.SetForegroundColor(color)
318 }
319
320
321
322
323 func SetBackgroundColor(color Color) {
324 output.SetBackgroundColor(color)
325 }
326
327
328
329
330 func SetCursorColor(color Color) {
331 output.SetCursorColor(color)
332 }
333
334
335
336
337 func RestoreScreen() {
338 output.RestoreScreen()
339 }
340
341
342
343
344 func SaveScreen() {
345 output.SaveScreen()
346 }
347
348
349
350
351
352 func AltScreen() {
353 output.AltScreen()
354 }
355
356
357
358
359
360 func ExitAltScreen() {
361 output.ExitAltScreen()
362 }
363
364
365
366
367 func ClearScreen() {
368 output.ClearScreen()
369 }
370
371
372
373
374 func MoveCursor(row int, column int) {
375 output.MoveCursor(row, column)
376 }
377
378
379
380
381 func HideCursor() {
382 output.HideCursor()
383 }
384
385
386
387
388 func ShowCursor() {
389 output.ShowCursor()
390 }
391
392
393
394
395 func SaveCursorPosition() {
396 output.SaveCursorPosition()
397 }
398
399
400
401
402 func RestoreCursorPosition() {
403 output.RestoreCursorPosition()
404 }
405
406
407
408
409 func CursorUp(n int) {
410 output.CursorUp(n)
411 }
412
413
414
415
416 func CursorDown(n int) {
417 output.CursorDown(n)
418 }
419
420
421
422
423 func CursorForward(n int) {
424 output.CursorForward(n)
425 }
426
427
428
429
430 func CursorBack(n int) {
431 output.CursorBack(n)
432 }
433
434
435
436
437
438 func CursorNextLine(n int) {
439 output.CursorNextLine(n)
440 }
441
442
443
444
445
446 func CursorPrevLine(n int) {
447 output.CursorPrevLine(n)
448 }
449
450
451
452
453 func ClearLine() {
454 output.ClearLine()
455 }
456
457
458
459
460 func ClearLineLeft() {
461 output.ClearLineLeft()
462 }
463
464
465
466
467 func ClearLineRight() {
468 output.ClearLineRight()
469 }
470
471
472
473
474 func ClearLines(n int) {
475 output.ClearLines(n)
476 }
477
478
479
480
481 func ChangeScrollingRegion(top, bottom int) {
482 output.ChangeScrollingRegion(top, bottom)
483 }
484
485
486
487
488
489 func InsertLines(n int) {
490 output.InsertLines(n)
491 }
492
493
494
495
496
497 func DeleteLines(n int) {
498 output.DeleteLines(n)
499 }
500
501
502
503
504 func EnableMousePress() {
505 output.EnableMousePress()
506 }
507
508
509
510
511 func DisableMousePress() {
512 output.DisableMousePress()
513 }
514
515
516
517
518 func EnableMouse() {
519 output.EnableMouse()
520 }
521
522
523
524
525 func DisableMouse() {
526 output.DisableMouse()
527 }
528
529
530
531
532 func EnableMouseHilite() {
533 output.EnableMouseHilite()
534 }
535
536
537
538
539 func DisableMouseHilite() {
540 output.DisableMouseHilite()
541 }
542
543
544
545
546 func EnableMouseCellMotion() {
547 output.EnableMouseCellMotion()
548 }
549
550
551
552
553 func DisableMouseCellMotion() {
554 output.DisableMouseCellMotion()
555 }
556
557
558
559
560 func EnableMouseAllMotion() {
561 output.EnableMouseAllMotion()
562 }
563
564
565
566
567 func DisableMouseAllMotion() {
568 output.DisableMouseAllMotion()
569 }
570
571
572
573
574 func SetWindowTitle(title string) {
575 output.SetWindowTitle(title)
576 }
577
578
579
580
581 func EnableBracketedPaste() {
582 output.EnableBracketedPaste()
583 }
584
585
586
587
588 func DisableBracketedPaste() {
589 output.DisableBracketedPaste()
590 }
591
View as plain text