main
Raw Download raw file
  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// Send Receive Mode (SRM) or Local Echo Mode is a mode that determines whether
247// the terminal echoes characters back to the host. When enabled, the terminal
248// sends characters to the host as they are typed.
249//
250// See: https://vt100.net/docs/vt510-rm/SRM.html
251const (
252	SendReceiveMode = ANSIMode(12)
253	LocalEchoMode   = SendReceiveMode
254	SRM             = SendReceiveMode
255
256	SetSendReceiveMode     = "\x1b[12h"
257	ResetSendReceiveMode   = "\x1b[12l"
258	RequestSendReceiveMode = "\x1b[12$p"
259
260	SetLocalEchoMode     = "\x1b[12h"
261	ResetLocalEchoMode   = "\x1b[12l"
262	RequestLocalEchoMode = "\x1b[12$p"
263)
264
265// Line Feed/New Line Mode (LNM) is a mode that determines whether the terminal
266// interprets the line feed character as a new line.
267//
268// When enabled, the terminal interprets the line feed character as a new line.
269// When disabled, the terminal interprets the line feed character as a line feed.
270//
271// A new line moves the cursor to the first position of the next line.
272// A line feed moves the cursor down one line without changing the column
273// scrolling the screen if necessary.
274//
275// See: https://vt100.net/docs/vt510-rm/LNM.html
276const (
277	LineFeedNewLineMode = ANSIMode(20)
278	LNM                 = LineFeedNewLineMode
279
280	SetLineFeedNewLineMode     = "\x1b[20h"
281	ResetLineFeedNewLineMode   = "\x1b[20l"
282	RequestLineFeedNewLineMode = "\x1b[20$p"
283)
284
285// Cursor Keys Mode (DECCKM) is a mode that determines whether the cursor keys
286// send ANSI cursor sequences or application sequences.
287//
288// See: https://vt100.net/docs/vt510-rm/DECCKM.html
289const (
290	CursorKeysMode = DECMode(1)
291	DECCKM         = CursorKeysMode
292
293	SetCursorKeysMode     = "\x1b[?1h"
294	ResetCursorKeysMode   = "\x1b[?1l"
295	RequestCursorKeysMode = "\x1b[?1$p"
296)
297
298// Deprecated: use [SetCursorKeysMode] and [ResetCursorKeysMode] instead.
299const (
300	EnableCursorKeys  = "\x1b[?1h"
301	DisableCursorKeys = "\x1b[?1l"
302)
303
304// Origin Mode (DECOM) is a mode that determines whether the cursor moves to the
305// home position or the margin position.
306//
307// See: https://vt100.net/docs/vt510-rm/DECOM.html
308const (
309	OriginMode = DECMode(6)
310	DECOM      = OriginMode
311
312	SetOriginMode     = "\x1b[?6h"
313	ResetOriginMode   = "\x1b[?6l"
314	RequestOriginMode = "\x1b[?6$p"
315)
316
317// Auto Wrap Mode (DECAWM) is a mode that determines whether the cursor wraps
318// to the next line when it reaches the right margin.
319//
320// See: https://vt100.net/docs/vt510-rm/DECAWM.html
321const (
322	AutoWrapMode = DECMode(7)
323	DECAWM       = AutoWrapMode
324
325	SetAutoWrapMode     = "\x1b[?7h"
326	ResetAutoWrapMode   = "\x1b[?7l"
327	RequestAutoWrapMode = "\x1b[?7$p"
328)
329
330// X10 Mouse Mode is a mode that determines whether the mouse reports on button
331// presses.
332//
333// The terminal responds with the following encoding:
334//
335//	CSI M CbCxCy
336//
337// Where Cb is the button-1, where it can be 1, 2, or 3.
338// Cx and Cy are the x and y coordinates of the mouse event.
339//
340// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
341const (
342	X10MouseMode = DECMode(9)
343
344	SetX10MouseMode     = "\x1b[?9h"
345	ResetX10MouseMode   = "\x1b[?9l"
346	RequestX10MouseMode = "\x1b[?9$p"
347)
348
349// Text Cursor Enable Mode (DECTCEM) is a mode that shows/hides the cursor.
350//
351// See: https://vt100.net/docs/vt510-rm/DECTCEM.html
352const (
353	TextCursorEnableMode = DECMode(25)
354	DECTCEM              = TextCursorEnableMode
355
356	SetTextCursorEnableMode     = "\x1b[?25h"
357	ResetTextCursorEnableMode   = "\x1b[?25l"
358	RequestTextCursorEnableMode = "\x1b[?25$p"
359)
360
361// These are aliases for [SetTextCursorEnableMode] and [ResetTextCursorEnableMode].
362const (
363	ShowCursor = SetTextCursorEnableMode
364	HideCursor = ResetTextCursorEnableMode
365)
366
367// Text Cursor Enable Mode (DECTCEM) is a mode that shows/hides the cursor.
368//
369// See: https://vt100.net/docs/vt510-rm/DECTCEM.html
370//
371// Deprecated: use [SetTextCursorEnableMode] and [ResetTextCursorEnableMode] instead.
372const (
373	CursorEnableMode        = DECMode(25)
374	RequestCursorVisibility = "\x1b[?25$p"
375)
376
377// Numeric Keypad Mode (DECNKM) is a mode that determines whether the keypad
378// sends application sequences or numeric sequences.
379//
380// This works like [DECKPAM] and [DECKPNM], but uses different sequences.
381//
382// See: https://vt100.net/docs/vt510-rm/DECNKM.html
383const (
384	NumericKeypadMode = DECMode(66)
385	DECNKM            = NumericKeypadMode
386
387	SetNumericKeypadMode     = "\x1b[?66h"
388	ResetNumericKeypadMode   = "\x1b[?66l"
389	RequestNumericKeypadMode = "\x1b[?66$p"
390)
391
392// Backarrow Key Mode (DECBKM) is a mode that determines whether the backspace
393// key sends a backspace or delete character. Disabled by default.
394//
395// See: https://vt100.net/docs/vt510-rm/DECBKM.html
396const (
397	BackarrowKeyMode = DECMode(67)
398	DECBKM           = BackarrowKeyMode
399
400	SetBackarrowKeyMode     = "\x1b[?67h"
401	ResetBackarrowKeyMode   = "\x1b[?67l"
402	RequestBackarrowKeyMode = "\x1b[?67$p"
403)
404
405// Left Right Margin Mode (DECLRMM) is a mode that determines whether the left
406// and right margins can be set with [DECSLRM].
407//
408// See: https://vt100.net/docs/vt510-rm/DECLRMM.html
409const (
410	LeftRightMarginMode = DECMode(69)
411	DECLRMM             = LeftRightMarginMode
412
413	SetLeftRightMarginMode     = "\x1b[?69h"
414	ResetLeftRightMarginMode   = "\x1b[?69l"
415	RequestLeftRightMarginMode = "\x1b[?69$p"
416)
417
418// Normal Mouse Mode is a mode that determines whether the mouse reports on
419// button presses and releases. It will also report modifier keys, wheel
420// events, and extra buttons.
421//
422// It uses the same encoding as [X10MouseMode] with a few differences:
423//
424// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
425const (
426	NormalMouseMode = DECMode(1000)
427
428	SetNormalMouseMode     = "\x1b[?1000h"
429	ResetNormalMouseMode   = "\x1b[?1000l"
430	RequestNormalMouseMode = "\x1b[?1000$p"
431)
432
433// VT Mouse Tracking is a mode that determines whether the mouse reports on
434// button press and release.
435//
436// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
437//
438// Deprecated: use [NormalMouseMode] instead.
439const (
440	MouseMode = DECMode(1000)
441
442	EnableMouse  = "\x1b[?1000h"
443	DisableMouse = "\x1b[?1000l"
444	RequestMouse = "\x1b[?1000$p"
445)
446
447// Highlight Mouse Tracking is a mode that determines whether the mouse reports
448// on button presses, releases, and highlighted cells.
449//
450// It uses the same encoding as [NormalMouseMode] with a few differences:
451//
452// On highlight events, the terminal responds with the following encoding:
453//
454//	CSI t CxCy
455//	CSI T CxCyCxCyCxCy
456//
457// Where the parameters are startx, starty, endx, endy, mousex, and mousey.
458const (
459	HighlightMouseMode = DECMode(1001)
460
461	SetHighlightMouseMode     = "\x1b[?1001h"
462	ResetHighlightMouseMode   = "\x1b[?1001l"
463	RequestHighlightMouseMode = "\x1b[?1001$p"
464)
465
466// VT Hilite Mouse Tracking is a mode that determines whether the mouse reports on
467// button presses, releases, and highlighted cells.
468//
469// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
470//
471// Deprecated: use [HighlightMouseMode] instead.
472const (
473	MouseHiliteMode = DECMode(1001)
474
475	EnableMouseHilite  = "\x1b[?1001h"
476	DisableMouseHilite = "\x1b[?1001l"
477	RequestMouseHilite = "\x1b[?1001$p"
478)
479
480// Button Event Mouse Tracking is essentially the same as [NormalMouseMode],
481// but it also reports button-motion events when a button is pressed.
482//
483// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
484const (
485	ButtonEventMouseMode = DECMode(1002)
486
487	SetButtonEventMouseMode     = "\x1b[?1002h"
488	ResetButtonEventMouseMode   = "\x1b[?1002l"
489	RequestButtonEventMouseMode = "\x1b[?1002$p"
490)
491
492// Cell Motion Mouse Tracking is a mode that determines whether the mouse
493// reports on button press, release, and motion events.
494//
495// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
496//
497// Deprecated: use [ButtonEventMouseMode] instead.
498const (
499	MouseCellMotionMode = DECMode(1002)
500
501	EnableMouseCellMotion  = "\x1b[?1002h"
502	DisableMouseCellMotion = "\x1b[?1002l"
503	RequestMouseCellMotion = "\x1b[?1002$p"
504)
505
506// Any Event Mouse Tracking is the same as [ButtonEventMouseMode], except that
507// all motion events are reported even if no mouse buttons are pressed.
508//
509// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
510const (
511	AnyEventMouseMode = DECMode(1003)
512
513	SetAnyEventMouseMode     = "\x1b[?1003h"
514	ResetAnyEventMouseMode   = "\x1b[?1003l"
515	RequestAnyEventMouseMode = "\x1b[?1003$p"
516)
517
518// All Mouse Tracking is a mode that determines whether the mouse reports on
519// button press, release, motion, and highlight events.
520//
521// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
522//
523// Deprecated: use [AnyEventMouseMode] instead.
524const (
525	MouseAllMotionMode = DECMode(1003)
526
527	EnableMouseAllMotion  = "\x1b[?1003h"
528	DisableMouseAllMotion = "\x1b[?1003l"
529	RequestMouseAllMotion = "\x1b[?1003$p"
530)
531
532// Focus Event Mode is a mode that determines whether the terminal reports focus
533// and blur events.
534//
535// The terminal sends the following encoding:
536//
537//	CSI I // Focus In
538//	CSI O // Focus Out
539//
540// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Focus-Tracking
541const (
542	FocusEventMode = DECMode(1004)
543
544	SetFocusEventMode     = "\x1b[?1004h"
545	ResetFocusEventMode   = "\x1b[?1004l"
546	RequestFocusEventMode = "\x1b[?1004$p"
547)
548
549// Deprecated: use [SetFocusEventMode], [ResetFocusEventMode], and
550// [RequestFocusEventMode] instead.
551const (
552	ReportFocusMode = DECMode(1004)
553
554	EnableReportFocus  = "\x1b[?1004h"
555	DisableReportFocus = "\x1b[?1004l"
556	RequestReportFocus = "\x1b[?1004$p"
557)
558
559// SGR Extended Mouse Mode is a mode that changes the mouse tracking encoding
560// to use SGR parameters.
561//
562// The terminal responds with the following encoding:
563//
564//	CSI < Cb ; Cx ; Cy M
565//
566// Where Cb is the same as [NormalMouseMode], and Cx and Cy are the x and y.
567//
568// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
569const (
570	SgrExtMouseMode = DECMode(1006)
571
572	SetSgrExtMouseMode     = "\x1b[?1006h"
573	ResetSgrExtMouseMode   = "\x1b[?1006l"
574	RequestSgrExtMouseMode = "\x1b[?1006$p"
575)
576
577// Deprecated: use [SgrExtMouseMode] [SetSgrExtMouseMode],
578// [ResetSgrExtMouseMode], and [RequestSgrExtMouseMode] instead.
579const (
580	MouseSgrExtMode    = DECMode(1006)
581	EnableMouseSgrExt  = "\x1b[?1006h"
582	DisableMouseSgrExt = "\x1b[?1006l"
583	RequestMouseSgrExt = "\x1b[?1006$p"
584)
585
586// UTF-8 Extended Mouse Mode is a mode that changes the mouse tracking encoding
587// to use UTF-8 parameters.
588//
589// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
590const (
591	Utf8ExtMouseMode = DECMode(1005)
592
593	SetUtf8ExtMouseMode     = "\x1b[?1005h"
594	ResetUtf8ExtMouseMode   = "\x1b[?1005l"
595	RequestUtf8ExtMouseMode = "\x1b[?1005$p"
596)
597
598// URXVT Extended Mouse Mode is a mode that changes the mouse tracking encoding
599// to use an alternate encoding.
600//
601// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
602const (
603	UrxvtExtMouseMode = DECMode(1015)
604
605	SetUrxvtExtMouseMode     = "\x1b[?1015h"
606	ResetUrxvtExtMouseMode   = "\x1b[?1015l"
607	RequestUrxvtExtMouseMode = "\x1b[?1015$p"
608)
609
610// SGR Pixel Extended Mouse Mode is a mode that changes the mouse tracking
611// encoding to use SGR parameters with pixel coordinates.
612//
613// This is similar to [SgrExtMouseMode], but also reports pixel coordinates.
614//
615// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
616const (
617	SgrPixelExtMouseMode = DECMode(1016)
618
619	SetSgrPixelExtMouseMode     = "\x1b[?1016h"
620	ResetSgrPixelExtMouseMode   = "\x1b[?1016l"
621	RequestSgrPixelExtMouseMode = "\x1b[?1016$p"
622)
623
624// Alternate Screen Mode is a mode that determines whether the alternate screen
625// buffer is active. When this mode is enabled, the alternate screen buffer is
626// cleared.
627//
628// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
629const (
630	AltScreenMode = DECMode(1047)
631
632	SetAltScreenMode     = "\x1b[?1047h"
633	ResetAltScreenMode   = "\x1b[?1047l"
634	RequestAltScreenMode = "\x1b[?1047$p"
635)
636
637// Save Cursor Mode is a mode that saves the cursor position.
638// This is equivalent to [SaveCursor] and [RestoreCursor].
639//
640// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
641const (
642	SaveCursorMode = DECMode(1048)
643
644	SetSaveCursorMode     = "\x1b[?1048h"
645	ResetSaveCursorMode   = "\x1b[?1048l"
646	RequestSaveCursorMode = "\x1b[?1048$p"
647)
648
649// Alternate Screen Save Cursor Mode is a mode that saves the cursor position as in
650// [SaveCursorMode], switches to the alternate screen buffer as in [AltScreenMode],
651// and clears the screen on switch.
652//
653// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
654const (
655	AltScreenSaveCursorMode = DECMode(1049)
656
657	SetAltScreenSaveCursorMode     = "\x1b[?1049h"
658	ResetAltScreenSaveCursorMode   = "\x1b[?1049l"
659	RequestAltScreenSaveCursorMode = "\x1b[?1049$p"
660)
661
662// Alternate Screen Buffer is a mode that determines whether the alternate screen
663// buffer is active.
664//
665// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
666//
667// Deprecated: use [AltScreenSaveCursorMode] instead.
668const (
669	AltScreenBufferMode = DECMode(1049)
670
671	SetAltScreenBufferMode     = "\x1b[?1049h"
672	ResetAltScreenBufferMode   = "\x1b[?1049l"
673	RequestAltScreenBufferMode = "\x1b[?1049$p"
674
675	EnableAltScreenBuffer  = "\x1b[?1049h"
676	DisableAltScreenBuffer = "\x1b[?1049l"
677	RequestAltScreenBuffer = "\x1b[?1049$p"
678)
679
680// Bracketed Paste Mode is a mode that determines whether pasted text is
681// bracketed with escape sequences.
682//
683// See: https://cirw.in/blog/bracketed-paste
684// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Bracketed-Paste-Mode
685const (
686	BracketedPasteMode = DECMode(2004)
687
688	SetBracketedPasteMode     = "\x1b[?2004h"
689	ResetBracketedPasteMode   = "\x1b[?2004l"
690	RequestBracketedPasteMode = "\x1b[?2004$p"
691)
692
693// Deprecated: use [SetBracketedPasteMode], [ResetBracketedPasteMode], and
694// [RequestBracketedPasteMode] instead.
695const (
696	EnableBracketedPaste  = "\x1b[?2004h"
697	DisableBracketedPaste = "\x1b[?2004l"
698	RequestBracketedPaste = "\x1b[?2004$p"
699)
700
701// Synchronized Output Mode is a mode that determines whether output is
702// synchronized with the terminal.
703//
704// See: https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036
705const (
706	SynchronizedOutputMode = DECMode(2026)
707
708	SetSynchronizedOutputMode     = "\x1b[?2026h"
709	ResetSynchronizedOutputMode   = "\x1b[?2026l"
710	RequestSynchronizedOutputMode = "\x1b[?2026$p"
711)
712
713// Deprecated: use [SynchronizedOutputMode], [SetSynchronizedOutputMode], and
714// [ResetSynchronizedOutputMode], and [RequestSynchronizedOutputMode] instead.
715const (
716	SyncdOutputMode = DECMode(2026)
717
718	EnableSyncdOutput  = "\x1b[?2026h"
719	DisableSyncdOutput = "\x1b[?2026l"
720	RequestSyncdOutput = "\x1b[?2026$p"
721)
722
723// Grapheme Clustering Mode is a mode that determines whether the terminal
724// should look for grapheme clusters instead of single runes in the rendered
725// text. This makes the terminal properly render combining characters such as
726// emojis.
727//
728// See: https://github.com/contour-terminal/terminal-unicode-core
729const (
730	GraphemeClusteringMode = DECMode(2027)
731
732	SetGraphemeClusteringMode     = "\x1b[?2027h"
733	ResetGraphemeClusteringMode   = "\x1b[?2027l"
734	RequestGraphemeClusteringMode = "\x1b[?2027$p"
735)
736
737// Deprecated: use [SetGraphemeClusteringMode], [ResetGraphemeClusteringMode], and
738// [RequestGraphemeClusteringMode] instead.
739const (
740	EnableGraphemeClustering  = "\x1b[?2027h"
741	DisableGraphemeClustering = "\x1b[?2027l"
742	RequestGraphemeClustering = "\x1b[?2027$p"
743)
744
745// Win32Input is a mode that determines whether input is processed by the
746// Win32 console and Conpty.
747//
748// See: https://github.com/microsoft/terminal/blob/main/doc/specs/%234999%20-%20Improved%20keyboard%20handling%20in%20Conpty.md
749const (
750	Win32InputMode = DECMode(9001)
751
752	SetWin32InputMode     = "\x1b[?9001h"
753	ResetWin32InputMode   = "\x1b[?9001l"
754	RequestWin32InputMode = "\x1b[?9001$p"
755)
756
757// Deprecated: use [SetWin32InputMode], [ResetWin32InputMode], and
758// [RequestWin32InputMode] instead.
759const (
760	EnableWin32Input  = "\x1b[?9001h"
761	DisableWin32Input = "\x1b[?9001l"
762	RequestWin32Input = "\x1b[?9001$p"
763)