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

@@ -34,11 +34,11 @@ type Chat 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
@@ -66,14 +66,23 @@ func (w *Chat) 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 *Chat) Id() string { return w.id }
func (w *Chat) HandleResize(ev *tcell.EventResize) {
w.w, w.h = ev.Size()
// w.w = wh.Min(w.w, w.WantW())
// w.h = wh.Min(w.h, w.WantH())
}
func (w *Chat) SetKeyMap(km KeyMap) { w.keyMap = km }
func (w *Chat) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
func (w *Chat) RemoveFromKeyMap(km KeyMap) {
for k := range km.Keys {
w.keyMap.Remove(k)
}
for r := range km.Runes {
w.keyMap.RemoveRune(r)
}
}
func (w *Chat) HandleKey(ev *tcell.EventKey) bool {
@@ -157,28 +166,27 @@ func (w *Chat) Draw(screen tcell.Screen) {
// x += len(post) - 1
}
func (w *Chat) Active() bool { return w.active }
func (w *Chat) SetActive(a bool) { w.active = a }
func (w *Chat) Visible() bool { return w.visible }
func (w *Chat) SetVisible(a bool) { w.visible = a }
func (w *Chat) Focusable() bool { return true }
func (w *Chat) SetTabbable(b bool) { w.tabbable = b }
func (w *Chat) Tabbable() bool { return w.tabbable }
func (w *Chat) SetX(x int) { w.x = x }
func (w *Chat) SetY(y int) { w.y = y }
func (w *Chat) GetX() int { return w.x }
func (w *Chat) GetY() int { return w.y }
func (w *Chat) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *Chat) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Chat) GetW() int { return w.w }
func (w *Chat) GetH() int { return w.h }
func (w *Chat) SetW(wd int) { w.w = wd }
func (w *Chat) SetH(h int) { w.h = h }
func (w *Chat) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Chat) WantW() int { return wh.MaxInt }
func (w *Chat) WantH() int { return wh.MaxInt }
func (w *Chat) MinW() int { return 2 + 20 }
func (w *Chat) MinH() int { return 6 }
func (w *Chat) Active() bool { return w.active }
func (w *Chat) SetActive(a bool) { w.active = a }
func (w *Chat) Visible() bool { return w.visible }
func (w *Chat) SetVisible(a bool) { w.visible = a }
func (w *Chat) Focusable() bool { return w.focusable }
func (w *Chat) SetFocusable(b bool) { w.focusable = b }
func (w *Chat) SetX(x int) { w.x = x }
func (w *Chat) SetY(y int) { w.y = y }
func (w *Chat) GetX() int { return w.x }
func (w *Chat) GetY() int { return w.y }
func (w *Chat) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *Chat) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Chat) GetW() int { return w.w }
func (w *Chat) GetH() int { return w.h }
func (w *Chat) SetW(wd int) { w.w = wd }
func (w *Chat) SetH(h int) { w.h = h }
func (w *Chat) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Chat) WantW() int { return wh.MaxInt }
func (w *Chat) WantH() int { return wh.MaxInt }
func (w *Chat) MinW() int { return 2 + 20 }
func (w *Chat) MinH() int { return 6 }
func (w *Chat) initKeyMap() {
w.keyMap = NewKeyMap(map[tcell.Key]func(ev *tcell.EventKey) bool{