Some Updates

This commit is contained in:
2025-10-02 12:12:52 -05:00
parent 998531f95d
commit 4b647d9d41
9 changed files with 150 additions and 24 deletions

View File

@@ -42,7 +42,7 @@ type Field struct {
x, y int
w, h int
filter func(*tcell.EventKey) bool
filter func(tcell.EventKey) bool
onChange func(prev, curr string)
keyMap KeyMap
@@ -60,9 +60,9 @@ func (w *Field) Init(id string, style tcell.Style) {
w.id = id
w.style = style
w.visible = true
w.filter = func(ev *tcell.EventKey) bool {
return wh.IsBS(*ev) ||
wh.KeyIsDisplayable(*ev)
w.filter = func(ev tcell.EventKey) bool {
return wh.IsBS(ev) ||
wh.KeyIsDisplayable(ev)
}
w.keyMap = NewKeyMap(map[tcell.Key]func(ev *tcell.EventKey) bool{
tcell.KeyLeft: w.handleLeft,
@@ -98,7 +98,7 @@ func (w *Field) HandleKey(ev *tcell.EventKey) bool {
if ok := w.keyMap.Handle(ev); ok {
return true
}
if w.filter != nil && !w.filter(ev) {
if w.filter != nil && !w.filter(*ev) {
return false
}
if ev.Key() == tcell.KeyRune {
@@ -238,3 +238,17 @@ func (w *Field) doOnChange(prev, curr string) {
w.onChange(prev, curr)
}
}
func (w *Field) SetFilter(f func(ev tcell.EventKey) bool) {
w.filter = func(ev tcell.EventKey) bool {
// We always want to make sure we allow backspace.
if wh.IsBS(ev) {
return true
}
// We also always want to make sure it's displayable
if !wh.KeyIsDisplayable(ev) {
return false
}
return f(ev)
}
}