added container menu closes #28

This commit is contained in:
Peter Reisinger
2017-11-20 11:09:36 +00:00
parent e1ec264345
commit 436266b1a4
8 changed files with 163 additions and 3 deletions

View File

@@ -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()
}