-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(term/ansi): add kitty and ctrl sequences
- Loading branch information
1 parent
c9812fb
commit bd8a315
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |