xterm.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package input
  2. import (
  3. "github.com/charmbracelet/x/ansi"
  4. )
  5. func parseXTermModifyOtherKeys(csi *ansi.CsiSequence) Event {
  6. // XTerm modify other keys starts with ESC [ 27 ; <modifier> ; <code> ~
  7. mod := KeyMod(csi.Param(1) - 1)
  8. r := rune(csi.Param(2))
  9. switch r {
  10. case ansi.BS:
  11. return KeyPressEvent{Mod: mod, Sym: KeyBackspace}
  12. case ansi.HT:
  13. return KeyPressEvent{Mod: mod, Sym: KeyTab}
  14. case ansi.CR:
  15. return KeyPressEvent{Mod: mod, Sym: KeyEnter}
  16. case ansi.ESC:
  17. return KeyPressEvent{Mod: mod, Sym: KeyEscape}
  18. case ansi.DEL:
  19. return KeyPressEvent{Mod: mod, Sym: KeyBackspace}
  20. }
  21. // CSI 27 ; <modifier> ; <code> ~ keys defined in XTerm modifyOtherKeys
  22. return KeyPressEvent{
  23. Mod: mod,
  24. Rune: r,
  25. }
  26. }
  27. // ModifyOtherKeysEvent represents a modifyOtherKeys event.
  28. //
  29. // 0: disable
  30. // 1: enable mode 1
  31. // 2: enable mode 2
  32. //
  33. // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
  34. // See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys
  35. type ModifyOtherKeysEvent uint8