1package ansi
2
3import (
4 "strconv"
5 "strings"
6)
7
8// ModeSetting represents a mode setting.
9type ModeSetting byte
10
11// ModeSetting constants.
12const (
13 ModeNotRecognized ModeSetting = iota
14 ModeSet
15 ModeReset
16 ModePermanentlySet
17 ModePermanentlyReset
18)
19
20// IsNotRecognized returns true if the mode is not recognized.
21func (m ModeSetting) IsNotRecognized() bool {
22 return m == ModeNotRecognized
23}
24
25// IsSet returns true if the mode is set or permanently set.
26func (m ModeSetting) IsSet() bool {
27 return m == ModeSet || m == ModePermanentlySet
28}
29
30// IsReset returns true if the mode is reset or permanently reset.
31func (m ModeSetting) IsReset() bool {
32 return m == ModeReset || m == ModePermanentlyReset
33}
34
35// IsPermanentlySet returns true if the mode is permanently set.
36func (m ModeSetting) IsPermanentlySet() bool {
37 return m == ModePermanentlySet
38}
39
40// IsPermanentlyReset returns true if the mode is permanently reset.
41func (m ModeSetting) IsPermanentlyReset() bool {
42 return m == ModePermanentlyReset
43}
44
45// Mode represents an interface for terminal modes.
46// Modes can be set, reset, and requested.
47type Mode interface {
48 Mode() int
49}
50
51// SetMode (SM) returns a sequence to set a mode.
52// The mode arguments are a list of modes to set.
53//
54// If one of the modes is a [DECMode], the function will returns two escape
55// sequences.
56//
57// ANSI format:
58//
59// CSI Pd ; ... ; Pd h
60//
61// DEC format:
62//
63// CSI ? Pd ; ... ; Pd h
64//
65// See: https://vt100.net/docs/vt510-rm/SM.html
66func SetMode(modes ...Mode) string {
67 return setMode(false, modes...)
68}
69
70// SM is an alias for [SetMode].
71func SM(modes ...Mode) string {
72 return SetMode(modes...)
73}
74
75// ResetMode (RM) returns a sequence to reset a mode.
76// The mode arguments are a list of modes to reset.
77//
78// If one of the modes is a [DECMode], the function will returns two escape
79// sequences.
80//
81// ANSI format:
82//
83// CSI Pd ; ... ; Pd l
84//
85// DEC format:
86//
87// CSI ? Pd ; ... ; Pd l
88//
89// See: https://vt100.net/docs/vt510-rm/RM.html
90func ResetMode(modes ...Mode) string {
91 return setMode(true, modes...)
92}
93
94// RM is an alias for [ResetMode].
95func RM(modes ...Mode) string {
96 return ResetMode(modes...)
97}
98
99func setMode(reset bool, modes ...Mode) (s string) {
100 if len(modes) == 0 {
101 return
102 }
103
104 cmd := "h"
105 if reset {
106 cmd = "l"
107 }
108
109 seq := "\x1b["
110 if len(modes) == 1 {
111 switch modes[0].(type) {
112 case DECMode:
113 seq += "?"
114 }
115 return seq + strconv.Itoa(modes[0].Mode()) + cmd
116 }
117
118 dec := make([]string, 0, len(modes)/2)
119 ansi := make([]string, 0, len(modes)/2)
120 for _, m := range modes {
121 switch m.(type) {
122 case DECMode:
123 dec = append(dec, strconv.Itoa(m.Mode()))
124 case ANSIMode:
125 ansi = append(ansi, strconv.Itoa(m.Mode()))
126 }
127 }
128
129 if len(ansi) > 0 {
130 s += seq + strings.Join(ansi, ";") + cmd
131 }
132 if len(dec) > 0 {
133 s += seq + "?" + strings.Join(dec, ";") + cmd
134 }
135 return
136}
137
138// RequestMode (DECRQM) returns a sequence to request a mode from the terminal.
139// The terminal responds with a report mode function [DECRPM].
140//
141// ANSI format:
142//
143// CSI Pa $ p
144//
145// DEC format:
146//
147// CSI ? Pa $ p
148//
149// See: https://vt100.net/docs/vt510-rm/DECRQM.html
150func RequestMode(m Mode) string {
151 seq := "\x1b["
152 switch m.(type) {
153 case DECMode:
154 seq += "?"
155 }
156 return seq + strconv.Itoa(m.Mode()) + "$p"
157}
158
159// DECRQM is an alias for [RequestMode].
160func DECRQM(m Mode) string {
161 return RequestMode(m)
162}
163
164// ReportMode (DECRPM) returns a sequence that the terminal sends to the host
165// in response to a mode request [DECRQM].
166//
167// ANSI format:
168//
169// CSI Pa ; Ps ; $ y
170//
171// DEC format:
172//
173// CSI ? Pa ; Ps $ y
174//
175// Where Pa is the mode number, and Ps is the mode value.
176//
177// 0: Not recognized
178// 1: Set
179// 2: Reset
180// 3: Permanent set
181// 4: Permanent reset
182//
183// See: https://vt100.net/docs/vt510-rm/DECRPM.html
184func ReportMode(mode Mode, value ModeSetting) string {
185 if value > 4 {
186 value = 0
187 }
188 switch mode.(type) {
189 case DECMode:
190 return "\x1b[?" + strconv.Itoa(mode.Mode()) + ";" + strconv.Itoa(int(value)) + "$y"
191 }
192 return "\x1b[" + strconv.Itoa(mode.Mode()) + ";" + strconv.Itoa(int(value)) + "$y"
193}
194
195// DECRPM is an alias for [ReportMode].
196func DECRPM(mode Mode, value ModeSetting) string {
197 return ReportMode(mode, value)
198}
199
200// ANSIMode represents an ANSI terminal mode.
201type ANSIMode int //nolint:revive
202
203// Mode returns the ANSI mode as an integer.
204func (m ANSIMode) Mode() int {
205 return int(m)
206}
207
208// DECMode represents a private DEC terminal mode.
209type DECMode int
210
211// Mode returns the DEC mode as an integer.
212func (m DECMode) Mode() int {
213 return int(m)
214}
215
216// Keyboard Action Mode (KAM) is a mode that controls locking of the keyboard.
217// When the keyboard is locked, it cannot send data to the terminal.
218//
219// See: https://vt100.net/docs/vt510-rm/KAM.html
220const (
221 KeyboardActionMode = ANSIMode(2)
222 KAM = KeyboardActionMode
223
224 SetKeyboardActionMode = "\x1b[2h"
225 ResetKeyboardActionMode = "\x1b[2l"
226 RequestKeyboardActionMode = "\x1b[2$p"
227)
228
229// Insert/Replace Mode (IRM) is a mode that determines whether characters are
230// inserted or replaced when typed.
231//
232// When enabled, characters are inserted at the cursor position pushing the
233// characters to the right. When disabled, characters replace the character at
234// the cursor position.
235//
236// See: https://vt100.net/docs/vt510-rm/IRM.html
237const (
238 InsertReplaceMode = ANSIMode(4)
239 IRM = InsertReplaceMode
240
241 SetInsertReplaceMode = "\x1b[4h"
242 ResetInsertReplaceMode = "\x1b[4l"
243 RequestInsertReplaceMode = "\x1b[4$p"
244)
245
246// BiDirectional Support Mode (BDSM) is a mode that determines whether the
247// terminal supports bidirectional text. When enabled, the terminal supports
248// bidirectional text and is set to implicit bidirectional mode. When disabled,
249// the terminal does not support bidirectional text.
250//
251// See ECMA-48 7.2.1.
252const (
253 BiDirectionalSupportMode = ANSIMode(8)
254 BDSM = BiDirectionalSupportMode
255
256 SetBiDirectionalSupportMode = "\x1b[8h"
257 ResetBiDirectionalSupportMode = "\x1b[8l"
258 RequestBiDirectionalSupportMode = "\x1b[8$p"
259)
260
261// Send Receive Mode (SRM) or Local Echo Mode is a mode that determines whether
262// the terminal echoes characters back to the host. When enabled, the terminal
263// sends characters to the host as they are typed.
264//
265// See: https://vt100.net/docs/vt510-rm/SRM.html
266const (
267 SendReceiveMode = ANSIMode(12)
268 LocalEchoMode = SendReceiveMode
269 SRM = SendReceiveMode
270
271 SetSendReceiveMode = "\x1b[12h"
272 ResetSendReceiveMode = "\x1b[12l"
273 RequestSendReceiveMode = "\x1b[12$p"
274
275 SetLocalEchoMode = "\x1b[12h"
276 ResetLocalEchoMode = "\x1b[12l"
277 RequestLocalEchoMode = "\x1b[12$p"
278)
279
280// Line Feed/New Line Mode (LNM) is a mode that determines whether the terminal
281// interprets the line feed character as a new line.
282//
283// When enabled, the terminal interprets the line feed character as a new line.
284// When disabled, the terminal interprets the line feed character as a line feed.
285//
286// A new line moves the cursor to the first position of the next line.
287// A line feed moves the cursor down one line without changing the column
288// scrolling the screen if necessary.
289//
290// See: https://vt100.net/docs/vt510-rm/LNM.html
291const (
292 LineFeedNewLineMode = ANSIMode(20)
293 LNM = LineFeedNewLineMode
294
295 SetLineFeedNewLineMode = "\x1b[20h"
296 ResetLineFeedNewLineMode = "\x1b[20l"
297 RequestLineFeedNewLineMode = "\x1b[20$p"
298)
299
300// Cursor Keys Mode (DECCKM) is a mode that determines whether the cursor keys
301// send ANSI cursor sequences or application sequences.
302//
303// See: https://vt100.net/docs/vt510-rm/DECCKM.html
304const (
305 CursorKeysMode = DECMode(1)
306 DECCKM = CursorKeysMode
307
308 SetCursorKeysMode = "\x1b[?1h"
309 ResetCursorKeysMode = "\x1b[?1l"
310 RequestCursorKeysMode = "\x1b[?1$p"
311)
312
313// Deprecated: use [SetCursorKeysMode] and [ResetCursorKeysMode] instead.
314const (
315 EnableCursorKeys = "\x1b[?1h"
316 DisableCursorKeys = "\x1b[?1l"
317)
318
319// Origin Mode (DECOM) is a mode that determines whether the cursor moves to the
320// home position or the margin position.
321//
322// See: https://vt100.net/docs/vt510-rm/DECOM.html
323const (
324 OriginMode = DECMode(6)
325 DECOM = OriginMode
326
327 SetOriginMode = "\x1b[?6h"
328 ResetOriginMode = "\x1b[?6l"
329 RequestOriginMode = "\x1b[?6$p"
330)
331
332// Auto Wrap Mode (DECAWM) is a mode that determines whether the cursor wraps
333// to the next line when it reaches the right margin.
334//
335// See: https://vt100.net/docs/vt510-rm/DECAWM.html
336const (
337 AutoWrapMode = DECMode(7)
338 DECAWM = AutoWrapMode
339
340 SetAutoWrapMode = "\x1b[?7h"
341 ResetAutoWrapMode = "\x1b[?7l"
342 RequestAutoWrapMode = "\x1b[?7$p"
343)
344
345// X10 Mouse Mode is a mode that determines whether the mouse reports on button
346// presses.
347//
348// The terminal responds with the following encoding:
349//
350// CSI M CbCxCy
351//
352// Where Cb is the button-1, where it can be 1, 2, or 3.
353// Cx and Cy are the x and y coordinates of the mouse event.
354//
355// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
356const (
357 X10MouseMode = DECMode(9)
358
359 SetX10MouseMode = "\x1b[?9h"
360 ResetX10MouseMode = "\x1b[?9l"
361 RequestX10MouseMode = "\x1b[?9$p"
362)
363
364// Text Cursor Enable Mode (DECTCEM) is a mode that shows/hides the cursor.
365//
366// See: https://vt100.net/docs/vt510-rm/DECTCEM.html
367const (
368 TextCursorEnableMode = DECMode(25)
369 DECTCEM = TextCursorEnableMode
370
371 SetTextCursorEnableMode = "\x1b[?25h"
372 ResetTextCursorEnableMode = "\x1b[?25l"
373 RequestTextCursorEnableMode = "\x1b[?25$p"
374)
375
376// These are aliases for [SetTextCursorEnableMode] and [ResetTextCursorEnableMode].
377const (
378 ShowCursor = SetTextCursorEnableMode
379 HideCursor = ResetTextCursorEnableMode
380)
381
382// Text Cursor Enable Mode (DECTCEM) is a mode that shows/hides the cursor.
383//
384// See: https://vt100.net/docs/vt510-rm/DECTCEM.html
385//
386// Deprecated: use [SetTextCursorEnableMode] and [ResetTextCursorEnableMode] instead.
387const (
388 CursorEnableMode = DECMode(25)
389 RequestCursorVisibility = "\x1b[?25$p"
390)
391
392// Numeric Keypad Mode (DECNKM) is a mode that determines whether the keypad
393// sends application sequences or numeric sequences.
394//
395// This works like [DECKPAM] and [DECKPNM], but uses different sequences.
396//
397// See: https://vt100.net/docs/vt510-rm/DECNKM.html
398const (
399 NumericKeypadMode = DECMode(66)
400 DECNKM = NumericKeypadMode
401
402 SetNumericKeypadMode = "\x1b[?66h"
403 ResetNumericKeypadMode = "\x1b[?66l"
404 RequestNumericKeypadMode = "\x1b[?66$p"
405)
406
407// Backarrow Key Mode (DECBKM) is a mode that determines whether the backspace
408// key sends a backspace or delete character. Disabled by default.
409//
410// See: https://vt100.net/docs/vt510-rm/DECBKM.html
411const (
412 BackarrowKeyMode = DECMode(67)
413 DECBKM = BackarrowKeyMode
414
415 SetBackarrowKeyMode = "\x1b[?67h"
416 ResetBackarrowKeyMode = "\x1b[?67l"
417 RequestBackarrowKeyMode = "\x1b[?67$p"
418)
419
420// Left Right Margin Mode (DECLRMM) is a mode that determines whether the left
421// and right margins can be set with [DECSLRM].
422//
423// See: https://vt100.net/docs/vt510-rm/DECLRMM.html
424const (
425 LeftRightMarginMode = DECMode(69)
426 DECLRMM = LeftRightMarginMode
427
428 SetLeftRightMarginMode = "\x1b[?69h"
429 ResetLeftRightMarginMode = "\x1b[?69l"
430 RequestLeftRightMarginMode = "\x1b[?69$p"
431)
432
433// Normal Mouse Mode is a mode that determines whether the mouse reports on
434// button presses and releases. It will also report modifier keys, wheel
435// events, and extra buttons.
436//
437// It uses the same encoding as [X10MouseMode] with a few differences:
438//
439// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
440const (
441 NormalMouseMode = DECMode(1000)
442
443 SetNormalMouseMode = "\x1b[?1000h"
444 ResetNormalMouseMode = "\x1b[?1000l"
445 RequestNormalMouseMode = "\x1b[?1000$p"
446)
447
448// VT Mouse Tracking is a mode that determines whether the mouse reports on
449// button press and release.
450//
451// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
452//
453// Deprecated: use [NormalMouseMode] instead.
454const (
455 MouseMode = DECMode(1000)
456
457 EnableMouse = "\x1b[?1000h"
458 DisableMouse = "\x1b[?1000l"
459 RequestMouse = "\x1b[?1000$p"
460)
461
462// Highlight Mouse Tracking is a mode that determines whether the mouse reports
463// on button presses, releases, and highlighted cells.
464//
465// It uses the same encoding as [NormalMouseMode] with a few differences:
466//
467// On highlight events, the terminal responds with the following encoding:
468//
469// CSI t CxCy
470// CSI T CxCyCxCyCxCy
471//
472// Where the parameters are startx, starty, endx, endy, mousex, and mousey.
473const (
474 HighlightMouseMode = DECMode(1001)
475
476 SetHighlightMouseMode = "\x1b[?1001h"
477 ResetHighlightMouseMode = "\x1b[?1001l"
478 RequestHighlightMouseMode = "\x1b[?1001$p"
479)
480
481// VT Hilite Mouse Tracking is a mode that determines whether the mouse reports on
482// button presses, releases, and highlighted cells.
483//
484// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
485//
486// Deprecated: use [HighlightMouseMode] instead.
487const (
488 MouseHiliteMode = DECMode(1001)
489
490 EnableMouseHilite = "\x1b[?1001h"
491 DisableMouseHilite = "\x1b[?1001l"
492 RequestMouseHilite = "\x1b[?1001$p"
493)
494
495// Button Event Mouse Tracking is essentially the same as [NormalMouseMode],
496// but it also reports button-motion events when a button is pressed.
497//
498// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
499const (
500 ButtonEventMouseMode = DECMode(1002)
501
502 SetButtonEventMouseMode = "\x1b[?1002h"
503 ResetButtonEventMouseMode = "\x1b[?1002l"
504 RequestButtonEventMouseMode = "\x1b[?1002$p"
505)
506
507// Cell Motion Mouse Tracking is a mode that determines whether the mouse
508// reports on button press, release, and motion events.
509//
510// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
511//
512// Deprecated: use [ButtonEventMouseMode] instead.
513const (
514 MouseCellMotionMode = DECMode(1002)
515
516 EnableMouseCellMotion = "\x1b[?1002h"
517 DisableMouseCellMotion = "\x1b[?1002l"
518 RequestMouseCellMotion = "\x1b[?1002$p"
519)
520
521// Any Event Mouse Tracking is the same as [ButtonEventMouseMode], except that
522// all motion events are reported even if no mouse buttons are pressed.
523//
524// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
525const (
526 AnyEventMouseMode = DECMode(1003)
527
528 SetAnyEventMouseMode = "\x1b[?1003h"
529 ResetAnyEventMouseMode = "\x1b[?1003l"
530 RequestAnyEventMouseMode = "\x1b[?1003$p"
531)
532
533// All Mouse Tracking is a mode that determines whether the mouse reports on
534// button press, release, motion, and highlight events.
535//
536// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
537//
538// Deprecated: use [AnyEventMouseMode] instead.
539const (
540 MouseAllMotionMode = DECMode(1003)
541
542 EnableMouseAllMotion = "\x1b[?1003h"
543 DisableMouseAllMotion = "\x1b[?1003l"
544 RequestMouseAllMotion = "\x1b[?1003$p"
545)
546
547// Focus Event Mode is a mode that determines whether the terminal reports focus
548// and blur events.
549//
550// The terminal sends the following encoding:
551//
552// CSI I // Focus In
553// CSI O // Focus Out
554//
555// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Focus-Tracking
556const (
557 FocusEventMode = DECMode(1004)
558
559 SetFocusEventMode = "\x1b[?1004h"
560 ResetFocusEventMode = "\x1b[?1004l"
561 RequestFocusEventMode = "\x1b[?1004$p"
562)
563
564// Deprecated: use [SetFocusEventMode], [ResetFocusEventMode], and
565// [RequestFocusEventMode] instead.
566const (
567 ReportFocusMode = DECMode(1004)
568
569 EnableReportFocus = "\x1b[?1004h"
570 DisableReportFocus = "\x1b[?1004l"
571 RequestReportFocus = "\x1b[?1004$p"
572)
573
574// SGR Extended Mouse Mode is a mode that changes the mouse tracking encoding
575// to use SGR parameters.
576//
577// The terminal responds with the following encoding:
578//
579// CSI < Cb ; Cx ; Cy M
580//
581// Where Cb is the same as [NormalMouseMode], and Cx and Cy are the x and y.
582//
583// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
584const (
585 SgrExtMouseMode = DECMode(1006)
586
587 SetSgrExtMouseMode = "\x1b[?1006h"
588 ResetSgrExtMouseMode = "\x1b[?1006l"
589 RequestSgrExtMouseMode = "\x1b[?1006$p"
590)
591
592// Deprecated: use [SgrExtMouseMode] [SetSgrExtMouseMode],
593// [ResetSgrExtMouseMode], and [RequestSgrExtMouseMode] instead.
594const (
595 MouseSgrExtMode = DECMode(1006)
596 EnableMouseSgrExt = "\x1b[?1006h"
597 DisableMouseSgrExt = "\x1b[?1006l"
598 RequestMouseSgrExt = "\x1b[?1006$p"
599)
600
601// UTF-8 Extended Mouse Mode is a mode that changes the mouse tracking encoding
602// to use UTF-8 parameters.
603//
604// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
605const (
606 Utf8ExtMouseMode = DECMode(1005)
607
608 SetUtf8ExtMouseMode = "\x1b[?1005h"
609 ResetUtf8ExtMouseMode = "\x1b[?1005l"
610 RequestUtf8ExtMouseMode = "\x1b[?1005$p"
611)
612
613// URXVT Extended Mouse Mode is a mode that changes the mouse tracking encoding
614// to use an alternate encoding.
615//
616// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
617const (
618 UrxvtExtMouseMode = DECMode(1015)
619
620 SetUrxvtExtMouseMode = "\x1b[?1015h"
621 ResetUrxvtExtMouseMode = "\x1b[?1015l"
622 RequestUrxvtExtMouseMode = "\x1b[?1015$p"
623)
624
625// SGR Pixel Extended Mouse Mode is a mode that changes the mouse tracking
626// encoding to use SGR parameters with pixel coordinates.
627//
628// This is similar to [SgrExtMouseMode], but also reports pixel coordinates.
629//
630// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
631const (
632 SgrPixelExtMouseMode = DECMode(1016)
633
634 SetSgrPixelExtMouseMode = "\x1b[?1016h"
635 ResetSgrPixelExtMouseMode = "\x1b[?1016l"
636 RequestSgrPixelExtMouseMode = "\x1b[?1016$p"
637)
638
639// Alternate Screen Mode is a mode that determines whether the alternate screen
640// buffer is active. When this mode is enabled, the alternate screen buffer is
641// cleared.
642//
643// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
644const (
645 AltScreenMode = DECMode(1047)
646
647 SetAltScreenMode = "\x1b[?1047h"
648 ResetAltScreenMode = "\x1b[?1047l"
649 RequestAltScreenMode = "\x1b[?1047$p"
650)
651
652// Save Cursor Mode is a mode that saves the cursor position.
653// This is equivalent to [SaveCursor] and [RestoreCursor].
654//
655// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
656const (
657 SaveCursorMode = DECMode(1048)
658
659 SetSaveCursorMode = "\x1b[?1048h"
660 ResetSaveCursorMode = "\x1b[?1048l"
661 RequestSaveCursorMode = "\x1b[?1048$p"
662)
663
664// Alternate Screen Save Cursor Mode is a mode that saves the cursor position as in
665// [SaveCursorMode], switches to the alternate screen buffer as in [AltScreenMode],
666// and clears the screen on switch.
667//
668// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
669const (
670 AltScreenSaveCursorMode = DECMode(1049)
671
672 SetAltScreenSaveCursorMode = "\x1b[?1049h"
673 ResetAltScreenSaveCursorMode = "\x1b[?1049l"
674 RequestAltScreenSaveCursorMode = "\x1b[?1049$p"
675)
676
677// Alternate Screen Buffer is a mode that determines whether the alternate screen
678// buffer is active.
679//
680// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
681//
682// Deprecated: use [AltScreenSaveCursorMode] instead.
683const (
684 AltScreenBufferMode = DECMode(1049)
685
686 SetAltScreenBufferMode = "\x1b[?1049h"
687 ResetAltScreenBufferMode = "\x1b[?1049l"
688 RequestAltScreenBufferMode = "\x1b[?1049$p"
689
690 EnableAltScreenBuffer = "\x1b[?1049h"
691 DisableAltScreenBuffer = "\x1b[?1049l"
692 RequestAltScreenBuffer = "\x1b[?1049$p"
693)
694
695// Bracketed Paste Mode is a mode that determines whether pasted text is
696// bracketed with escape sequences.
697//
698// See: https://cirw.in/blog/bracketed-paste
699// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Bracketed-Paste-Mode
700const (
701 BracketedPasteMode = DECMode(2004)
702
703 SetBracketedPasteMode = "\x1b[?2004h"
704 ResetBracketedPasteMode = "\x1b[?2004l"
705 RequestBracketedPasteMode = "\x1b[?2004$p"
706)
707
708// Deprecated: use [SetBracketedPasteMode], [ResetBracketedPasteMode], and
709// [RequestBracketedPasteMode] instead.
710const (
711 EnableBracketedPaste = "\x1b[?2004h"
712 DisableBracketedPaste = "\x1b[?2004l"
713 RequestBracketedPaste = "\x1b[?2004$p"
714)
715
716// Synchronized Output Mode is a mode that determines whether output is
717// synchronized with the terminal.
718//
719// See: https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036
720const (
721 SynchronizedOutputMode = DECMode(2026)
722
723 SetSynchronizedOutputMode = "\x1b[?2026h"
724 ResetSynchronizedOutputMode = "\x1b[?2026l"
725 RequestSynchronizedOutputMode = "\x1b[?2026$p"
726)
727
728// Deprecated: use [SynchronizedOutputMode], [SetSynchronizedOutputMode], and
729// [ResetSynchronizedOutputMode], and [RequestSynchronizedOutputMode] instead.
730const (
731 SyncdOutputMode = DECMode(2026)
732
733 EnableSyncdOutput = "\x1b[?2026h"
734 DisableSyncdOutput = "\x1b[?2026l"
735 RequestSyncdOutput = "\x1b[?2026$p"
736)
737
738// Grapheme Clustering Mode is a mode that determines whether the terminal
739// should look for grapheme clusters instead of single runes in the rendered
740// text. This makes the terminal properly render combining characters such as
741// emojis.
742//
743// See: https://github.com/contour-terminal/terminal-unicode-core
744const (
745 GraphemeClusteringMode = DECMode(2027)
746
747 SetGraphemeClusteringMode = "\x1b[?2027h"
748 ResetGraphemeClusteringMode = "\x1b[?2027l"
749 RequestGraphemeClusteringMode = "\x1b[?2027$p"
750)
751
752// Deprecated: use [SetGraphemeClusteringMode], [ResetGraphemeClusteringMode], and
753// [RequestGraphemeClusteringMode] instead.
754const (
755 EnableGraphemeClustering = "\x1b[?2027h"
756 DisableGraphemeClustering = "\x1b[?2027l"
757 RequestGraphemeClustering = "\x1b[?2027$p"
758)
759
760// Win32Input is a mode that determines whether input is processed by the
761// Win32 console and Conpty.
762//
763// See: https://github.com/microsoft/terminal/blob/main/doc/specs/%234999%20-%20Improved%20keyboard%20handling%20in%20Conpty.md
764const (
765 Win32InputMode = DECMode(9001)
766
767 SetWin32InputMode = "\x1b[?9001h"
768 ResetWin32InputMode = "\x1b[?9001l"
769 RequestWin32InputMode = "\x1b[?9001$p"
770)
771
772// Deprecated: use [SetWin32InputMode], [ResetWin32InputMode], and
773// [RequestWin32InputMode] instead.
774const (
775 EnableWin32Input = "\x1b[?9001h"
776 DisableWin32Input = "\x1b[?9001l"
777 RequestWin32Input = "\x1b[?9001$p"
778)