vendor/github.com/charmbracelet/x/ansi/mode.go

153 lines · 4920 bytes

  1package ansi
  2
  3// This file define uses multiple sequences to set (SM), reset (RM), and request
  4// (DECRQM) different ANSI and DEC modes.
  5//
  6// See: https://vt100.net/docs/vt510-rm/SM.html
  7// See: https://vt100.net/docs/vt510-rm/RM.html
  8// See: https://vt100.net/docs/vt510-rm/DECRQM.html
  9//
 10// The terminal then responds to the request with a Report Mode function
 11// (DECRPM) in the format:
 12//
 13// ANSI format:
 14//
 15//  CSI Pa ; Ps ; $ y
 16//
 17// DEC format:
 18//
 19//  CSI ? Pa ; Ps $ y
 20//
 21// Where Pa is the mode number, and Ps is the mode value.
 22// See: https://vt100.net/docs/vt510-rm/DECRPM.html
 23
 24// Application Cursor Keys (DECCKM) is a mode that determines whether the
 25// cursor keys send ANSI cursor sequences or application sequences.
 26//
 27// See: https://vt100.net/docs/vt510-rm/DECCKM.html
 28const (
 29	EnableCursorKeys  = "\x1b[?1h"
 30	DisableCursorKeys = "\x1b[?1l"
 31	RequestCursorKeys = "\x1b[?1$p"
 32)
 33
 34// Text Cursor Enable Mode (DECTCEM) is a mode that shows/hides the cursor.
 35//
 36// See: https://vt100.net/docs/vt510-rm/DECTCEM.html
 37const (
 38	ShowCursor              = "\x1b[?25h"
 39	HideCursor              = "\x1b[?25l"
 40	RequestCursorVisibility = "\x1b[?25$p"
 41)
 42
 43// VT Mouse Tracking is a mode that determines whether the mouse reports on
 44// button press and release.
 45//
 46// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
 47const (
 48	EnableMouse  = "\x1b[?1000h"
 49	DisableMouse = "\x1b[?1000l"
 50	RequestMouse = "\x1b[?1000$p"
 51)
 52
 53// VT Hilite Mouse Tracking is a mode that determines whether the mouse reports on
 54// button presses, releases, and highlighted cells.
 55//
 56// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
 57const (
 58	EnableMouseHilite  = "\x1b[?1001h"
 59	DisableMouseHilite = "\x1b[?1001l"
 60	RequestMouseHilite = "\x1b[?1001$p"
 61)
 62
 63// Cell Motion Mouse Tracking is a mode that determines whether the mouse
 64// reports on button press, release, and motion events.
 65//
 66// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
 67const (
 68	EnableMouseCellMotion  = "\x1b[?1002h"
 69	DisableMouseCellMotion = "\x1b[?1002l"
 70	RequestMouseCellMotion = "\x1b[?1002$p"
 71)
 72
 73// All Mouse Tracking is a mode that determines whether the mouse reports on
 74// button press, release, motion, and highlight events.
 75//
 76// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
 77const (
 78	EnableMouseAllMotion  = "\x1b[?1003h"
 79	DisableMouseAllMotion = "\x1b[?1003l"
 80	RequestMouseAllMotion = "\x1b[?1003$p"
 81)
 82
 83// Report Focus is a mode that makes the terminal report focus-in and focus-out events.
 84//
 85// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-FocusIn_FocusOut
 86const (
 87	EnableReportFocus  = "\x1b[?1004h"
 88	DisableReportFocus = "\x1b[?1004l"
 89	RequestReportFocus = "\x1b[?1004$p"
 90)
 91
 92// SGR Mouse Extension is a mode that determines whether the mouse reports events
 93// formatted with SGR parameters.
 94//
 95// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
 96const (
 97	EnableMouseSgrExt  = "\x1b[?1006h"
 98	DisableMouseSgrExt = "\x1b[?1006l"
 99	RequestMouseSgrExt = "\x1b[?1006$p"
100)
101
102// Alternate Screen Buffer is a mode that determines whether the alternate screen
103// buffer is active.
104//
105// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
106const (
107	EnableAltScreenBuffer  = "\x1b[?1049h"
108	DisableAltScreenBuffer = "\x1b[?1049l"
109	RequestAltScreenBuffer = "\x1b[?1049$p"
110)
111
112// Bracketed Paste Mode is a mode that determines whether pasted text is
113// bracketed with escape sequences.
114//
115// See: https://cirw.in/blog/bracketed-paste
116// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Bracketed-Paste-Mode
117const (
118	EnableBracketedPaste  = "\x1b[?2004h"
119	DisableBracketedPaste = "\x1b[?2004l"
120	RequestBracketedPaste = "\x1b[?2004$p"
121)
122
123// Synchronized Output Mode is a mode that determines whether output is
124// synchronized with the terminal.
125//
126// See: https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036
127const (
128	EnableSyncdOutput  = "\x1b[?2026h"
129	DisableSyncdOutput = "\x1b[?2026l"
130	RequestSyncdOutput = "\x1b[?2026$p"
131)
132
133// Grapheme Clustering Mode is a mode that determines whether the terminal
134// should look for grapheme clusters instead of single runes in the rendered
135// text. This makes the terminal properly render combining characters such as
136// emojis.
137//
138// See: https://github.com/contour-terminal/terminal-unicode-core
139const (
140	EnableGraphemeClustering  = "\x1b[?2027h"
141	DisableGraphemeClustering = "\x1b[?2027l"
142	RequestGraphemeClustering = "\x1b[?2027$p"
143)
144
145// Win32Input is a mode that determines whether input is processed by the
146// Win32 console and Conpty.
147//
148// See: https://github.com/microsoft/terminal/blob/main/doc/specs/%234999%20-%20Improved%20keyboard%20handling%20in%20Conpty.md
149const (
150	EnableWin32Input  = "\x1b[?9001h"
151	DisableWin32Input = "\x1b[?9001l"
152	RequestWin32Input = "\x1b[?9001$p"
153)