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