mode.go 21 KB

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