mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
added container menu closes #28
This commit is contained in:
50
menus.go
50
menus.go
@@ -94,3 +94,53 @@ func SortMenu() {
|
||||
ui.Render(m)
|
||||
ui.Loop()
|
||||
}
|
||||
|
||||
func ContainerMenu() {
|
||||
|
||||
c := cursor.Selected()
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
|
||||
ui.DefaultEvtStream.ResetHandlers()
|
||||
defer ui.DefaultEvtStream.ResetHandlers()
|
||||
|
||||
m := menu.NewMenu()
|
||||
m.Selectable = true
|
||||
|
||||
m.BorderLabel = "Menu"
|
||||
var items []menu.Item
|
||||
if c.Meta["state"] == "running" {
|
||||
items = append(items, menu.Item{Val: "stop", Label: "stop"})
|
||||
}
|
||||
if c.Meta["state"] == "exited" {
|
||||
items = append(items, menu.Item{Val: "start", Label: "start"})
|
||||
items = append(items, menu.Item{Val: "remove", Label: "remove"})
|
||||
}
|
||||
items = append(items, menu.Item{Val: "cancel", Label: "cancel"})
|
||||
|
||||
m.AddItems(items...)
|
||||
ui.Render(m)
|
||||
|
||||
HandleKeys("up", m.Up)
|
||||
HandleKeys("down", m.Down)
|
||||
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
|
||||
switch m.SelectedItem().Val {
|
||||
case "start":
|
||||
c.Start()
|
||||
ui.StopLoop()
|
||||
case "stop":
|
||||
c.Stop()
|
||||
ui.StopLoop()
|
||||
case "remove":
|
||||
c.Remove()
|
||||
ui.StopLoop()
|
||||
case "cancel":
|
||||
ui.StopLoop()
|
||||
}
|
||||
})
|
||||
ui.Handle("/sys/kbd/", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
ui.Loop()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user