show_key kitten: In kitty mode show the actual bytes sent by the terminal rather than a re-encoding of the parsed key event

Also port the kitten to Go
This commit is contained in:
Kovid Goyal
2023-04-26 21:48:53 +05:30
parent 7b6d11fd1e
commit 019359b219
9 changed files with 215 additions and 140 deletions

View File

@@ -11,6 +11,7 @@ import (
"kitty/kittens/hints"
"kitty/kittens/hyperlinked_grep"
"kitty/kittens/icat"
"kitty/kittens/show_key"
"kitty/kittens/ssh"
"kitty/kittens/themes"
"kitty/kittens/unicode_input"
@@ -41,6 +42,8 @@ func KittyToolEntryPoints(root *cli.Command) {
ssh.EntryPoint(root)
// unicode_input
unicode_input.EntryPoint(root)
// show_key
show_key.EntryPoint(root)
// hyperlinked_grep
hyperlinked_grep.EntryPoint(root)
// ask

View File

@@ -105,6 +105,9 @@ type KeyEvent struct {
AlternateKey string
Text string
Handled bool
// The CSI string this key event was decoded from. Empty if not decoded from CSI.
CSI string
}
func (self *KeyEvent) String() string {
@@ -133,6 +136,7 @@ func KeyEventFromCSI(csi string) *KeyEvent {
if len(csi) == 0 {
return nil
}
orig_csi := csi
last_char := csi[len(csi)-1:]
if !strings.Contains("u~ABCDEHFPQRS", last_char) || (last_char == "~" && (csi == "200~" || csi == "201~")) {
return nil
@@ -165,7 +169,7 @@ func KeyEventFromCSI(csi string) *KeyEvent {
if len(sections) > 2 {
third_section = get_sub_sections(sections[2], 0)
}
var ans = KeyEvent{Type: PRESS}
var ans = KeyEvent{Type: PRESS, CSI: orig_csi}
var keynum int
if val, ok := letter_trailer_to_csi_number_map[last_char]; ok {
keynum = val