xterm.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package ansi
  2. import "strconv"
  3. // KeyModifierOptions (XTMODKEYS) sets/resets xterm key modifier options.
  4. //
  5. // Default is 0.
  6. //
  7. // CSI > Pp m
  8. // CSI > Pp ; Pv m
  9. //
  10. // If Pv is omitted, the resource is reset to its initial value.
  11. //
  12. // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
  13. func KeyModifierOptions(p int, vs ...int) string {
  14. var pp, pv string
  15. if p > 0 {
  16. pp = strconv.Itoa(p)
  17. }
  18. if len(vs) == 0 {
  19. return "\x1b[>" + strconv.Itoa(p) + "m"
  20. }
  21. v := vs[0]
  22. if v > 0 {
  23. pv = strconv.Itoa(v)
  24. return "\x1b[>" + pp + ";" + pv + "m"
  25. }
  26. return "\x1b[>" + pp + "m"
  27. }
  28. // XTMODKEYS is an alias for [KeyModifierOptions].
  29. func XTMODKEYS(p int, vs ...int) string {
  30. return KeyModifierOptions(p, vs...)
  31. }
  32. // SetKeyModifierOptions sets xterm key modifier options.
  33. // This is an alias for [KeyModifierOptions].
  34. func SetKeyModifierOptions(pp int, pv int) string {
  35. return KeyModifierOptions(pp, pv)
  36. }
  37. // ResetKeyModifierOptions resets xterm key modifier options.
  38. // This is an alias for [KeyModifierOptions].
  39. func ResetKeyModifierOptions(pp int) string {
  40. return KeyModifierOptions(pp)
  41. }
  42. // QueryKeyModifierOptions (XTQMODKEYS) requests xterm key modifier options.
  43. //
  44. // Default is 0.
  45. //
  46. // CSI ? Pp m
  47. //
  48. // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
  49. func QueryKeyModifierOptions(pp int) string {
  50. var p string
  51. if pp > 0 {
  52. p = strconv.Itoa(pp)
  53. }
  54. return "\x1b[?" + p + "m"
  55. }
  56. // XTQMODKEYS is an alias for [QueryKeyModifierOptions].
  57. func XTQMODKEYS(pp int) string {
  58. return QueryKeyModifierOptions(pp)
  59. }
  60. // Modify Other Keys (modifyOtherKeys) is an xterm feature that allows the
  61. // terminal to modify the behavior of certain keys to send different escape
  62. // sequences when pressed.
  63. //
  64. // See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys
  65. const (
  66. SetModifyOtherKeys1 = "\x1b[>4;1m"
  67. SetModifyOtherKeys2 = "\x1b[>4;2m"
  68. ResetModifyOtherKeys = "\x1b[>4m"
  69. QueryModifyOtherKeys = "\x1b[?4m"
  70. )
  71. // ModifyOtherKeys returns a sequence that sets XTerm modifyOtherKeys mode.
  72. // The mode argument specifies the mode to set.
  73. //
  74. // 0: Disable modifyOtherKeys mode.
  75. // 1: Enable modifyOtherKeys mode 1.
  76. // 2: Enable modifyOtherKeys mode 2.
  77. //
  78. // CSI > 4 ; mode m
  79. //
  80. // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
  81. // See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys
  82. //
  83. // Deprecated: use [SetModifyOtherKeys1] or [SetModifyOtherKeys2] instead.
  84. func ModifyOtherKeys(mode int) string {
  85. return "\x1b[>4;" + strconv.Itoa(mode) + "m"
  86. }
  87. // DisableModifyOtherKeys disables the modifyOtherKeys mode.
  88. //
  89. // CSI > 4 ; 0 m
  90. //
  91. // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
  92. // See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys
  93. //
  94. // Deprecated: use [ResetModifyOtherKeys] instead.
  95. const DisableModifyOtherKeys = "\x1b[>4;0m"
  96. // EnableModifyOtherKeys1 enables the modifyOtherKeys mode 1.
  97. //
  98. // CSI > 4 ; 1 m
  99. //
  100. // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
  101. // See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys
  102. //
  103. // Deprecated: use [SetModifyOtherKeys1] instead.
  104. const EnableModifyOtherKeys1 = "\x1b[>4;1m"
  105. // EnableModifyOtherKeys2 enables the modifyOtherKeys mode 2.
  106. //
  107. // CSI > 4 ; 2 m
  108. //
  109. // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
  110. // See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys
  111. //
  112. // Deprecated: use [SetModifyOtherKeys2] instead.
  113. const EnableModifyOtherKeys2 = "\x1b[>4;2m"
  114. // RequestModifyOtherKeys requests the modifyOtherKeys mode.
  115. //
  116. // CSI ? 4 m
  117. //
  118. // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
  119. // See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys
  120. //
  121. // Deprecated: use [QueryModifyOtherKeys] instead.
  122. const RequestModifyOtherKeys = "\x1b[?4m"