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

+56
View File
@@ -0,0 +1,56 @@
// License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>
package shortcuts
import (
"fmt"
"github.com/kovidgoyal/kitty/tools/tui/loop"
"strings"
)
var _ = fmt.Print
type ShortcutMap[T comparable] struct {
leaves map[string]T
children map[string]*ShortcutMap[T]
}
func (self *ShortcutMap[T]) ResolveKeyEvent(k *loop.KeyEvent, pending_keys ...string) (ac T, pending string) {
q := self
for _, pk := range pending_keys {
q = self.children[pk]
if q == nil {
return
}
}
for c, ans := range q.leaves {
if k.MatchesPressOrRepeat(c) {
ac = ans
return
}
}
for c := range q.children {
if k.MatchesPressOrRepeat(c) {
pending = c
return
}
}
return
}
func (self *ShortcutMap[T]) Add(ac T, keys ...string) (conflict T) {
return self.add(ac, keys)
}
func (self *ShortcutMap[T]) AddOrPanic(ac T, keys ...string) {
var zero T
c := self.add(ac, keys)
if c != zero {
panic(fmt.Sprintf("The shortcut for %#v (%s) conflicted with the shortcut for %#v (%s)",
ac, strings.Join(keys, " "), c, strings.Join(self.shortcut_for(c), " ")))
}
}
func New[T comparable]() *ShortcutMap[T] {
return &ShortcutMap[T]{leaves: make(map[string]T), children: make(map[string]*ShortcutMap[T])}
}
+64
View File
@@ -0,0 +1,64 @@
// License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>
package shortcuts
import (
"fmt"
)
var _ = fmt.Print
func (self *ShortcutMap[T]) first_action() (ans T) {
for _, ac := range self.leaves {
return ac
}
for _, child := range self.children {
return child.first_action()
}
return
}
func (self *ShortcutMap[T]) shortcut_for(ac T) (keys []string) {
keys = []string{}
for key, q := range self.leaves {
if ac == q {
return append(keys, key)
}
}
for key, child := range self.children {
ckeys := child.shortcut_for(ac)
if len(ckeys) > 0 {
return append(append(keys, key), ckeys...)
}
}
return
}
func (self *ShortcutMap[T]) add(ac T, keys []string) (conflict T) {
sm := self
last := len(keys) - 1
for i, key := range keys {
if i == last {
if c, found := sm.leaves[key]; found {
conflict = c
}
sm.leaves[key] = ac
if c, found := sm.children[key]; found {
conflict = c.first_action()
delete(sm.children, key)
}
} else {
if c, found := sm.leaves[key]; found {
conflict = c
delete(sm.leaves, key)
}
q := sm.children[key]
if q == nil {
q = &ShortcutMap[T]{leaves: map[string]T{}, children: map[string]*ShortcutMap[T]{}}
sm.children[key] = q
}
sm = q
}
}
return
}