mode.go 21 KB

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