Skip to content

Commit

Permalink
add stream to input widget, realtime filtering updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bcicen committed Mar 7, 2017
1 parent df8b9ff commit 98d8dc6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 0 additions & 1 deletion grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func Display() bool {

ui.Loop()
if menu != nil {
ui.Clear()
menu()
return false
}
Expand Down
14 changes: 14 additions & 0 deletions menus.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var helpDialog = []menu.Item{
}

func HelpMenu() {
ui.Clear()
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()

Expand All @@ -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)
Expand All @@ -52,6 +65,7 @@ func FilterMenu() {
}

func SortMenu() {
ui.Clear()
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()

Expand Down
8 changes: 8 additions & 0 deletions widgets/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 98d8dc6

Please sign in to comment.