40 lines
816 B
Go
40 lines
816 B
Go
package ui
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"git.sr.ht/~rockorager/vaxis"
|
|
"git.sr.ht/~rockorager/vaxis/widgets/textinput"
|
|
)
|
|
|
|
type Input struct {
|
|
model textinput.Model
|
|
AutoComplete []string
|
|
Placeholder string
|
|
}
|
|
|
|
func (m *Input) Draw(win vaxis.Window) {
|
|
// figure out which thing to complete
|
|
rest := ""
|
|
if m.model.String() != "" {
|
|
for _, comp := range m.AutoComplete {
|
|
if strings.HasPrefix(comp, m.model.String()) {
|
|
rest = comp[len(m.model.String()):]
|
|
break
|
|
}
|
|
}
|
|
} else {
|
|
rest = m.Placeholder
|
|
}
|
|
m.model.Draw(win)
|
|
win.New(len(m.model.String()), 0, win.Width, win.Height).Print(vaxis.Segment{Text: rest, Style: vaxis.Style{Foreground: vaxis.IndexColor(8)}})
|
|
}
|
|
|
|
func (m *Input) Update(event vaxis.Event) {
|
|
m.model.Update(event)
|
|
}
|
|
|
|
func (m *Input) String() string {
|
|
return m.model.String()
|
|
}
|