Some work

This commit is contained in:
2025-10-03 13:35:05 -05:00
parent 4b647d9d41
commit f1e705bba5
4 changed files with 41 additions and 12 deletions

View File

@@ -83,13 +83,14 @@ func (w *BorderedWidget) Draw(screen tcell.Screen) {
if !w.widget.Visible() {
return
}
st := w.style.Dim(!w.Active())
if len(w.title) > 0 {
wh.TitledBorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, w.title, w.border, w.style, screen)
wh.TitledBorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, w.title, w.border, st, screen)
} else {
wh.BorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, w.border, w.style, screen)
wh.BorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, w.border, st, screen)
}
if len(w.help) > 0 {
wh.DrawText(w.x+w.w-len(w.help)-2, w.y+w.h, w.help, w.style, screen)
wh.DrawText(w.x+w.w-len(w.help)-2, w.y+w.h, w.help, st, screen)
}
w.GetPos().DrawOffset(w.widget, screen)
}

View File

@@ -67,6 +67,7 @@ func (w *DatePicker) Init(id string, s tcell.Style) {
w.format = time.RFC3339
w.dateFld = NewField(fmt.Sprintf("%s-date", id), s)
w.dateFld.SetOverwrite(true)
w.dateFld.SetValue(w.date.Format(w.format))
w.dateFld.SetH(1)

View File

@@ -35,6 +35,8 @@ type Field struct {
label string
value string
overwriteMode bool
cursor int
visible bool
active bool
@@ -93,6 +95,10 @@ func (w *Field) HandleKey(ev *tcell.EventKey) bool {
return false
}
if wh.IsBS(*ev) {
if w.overwriteMode {
w.cursor--
return true
}
return w.handleBackspace(ev)
}
if ok := w.keyMap.Handle(ev); ok {
@@ -102,7 +108,16 @@ func (w *Field) HandleKey(ev *tcell.EventKey) bool {
return false
}
if ev.Key() == tcell.KeyRune {
w.SetValue(fmt.Sprintf("%s%s%s", w.value[:w.cursor], string(ev.Rune()), w.value[w.cursor:]))
var val string
if w.overwriteMode {
val = fmt.Sprintf("%s%s", w.value[:w.cursor], string(ev.Rune()))
if len(w.value) > w.cursor+1 {
val = fmt.Sprintf("%s%s", val, w.value[w.cursor+1:])
}
} else {
val = fmt.Sprintf("%s%s%s", w.value[:w.cursor], string(ev.Rune()), w.value[w.cursor:])
}
w.SetValue(val)
w.cursor++
return true
}
@@ -252,3 +267,4 @@ func (w *Field) SetFilter(f func(ev tcell.EventKey) bool) {
return f(ev)
}
}
func (w *Field) SetOverwrite(b bool) { w.overwriteMode = b }

View File

@@ -68,8 +68,20 @@ func (w *TopMenuLayout) Init(id string, s tcell.Style) {
w.menu.SetType(MenuTypeH)
w.widget = NewBlankWidget("blank")
w.keyMap = BlankKeyMap()
w.keyMap.Add(tcell.KeyEscape, func(ev *tcell.EventKey) bool {
w.keyMap = NewKeyMap(map[tcell.Key]func(ev *tcell.EventKey) bool{
tcell.KeyEscape: func(ev *tcell.EventKey) bool {
return w.ToggleMenu()
},
})
w.keyMap.AddRune(' ', func(ev *tcell.EventKey) bool {
if ev.Modifiers()&tcell.ModAlt != 0 {
return w.ToggleMenu()
}
return false
})
}
func (w *TopMenuLayout) ToggleMenu() bool {
if w.menu != nil {
w.menu.SetActive(!w.menu.Active())
if w.widget != nil {
@@ -78,7 +90,6 @@ func (w *TopMenuLayout) Init(id string, s tcell.Style) {
return true
}
return false
})
}
func (w *TopMenuLayout) Id() string { return w.id }