mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
82 lines
1.6 KiB
Go
82 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/bcicen/ctop/config"
|
|
"github.com/bcicen/ctop/widgets"
|
|
"github.com/bcicen/ctop/widgets/menu"
|
|
ui "github.com/gizak/termui"
|
|
)
|
|
|
|
var helpDialog = []menu.Item{
|
|
menu.Item{"[h] - open this help dialog", ""},
|
|
menu.Item{"[s] - select container sort field", ""},
|
|
menu.Item{"[r] - reverse container sort order", ""},
|
|
menu.Item{"[q] - exit ctop", ""},
|
|
}
|
|
|
|
func HelpMenu() {
|
|
ResetView()
|
|
defer ResetView()
|
|
|
|
m := menu.NewMenu()
|
|
m.TextFgColor = ui.ColorWhite
|
|
m.BorderLabel = "Help"
|
|
m.BorderFg = ui.ColorCyan
|
|
m.AddItems(helpDialog...)
|
|
ui.Render(m)
|
|
ui.Handle("/sys/kbd/", func(ui.Event) {
|
|
ui.StopLoop()
|
|
})
|
|
ui.Loop()
|
|
}
|
|
|
|
func FilterMenu() {
|
|
ui.DefaultEvtStream.ResetHandlers()
|
|
defer ResetView()
|
|
|
|
i := widgets.NewInput()
|
|
i.TextFgColor = ui.ColorWhite
|
|
i.BorderLabel = "Filter"
|
|
i.BorderFg = ui.ColorCyan
|
|
i.SetY(ui.TermHeight() - i.Height)
|
|
ui.Render(i)
|
|
i.InputHandlers()
|
|
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
|
|
config.Update("filterStr", i.Data)
|
|
ui.StopLoop()
|
|
})
|
|
ui.Loop()
|
|
}
|
|
|
|
func SortMenu() {
|
|
ResetView()
|
|
defer ResetView()
|
|
|
|
m := menu.NewMenu()
|
|
m.Selectable = true
|
|
m.SortItems = true
|
|
m.TextFgColor = ui.ColorWhite
|
|
m.BorderLabel = "Sort Field"
|
|
m.BorderFg = ui.ColorCyan
|
|
|
|
for _, field := range SortFields() {
|
|
m.AddItems(menu.Item{field, ""})
|
|
}
|
|
|
|
// set cursor position to current sort field
|
|
//current := config.Get("sortField")
|
|
//for n, item := range m.Items {
|
|
//if item.Val == current {
|
|
//m.CursorPos = n
|
|
//}
|
|
//}
|
|
|
|
ui.Render(m)
|
|
m.NavigationHandlers()
|
|
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
|
|
config.Update("sortField", m.SelectedItem().Val)
|
|
ui.StopLoop()
|
|
})
|
|
ui.Loop()
|
|
}
|