2017-01-04 23:13:17 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-02-07 03:33:09 +00:00
|
|
|
"github.com/bcicen/ctop/config"
|
2017-01-04 23:13:17 +00:00
|
|
|
"github.com/bcicen/ctop/widgets"
|
2017-02-15 07:40:16 +00:00
|
|
|
"github.com/bcicen/ctop/widgets/menu"
|
2017-01-04 23:13:17 +00:00
|
|
|
ui "github.com/gizak/termui"
|
|
|
|
)
|
|
|
|
|
2017-02-15 07:40:16 +00:00
|
|
|
var helpDialog = []menu.Item{
|
2017-03-07 00:09:46 +00:00
|
|
|
menu.Item{"[a] - toggle display of all containers", ""},
|
|
|
|
menu.Item{"[f] - filter displayed containers", ""},
|
2017-02-15 07:40:16 +00:00
|
|
|
menu.Item{"[h] - open this help dialog", ""},
|
2017-03-08 23:40:35 +00:00
|
|
|
menu.Item{"[H] - toggle ctop header", ""},
|
2017-02-15 07:40:16 +00:00
|
|
|
menu.Item{"[s] - select container sort field", ""},
|
|
|
|
menu.Item{"[r] - reverse container sort order", ""},
|
|
|
|
menu.Item{"[q] - exit ctop", ""},
|
2017-01-04 23:13:17 +00:00
|
|
|
}
|
|
|
|
|
2017-01-08 23:07:58 +00:00
|
|
|
func HelpMenu() {
|
2017-03-07 01:47:07 +00:00
|
|
|
ui.Clear()
|
2017-02-18 03:37:00 +00:00
|
|
|
ui.DefaultEvtStream.ResetHandlers()
|
|
|
|
defer ui.DefaultEvtStream.ResetHandlers()
|
2017-02-13 03:22:32 +00:00
|
|
|
|
2017-02-15 07:40:16 +00:00
|
|
|
m := menu.NewMenu()
|
2017-01-04 23:13:17 +00:00
|
|
|
m.BorderLabel = "Help"
|
2017-02-15 07:40:16 +00:00
|
|
|
m.AddItems(helpDialog...)
|
2017-01-04 23:13:17 +00:00
|
|
|
ui.Render(m)
|
|
|
|
ui.Handle("/sys/kbd/", func(ui.Event) {
|
|
|
|
ui.StopLoop()
|
|
|
|
})
|
|
|
|
ui.Loop()
|
|
|
|
}
|
|
|
|
|
2017-01-21 18:15:29 +00:00
|
|
|
func FilterMenu() {
|
2017-02-13 03:22:32 +00:00
|
|
|
ui.DefaultEvtStream.ResetHandlers()
|
2017-02-18 03:37:00 +00:00
|
|
|
defer ui.DefaultEvtStream.ResetHandlers()
|
2017-02-13 03:22:32 +00:00
|
|
|
|
2017-01-21 18:15:29 +00:00
|
|
|
i := widgets.NewInput()
|
|
|
|
i.BorderLabel = "Filter"
|
2017-02-13 03:22:32 +00:00
|
|
|
i.SetY(ui.TermHeight() - i.Height)
|
2017-01-21 18:15:29 +00:00
|
|
|
ui.Render(i)
|
2017-03-07 01:47:07 +00:00
|
|
|
|
|
|
|
// refresh container rows on input
|
|
|
|
stream := i.Stream()
|
|
|
|
go func() {
|
|
|
|
for s := range stream {
|
|
|
|
config.Update("filterStr", s)
|
2017-03-08 00:10:38 +00:00
|
|
|
RefreshDisplay()
|
2017-03-07 01:47:07 +00:00
|
|
|
ui.Render(i)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2017-01-21 18:15:29 +00:00
|
|
|
i.InputHandlers()
|
|
|
|
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
|
2017-02-07 03:33:09 +00:00
|
|
|
config.Update("filterStr", i.Data)
|
2017-01-21 18:15:29 +00:00
|
|
|
ui.StopLoop()
|
|
|
|
})
|
|
|
|
ui.Loop()
|
|
|
|
}
|
|
|
|
|
2017-01-08 23:07:58 +00:00
|
|
|
func SortMenu() {
|
2017-03-07 01:47:07 +00:00
|
|
|
ui.Clear()
|
2017-02-18 03:37:00 +00:00
|
|
|
ui.DefaultEvtStream.ResetHandlers()
|
|
|
|
defer ui.DefaultEvtStream.ResetHandlers()
|
2017-02-13 03:22:32 +00:00
|
|
|
|
2017-02-15 07:40:16 +00:00
|
|
|
m := menu.NewMenu()
|
2017-01-04 23:13:17 +00:00
|
|
|
m.Selectable = true
|
2017-02-15 06:01:35 +00:00
|
|
|
m.SortItems = true
|
2017-01-04 23:13:17 +00:00
|
|
|
m.BorderLabel = "Sort Field"
|
2017-01-09 15:02:34 +00:00
|
|
|
|
2017-02-15 07:40:16 +00:00
|
|
|
for _, field := range SortFields() {
|
|
|
|
m.AddItems(menu.Item{field, ""})
|
|
|
|
}
|
2017-02-15 06:01:35 +00:00
|
|
|
|
2017-01-09 15:02:34 +00:00
|
|
|
// set cursor position to current sort field
|
2017-02-19 03:54:24 +00:00
|
|
|
m.SetCursor(config.GetVal("sortField"))
|
2017-01-09 15:02:34 +00:00
|
|
|
|
2017-01-04 23:13:17 +00:00
|
|
|
ui.Render(m)
|
|
|
|
m.NavigationHandlers()
|
|
|
|
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
|
2017-02-15 07:40:16 +00:00
|
|
|
config.Update("sortField", m.SelectedItem().Val)
|
2017-01-04 23:13:17 +00:00
|
|
|
ui.StopLoop()
|
|
|
|
})
|
|
|
|
ui.Loop()
|
|
|
|
}
|