mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
add stream to input widget, realtime filtering updates
This commit is contained in:
parent
df8b9fffab
commit
98d8dc62f9
1
grid.go
1
grid.go
@ -141,7 +141,6 @@ func Display() bool {
|
||||
|
||||
ui.Loop()
|
||||
if menu != nil {
|
||||
ui.Clear()
|
||||
menu()
|
||||
return false
|
||||
}
|
||||
|
14
menus.go
14
menus.go
@ -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()
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user