ctop/menus.go

75 lines
1.4 KiB
Go
Raw Normal View History

2017-01-05 00:13:17 +01:00
package main
import (
2017-02-07 04:33:09 +01:00
"github.com/bcicen/ctop/config"
2017-01-05 00:13:17 +01:00
"github.com/bcicen/ctop/widgets"
ui "github.com/gizak/termui"
)
var helpDialog = []string{
"[h] - open this help dialog",
2017-01-06 12:53:30 +01:00
"[s] - select container sort field",
2017-01-12 20:48:29 +01:00
"[r] - reverse container sort order",
2017-01-05 00:13:17 +01:00
"[q] - exit ctop",
}
2017-01-09 00:07:58 +01:00
func HelpMenu() {
ResetView()
defer ResetView()
2017-01-05 00:13:17 +01:00
m := widgets.NewMenu(helpDialog)
m.TextFgColor = ui.ColorWhite
m.BorderLabel = "Help"
m.BorderFg = ui.ColorCyan
ui.Render(m)
ui.Handle("/sys/kbd/", func(ui.Event) {
ui.StopLoop()
})
ui.Loop()
}
2017-01-21 19:15:29 +01:00
func FilterMenu() {
ui.DefaultEvtStream.ResetHandlers()
defer ResetView()
2017-01-21 19:15:29 +01:00
i := widgets.NewInput()
i.TextFgColor = ui.ColorWhite
i.BorderLabel = "Filter"
i.BorderFg = ui.ColorCyan
i.SetY(ui.TermHeight() - i.Height)
2017-01-21 19:15:29 +01:00
ui.Render(i)
i.InputHandlers()
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
2017-02-07 04:33:09 +01:00
config.Update("filterStr", i.Data)
2017-01-21 19:15:29 +01:00
ui.StopLoop()
})
ui.Loop()
}
2017-01-09 00:07:58 +01:00
func SortMenu() {
ResetView()
defer ResetView()
2017-01-12 20:24:12 +01:00
m := widgets.NewMenu(SortFields())
2017-01-05 00:13:17 +01:00
m.Selectable = true
m.TextFgColor = ui.ColorWhite
m.BorderLabel = "Sort Field"
m.BorderFg = ui.ColorCyan
// set cursor position to current sort field
current := config.Get("sortField")
for n, item := range m.Items {
if item.Val == current {
m.CursorPos = n
}
}
2017-01-05 00:13:17 +01:00
ui.Render(m)
m.NavigationHandlers()
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
config.Update("sortField", m.Items[m.CursorPos].Val)
2017-01-05 00:13:17 +01:00
ui.StopLoop()
})
ui.Loop()
}