Much Work

- Definable KeyMaps
- Change 'Tabbable' to just use 'Focusable'
This commit is contained in:
2025-09-04 11:09:34 -05:00
parent c1db729bb3
commit f571b13a31
26 changed files with 881 additions and 615 deletions

View File

@@ -35,11 +35,11 @@ type Cli struct {
id string
style tcell.Style
x, y int
w, h int
active bool
visible bool
tabbable bool
x, y int
w, h int
active bool
visible bool
focusable bool
title string
rawLog []string
@@ -71,7 +71,7 @@ func (w *Cli) Init(id string, s tcell.Style) {
w.id, w.style = id, s
w.visible = true
w.initKeyMap()
w.tabbable = true
w.focusable = true
}
func (w *Cli) Id() string { return w.id }
@@ -79,6 +79,17 @@ func (w *Cli) HandleResize(ev *tcell.EventResize) {
w.w, w.h = ev.Size()
}
func (w *Cli) SetKeyMap(km KeyMap) { w.keyMap = km }
func (w *Cli) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
func (w *Cli) RemoveFromKeyMap(km KeyMap) {
for k := range km.Keys {
w.keyMap.Remove(k)
}
for r := range km.Runes {
w.keyMap.RemoveRune(r)
}
}
func (w *Cli) HandleKey(ev *tcell.EventKey) bool {
if !w.active {
return false
@@ -167,28 +178,27 @@ func (w *Cli) Draw(screen tcell.Screen) {
// x += len(post) - 1
}
func (w *Cli) Active() bool { return w.active }
func (w *Cli) SetActive(a bool) { w.active = a }
func (w *Cli) Visible() bool { return w.visible }
func (w *Cli) SetVisible(a bool) { w.visible = a }
func (w *Cli) Focusable() bool { return true }
func (w *Cli) SetTabbable(b bool) { w.tabbable = b }
func (w *Cli) Tabbable() bool { return w.tabbable }
func (w *Cli) SetX(x int) { w.x = x }
func (w *Cli) SetY(y int) { w.y = y }
func (w *Cli) GetX() int { return w.x }
func (w *Cli) GetY() int { return w.y }
func (w *Cli) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *Cli) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Cli) GetW() int { return w.w }
func (w *Cli) GetH() int { return w.h }
func (w *Cli) SetW(wd int) { w.w = wd }
func (w *Cli) SetH(h int) { w.h = h }
func (w *Cli) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Cli) WantW() int { return wh.MaxInt }
func (w *Cli) WantH() int { return wh.MaxInt }
func (w *Cli) MinW() int { return 20 }
func (w *Cli) MinH() int { return 6 }
func (w *Cli) Active() bool { return w.active }
func (w *Cli) SetActive(a bool) { w.active = a }
func (w *Cli) Visible() bool { return w.visible }
func (w *Cli) SetVisible(a bool) { w.visible = a }
func (w *Cli) Focusable() bool { return true }
func (w *Cli) SetFocusable(b bool) { w.focusable = b }
func (w *Cli) SetX(x int) { w.x = x }
func (w *Cli) SetY(y int) { w.y = y }
func (w *Cli) GetX() int { return w.x }
func (w *Cli) GetY() int { return w.y }
func (w *Cli) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *Cli) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Cli) GetW() int { return w.w }
func (w *Cli) GetH() int { return w.h }
func (w *Cli) SetW(wd int) { w.w = wd }
func (w *Cli) SetH(h int) { w.h = h }
func (w *Cli) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Cli) WantW() int { return wh.MaxInt }
func (w *Cli) WantH() int { return wh.MaxInt }
func (w *Cli) MinW() int { return 20 }
func (w *Cli) MinH() int { return 6 }
func (w *Cli) initKeyMap() {
w.keyMap = NewKeyMap(map[tcell.Key]func(ev *tcell.EventKey) bool{