mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
Open in browser
Most containers expose some http port. We can open it in browser. For simplicity we can just open first container's published port. We'll determine the ip:port on container creation and store to meta "Web Port". To open browser on any platform was added a new dependency github.com/pkg/browser which is very small
This commit is contained in:
23
menus.go
23
menus.go
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/bcicen/ctop/widgets"
|
||||
"github.com/bcicen/ctop/widgets/menu"
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/pkg/browser"
|
||||
)
|
||||
|
||||
// MenuFn executes a menu window, returning the next menu or nil
|
||||
@@ -27,6 +28,7 @@ var helpDialog = []menu.Item{
|
||||
{"[o] - open single view", ""},
|
||||
{"[l] - view container logs ([t] to toggle timestamp when open)", ""},
|
||||
{"[e] - exec shell", ""},
|
||||
{"[w] - open browser (first port is http)", ""},
|
||||
{"[c] - configure columns", ""},
|
||||
{"[S] - save current configuration to file", ""},
|
||||
{"[q] - exit ctop", ""},
|
||||
@@ -221,6 +223,7 @@ func ContainerMenu() MenuFn {
|
||||
items = append(items, menu.Item{Val: "pause", Label: "[p] pause"})
|
||||
items = append(items, menu.Item{Val: "restart", Label: "[r] restart"})
|
||||
items = append(items, menu.Item{Val: "exec", Label: "[e] exec shell"})
|
||||
items = append(items, menu.Item{Val: "browser", Label: "[w] open in browser"})
|
||||
}
|
||||
if c.Meta["state"] == "exited" || c.Meta["state"] == "created" {
|
||||
items = append(items, menu.Item{Val: "start", Label: "[s] start"})
|
||||
@@ -277,6 +280,9 @@ func ContainerMenu() MenuFn {
|
||||
selected = "restart"
|
||||
ui.StopLoop()
|
||||
})
|
||||
ui.Handle("/sys/kbd/w", func(ui.Event) {
|
||||
selected = "browser"
|
||||
})
|
||||
}
|
||||
ui.Handle("/sys/kbd/R", func(ui.Event) {
|
||||
selected = "remove"
|
||||
@@ -303,6 +309,8 @@ func ContainerMenu() MenuFn {
|
||||
nextMenu = LogMenu
|
||||
case "exec":
|
||||
nextMenu = ExecShell
|
||||
case "browser":
|
||||
nextMenu = OpenInBrowser
|
||||
case "start":
|
||||
nextMenu = Confirm(confirmTxt("start", c.GetMeta("name")), c.Start)
|
||||
case "stop":
|
||||
@@ -374,6 +382,21 @@ func ExecShell() MenuFn {
|
||||
return nil
|
||||
}
|
||||
|
||||
func OpenInBrowser() MenuFn {
|
||||
c := cursor.Selected()
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
webPort := c.Meta.Get("Web Port")
|
||||
if webPort == "" {
|
||||
return nil
|
||||
}
|
||||
link := "http://" + webPort + "/"
|
||||
browser.OpenURL(link)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create a confirmation dialog with a given description string and
|
||||
// func to perform if confirmed
|
||||
func Confirm(txt string, fn func()) MenuFn {
|
||||
|
||||
Reference in New Issue
Block a user