chore: import official kitty sources from upstream

Bring the kovidgoyal/kitty codebase in as the base of FWS-Kitty, vendored at upstream commit 91fb38a without its git history.
This commit is contained in:
BlackAngelTV committed 2026-11-04 11:35:59 +01:00
commit 3d174c45a4
1134 files changed
+433629

No files matched your search

View File
Whitespace-only changes.
+85
View File
@@ -0,0 +1,85 @@
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
package show_key
import (
"fmt"
"strings"
"github.com/kovidgoyal/kitty/tools/cli/markup"
"github.com/kovidgoyal/kitty/tools/tui/loop"
)
var _ = fmt.Print
func csi(csi string) string {
return "CSI " + strings.NewReplacer(":", " : ", ";", " ; ").Replace(csi[:len(csi)-1]) + " " + csi[len(csi)-1:]
}
func run_kitty_loop(_ *Options) (err error) {
lp, err := loop.New(loop.FullKeyboardProtocol)
if err != nil {
return err
}
ctx := markup.New(true)
lp.OnInitialize = func() (string, error) {
lp.SetCursorVisible(false)
lp.SetWindowTitle("kitty extended keyboard protocol demo")
lp.Println("Press any keys - Ctrl+C or Ctrl+D will terminate")
return "", nil
}
lp.OnKeyEvent = func(e *loop.KeyEvent) (err error) {
e.Handled = true
if e.MatchesPressOrRepeat("ctrl+c") || e.MatchesPressOrRepeat("ctrl+d") {
lp.Quit(0)
return
}
mods := e.Mods.String()
if mods != "" {
mods += "+"
}
etype := e.Type.String()
key := e.Key
if key == " " {
key = "space"
}
key = mods + key
lp.Printf("%s %s %s\r\n", ctx.Green(key), ctx.Yellow(etype), e.Text)
lp.Println(ctx.Cyan(csi(e.CSI)))
if e.AlternateKey != "" || e.ShiftedKey != "" {
if e.ShiftedKey != "" {
lp.QueueWriteString(ctx.Dim("Shifted key: "))
lp.QueueWriteString(e.ShiftedKey + " ")
}
if e.AlternateKey != "" {
lp.QueueWriteString(ctx.Dim("Alternate key: "))
lp.QueueWriteString(e.AlternateKey + " ")
}
lp.Println()
}
lp.Println()
return
}
lp.OnText = func(text string, from_key_event bool, in_bracketed_paste bool) error {
if from_key_event {
return nil
}
lp.Printf("%s: %s\n\n", ctx.Green("Text"), text)
return nil
}
err = lp.Run()
if err != nil {
return
}
ds := lp.DeathSignalName()
if ds != "" {
fmt.Println("Killed by signal: ", ds)
lp.KillIfSignalled()
return
}
return
}
+83
View File
@@ -0,0 +1,83 @@
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
package show_key
import (
"errors"
"fmt"
"github.com/kovidgoyal/kitty/tools/cli/markup"
"github.com/kovidgoyal/kitty/tools/tty"
"io"
"os"
"strings"
"golang.org/x/sys/unix"
)
var _ = fmt.Print
func print_key(buf []byte, ctx *markup.Context) {
const ctrl_keys = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
var unix strings.Builder
var send_text strings.Builder
for _, ch := range buf {
switch {
case int(ch) < len(ctrl_keys):
unix.WriteString("^" + ctrl_keys[ch:ch+1])
case ch == 127:
unix.WriteString("^?")
default:
unix.WriteString(string(rune(ch)))
}
}
for _, ch := range string(buf) {
q := fmt.Sprintf("%#v", string(ch))
send_text.WriteString(q[1 : len(q)-1])
}
os.Stdout.WriteString(unix.String() + "\t\t")
os.Stdout.WriteString(ctx.Yellow(send_text.String()) + "\r\n")
}
func run_legacy_loop(opts *Options) (err error) {
term, err := tty.OpenControllingTerm(tty.SetRaw)
if err != nil {
return err
}
defer func() {
term.RestoreAndClose()
}()
if opts.KeyMode != "unchanged" {
os.Stdout.WriteString("\x1b[?1")
switch opts.KeyMode {
case "normal":
os.Stdout.WriteString("l")
default:
os.Stdout.WriteString("h")
}
defer func() {
os.Stdout.WriteString("\x1b[?1l")
}()
}
fmt.Print("Press any keys - Ctrl+D will terminate this program\r\n")
ctx := markup.New(true)
fmt.Print(ctx.Green("UNIX\t\tsend_text\r\n"))
buf := make([]byte, 64)
for {
n, err := term.Read(buf)
if err != nil {
if errors.Is(err, io.EOF) {
break
}
if !(errors.Is(err, unix.EAGAIN) || errors.Is(err, unix.EBUSY)) {
return err
}
}
if n > 0 {
print_key(buf[:n], ctx)
if n == 1 && buf[0] == 4 {
break
}
}
}
return
}
+27
View File
@@ -0,0 +1,27 @@
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
package show_key
import (
"fmt"
"github.com/kovidgoyal/kitty/tools/cli"
)
var _ = fmt.Print
func main(cmd *cli.Command, opts *Options, args []string) (rc int, err error) {
if opts.KeyMode == "kitty" {
err = run_kitty_loop(opts)
} else {
err = run_legacy_loop(opts)
}
if err != nil {
rc = 1
}
return
}
func EntryPoint(parent *cli.Command) {
create_cmd(parent, main)
}
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env python
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
import sys
OPTIONS = r"""
--key-mode -m
default=normal
type=choices
choices=normal,application,kitty,unchanged
The keyboard mode to use when showing keys. :code:`normal` mode is with DECCKM
reset and :code:`application` mode is with DECCKM set. :code:`kitty` is the full
kitty extended keyboard protocol.
""".format
help_text = 'Show the codes generated by the terminal for key presses in various keyboard modes'
usage = ''
def main(args: list[str]) -> None:
raise SystemExit('This should be run as kitten show_key')
if __name__ == '__main__':
main(sys.argv)
elif __name__ == '__doc__':
cd = sys.cli_docs # type: ignore
cd['usage'] = usage
cd['options'] = OPTIONS
cd['help_text'] = help_text
cd['short_desc'] = help_text