Skip to content

Commit

Permalink
feat(term/ansi): add kitty and ctrl sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Feb 28, 2024
1 parent c9812fb commit bd8a315
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
17 changes: 17 additions & 0 deletions exp/term/ansi/ctrl/ctrl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ctrl

// RequestXTVersion is a control sequence that requests the terminal's XTVERSION. It responds with a DSR sequence identifying the version.
//
// CSI > Ps q
// DCS > | text ST
//
// See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-PC-Style-Function-Keys
const RequestXTVersion = "\x1b[" + ">0q"

// RequestPrimaryDeviceAttributes is a control sequence that requests the
// terminal's primary device attributes (DA1).
//
// CSI c
//
// See https://vt100.net/docs/vt510-rm/DA1.html
const RequestPrimaryDeviceAttributes = "\x1b[" + "c"
51 changes: 51 additions & 0 deletions exp/term/ansi/kitty/kitty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package kitty

import "strconv"

// Kitty keyboard protocol progressive enhancement flags.
// See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement
const (
DisambiguateEscapeCodes = 1 << iota
ReportEventTypes
ReportAlternateKeys
ReportAllKeys
ReportAssociatedKeys

AllFlags = DisambiguateEscapeCodes | ReportEventTypes | ReportAlternateKeys | ReportAllKeys | ReportAssociatedKeys
)

// Request is a sequence to request the terminal Kitty keyboard protocol
// enabled flags.
//
// See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
const Request = "\x1b[?u"

// Push returns a sequence to push the given flags to the terminal Kitty
// Keyboard stack.
//
// CSI > flags u
//
// See https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement
func Push(flags int) string {
var f string
if flags > 0 {
f = strconv.Itoa(flags)
}

return "\x1b" + "[" + ">" + f + "u"
}

// Pop returns a sequence to pop n number of flags from the terminal Kitty
// Keyboard stack.
//
// CSI < flags u
//
// See https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement
func Pop(n int) string {
var num string
if n > 0 {
num = strconv.Itoa(n)
}

return "\x1b" + "[" + "<" + num + "u"
}

0 comments on commit bd8a315

Please sign in to comment.