| 1 |
package input |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/charmbracelet/x/ansi" |
| 5 |
) |
| 6 |
|
| 7 |
func parseXTermModifyOtherKeys(params ansi.Params) Event { |
| 8 |
// XTerm modify other keys starts with ESC [ 27 ; <modifier> ; <code> ~ |
| 9 |
xmod, _, _ := params.Param(1, 1) |
| 10 |
xrune, _, _ := params.Param(2, 1) |
| 11 |
mod := KeyMod(xmod - 1) |
| 12 |
r := rune(xrune) |
| 13 |
|
| 14 |
switch r { |
| 15 |
case ansi.BS: |
| 16 |
return KeyPressEvent{Mod: mod, Code: KeyBackspace} |
| 17 |
case ansi.HT: |
| 18 |
return KeyPressEvent{Mod: mod, Code: KeyTab} |
| 19 |
case ansi.CR: |
| 20 |
return KeyPressEvent{Mod: mod, Code: KeyEnter} |
| 21 |
case ansi.ESC: |
| 22 |
return KeyPressEvent{Mod: mod, Code: KeyEscape} |
| 23 |
case ansi.DEL: |
| 24 |
return KeyPressEvent{Mod: mod, Code: KeyBackspace} |
| 25 |
} |
| 26 |
|
| 27 |
// CSI 27 ; <modifier> ; <code> ~ keys defined in XTerm modifyOtherKeys |
| 28 |
k := KeyPressEvent{Code: r, Mod: mod} |
| 29 |
if k.Mod <= ModShift { |
| 30 |
k.Text = string(r) |
| 31 |
} |
| 32 |
|
| 33 |
return k |
| 34 |
} |
| 35 |
|
| 36 |
// TerminalVersionEvent is a message that represents the terminal version. |
| 37 |
type TerminalVersionEvent string |
| 38 |
|
| 39 |
// ModifyOtherKeysEvent represents a modifyOtherKeys event. |
| 40 |
// |
| 41 |
// 0: disable |
| 42 |
// 1: enable mode 1 |
| 43 |
// 2: enable mode 2 |
| 44 |
// |
| 45 |
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ |
| 46 |
// See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys |
| 47 |
type ModifyOtherKeysEvent uint8 |