add stream to input widget, realtime filtering updates

This commit is contained in:
Bradley Cicenas 2017-03-07 01:47:07 +00:00
parent df8b9fffab
commit 98d8dc62f9
3 changed files with 22 additions and 1 deletions

View File

@ -141,7 +141,6 @@ func Display() bool {
ui.Loop()
if menu != nil {
ui.Clear()
menu()
return false
}

View File

@ -18,6 +18,7 @@ var helpDialog = []menu.Item{
}
func HelpMenu() {
ui.Clear()
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()
@ -43,6 +44,18 @@ func FilterMenu() {
i.BorderFg = ui.ColorCyan
i.SetY(ui.TermHeight() - i.Height)
ui.Render(i)
// refresh container rows on input
stream := i.Stream()
go func() {
for s := range stream {
config.Update("filterStr", s)
cursor.RefreshContainers()
RedrawRows()
ui.Render(i)
}
}()
i.InputHandlers()
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
config.Update("filterStr", i.Data)
@ -52,6 +65,7 @@ func FilterMenu() {
}
func SortMenu() {
ui.Clear()
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()

View File

@ -19,6 +19,7 @@ type Input struct {
MaxLen int
TextFgColor ui.Attribute
TextBgColor ui.Attribute
stream chan string // stream text as it changes
padding Padding
}
@ -55,12 +56,18 @@ func (i *Input) Buffer() ui.Buffer {
return buf
}
func (i *Input) Stream() chan string {
i.stream = make(chan string)
return i.stream
}
func (i *Input) KeyPress(e ui.Event) {
ch := strings.Replace(e.Path, "/sys/kbd/", "", -1)
if ch == "C-8" {
idx := len(i.Data) - 1
if idx > -1 {
i.Data = i.Data[0:idx]
i.stream <- i.Data
}
ui.Render(i)
return
@ -70,6 +77,7 @@ func (i *Input) KeyPress(e ui.Event) {
}
if strings.Index(input_chars, ch) > -1 {
i.Data += ch
i.stream <- i.Data
ui.Render(i)
}
}