Really figuring some things out

This commit is contained in:
2025-08-07 11:18:03 -05:00
parent 7c96fbb187
commit b476c74683
23 changed files with 737 additions and 249 deletions

View File

@@ -25,7 +25,7 @@ import (
"fmt"
"strings"
h "git.bullercodeworks.com/brian/tcell-widgets/helpers"
wh "git.bullercodeworks.com/brian/tcell-widgets/helpers"
"github.com/gdamore/tcell"
)
@@ -47,7 +47,7 @@ type Searcher struct {
selectFunc func(idx int, s string) bool
hideOnSelect bool
logger func(string)
logger func(string, ...any)
keyMap KeyMap
}
@@ -81,8 +81,16 @@ func (w *Searcher) Init(id string, style tcell.Style) {
w.tabbable = true
}
func (w *Searcher) Id() string { return w.id }
func (w *Searcher) HandleResize(ev *tcell.EventResize) {}
func (w *Searcher) Id() string { return w.id }
func (w *Searcher) 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())
// TODO: Verify this is fine:
w.search.HandleResize(ev)
}
func (w *Searcher) HandleKey(ev *tcell.EventKey) bool {
if !w.active {
return false
@@ -172,9 +180,9 @@ func (w *Searcher) Draw(screen tcell.Screen) {
dStyle = dStyle.Dim(true)
}
if len(w.title) > 0 {
h.TitledBorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, w.title, h.BRD_CSIMPLE, dStyle, screen)
wh.TitledBorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, w.title, wh.BRD_CSIMPLE, dStyle, screen)
} else {
h.BorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, h.BRD_CSIMPLE, dStyle, screen)
wh.BorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, wh.BRD_CSIMPLE, dStyle, screen)
}
w.search.DrawOffset(w.GetPos(), screen)
x, y := w.x+1, w.y+2
@@ -186,13 +194,13 @@ func (w *Searcher) Draw(screen tcell.Screen) {
if w.cursor+w.h/2 > fD {
stIdx = fD - w.h/2
}
stIdx = h.Max(stIdx, 0)
stIdx = wh.Max(stIdx, 0)
for i := stIdx; i < fD; i++ {
st := dStyle
if i == w.cursor {
st = st.Reverse(true)
}
h.DrawText(x, y, w.filteredData[i], st, screen)
wh.DrawText(x, y, w.filteredData[i], st, screen)
y++
if y >= w.y+w.h {
break
@@ -222,7 +230,7 @@ func (w *Searcher) WantW() int {
ret := 2 + w.search.WantW()
var maxData int
for i := range w.filteredData {
maxData = h.Max(maxData, len(w.filteredData[i]))
maxData = wh.Max(maxData, len(w.filteredData[i]))
}
return ret + maxData
}
@@ -258,7 +266,7 @@ func (w *Searcher) SetData(data []string) {
func (w *Searcher) updateFilter() {
var selVal string
var data []string
data := []string{}
copy(data, w.filteredData)
if len(data) > 0 && len(data) > w.cursor {
selVal = data[w.cursor]
@@ -308,9 +316,9 @@ func (w *Searcher) ClearSearch() {
w.search.SetValue("")
}
func (w *Searcher) SetLogger(l func(string)) { w.logger = l }
func (w *Searcher) Log(txt string) {
func (w *Searcher) SetLogger(l func(string, ...any)) { w.logger = l }
func (w *Searcher) Log(txt string, args ...any) {
if w.logger != nil {
w.logger(txt)
w.logger(txt, args)
}
}