kitty.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package ansi
  2. import "strconv"
  3. // Kitty keyboard protocol progressive enhancement flags.
  4. // See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement
  5. const (
  6. KittyDisambiguateEscapeCodes = 1 << iota
  7. KittyReportEventTypes
  8. KittyReportAlternateKeys
  9. KittyReportAllKeys
  10. KittyReportAssociatedKeys
  11. KittyAllFlags = KittyDisambiguateEscapeCodes | KittyReportEventTypes |
  12. KittyReportAlternateKeys | KittyReportAllKeys | KittyReportAssociatedKeys
  13. )
  14. // RequestKittyKeyboard is a sequence to request the terminal Kitty keyboard
  15. // protocol enabled flags.
  16. //
  17. // See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
  18. const RequestKittyKeyboard = "\x1b[?u"
  19. // PushKittyKeyboard returns a sequence to push the given flags to the terminal
  20. // Kitty Keyboard stack.
  21. //
  22. // CSI > flags u
  23. //
  24. // See https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement
  25. func PushKittyKeyboard(flags int) string {
  26. var f string
  27. if flags > 0 {
  28. f = strconv.Itoa(flags)
  29. }
  30. return "\x1b[>" + f + "u"
  31. }
  32. // DisableKittyKeyboard is a sequence to push zero into the terminal Kitty
  33. // Keyboard stack to disable the protocol.
  34. //
  35. // This is equivalent to PushKittyKeyboard(0).
  36. const DisableKittyKeyboard = "\x1b[>0u"
  37. // PopKittyKeyboard returns a sequence to pop n number of flags from the
  38. // terminal Kitty Keyboard stack.
  39. //
  40. // CSI < flags u
  41. //
  42. // See https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement
  43. func PopKittyKeyboard(n int) string {
  44. var num string
  45. if n > 0 {
  46. num = strconv.Itoa(n)
  47. }
  48. return "\x1b[<" + num + "u"
  49. }