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"
|
|
|
|
ui "github.com/gizak/termui"
|
|
|
|
)
|
|
|
|
|
|
|
|
var helpDialog = []string{
|
|
|
|
"[h] - open this help dialog",
|
2017-01-06 11:53:30 +00:00
|
|
|
"[s] - select container sort field",
|
2017-01-12 19:48:29 +00:00
|
|
|
"[r] - reverse container sort order",
|
2017-01-04 23:13:17 +00:00
|
|
|
"[q] - exit ctop",
|
|
|
|
}
|
|
|
|
|
2017-01-08 23:07:58 +00:00
|
|
|
func HelpMenu() {
|
2017-02-13 03:22:32 +00:00
|
|
|
ResetView()
|
|
|
|
defer ResetView()
|
|
|
|
|
2017-02-15 06:01:35 +00:00
|
|
|
m := widgets.NewMenu()
|
2017-01-04 23:13:17 +00:00
|
|
|
m.TextFgColor = ui.ColorWhite
|
|
|
|
m.BorderLabel = "Help"
|
|
|
|
m.BorderFg = ui.ColorCyan
|
2017-02-15 06:01:35 +00:00
|
|
|
m.AddItems(widgets.NewMenuItems(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()
|
|
|
|
defer ResetView()
|
|
|
|
|
2017-01-21 18:15:29 +00:00
|
|
|
i := widgets.NewInput()
|
|
|
|
i.TextFgColor = ui.ColorWhite
|
|
|
|
i.BorderLabel = "Filter"
|
|
|
|
i.BorderFg = ui.ColorCyan
|
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)
|
|
|
|
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-02-13 03:22:32 +00:00
|
|
|
ResetView()
|
|
|
|
defer ResetView()
|
|
|
|
|
2017-02-15 06:01:35 +00:00
|
|
|
m := widgets.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.TextFgColor = ui.ColorWhite
|
|
|
|
m.BorderLabel = "Sort Field"
|
|
|
|
m.BorderFg = ui.ColorCyan
|
2017-01-09 15:02:34 +00:00
|
|
|
|
2017-02-15 06:01:35 +00:00
|
|
|
m.AddItems(widgets.NewMenuItems(SortFields())...)
|
|
|
|
|
2017-01-09 15:02:34 +00:00
|
|
|
// set cursor position to current sort field
|
2017-02-12 06:03:10 +00:00
|
|
|
current := config.Get("sortField")
|
2017-02-15 04:44:03 +00:00
|
|
|
for n, item := range m.Items {
|
|
|
|
if item.Val == current {
|
2017-01-09 15:02:34 +00:00
|
|
|
m.CursorPos = n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-04 23:13:17 +00:00
|
|
|
ui.Render(m)
|
|
|
|
m.NavigationHandlers()
|
|
|
|
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
|
2017-02-15 04:44:03 +00:00
|
|
|
config.Update("sortField", m.Items[m.CursorPos].Val)
|
2017-01-04 23:13:17 +00:00
|
|
|
ui.StopLoop()
|
|
|
|
})
|
|
|
|
ui.Loop()
|
|
|
|
}
|