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