Exec Sh Feature

This commit is contained in:
Stanislav Pavlovichev 2018-10-07 16:46:32 +03:00
parent caf6fc63c1
commit f27de1c29e

View File

@ -2,6 +2,8 @@ package main
import ( import (
"fmt" "fmt"
"os"
"os/exec"
"time" "time"
"github.com/bcicen/ctop/config" "github.com/bcicen/ctop/config"
@ -134,6 +136,7 @@ func ContainerMenu() MenuFn {
items = append(items, menu.Item{Val: "stop", Label: "stop"}) items = append(items, menu.Item{Val: "stop", Label: "stop"})
items = append(items, menu.Item{Val: "pause", Label: "pause"}) items = append(items, menu.Item{Val: "pause", Label: "pause"})
items = append(items, menu.Item{Val: "restart", Label: "restart"}) items = append(items, menu.Item{Val: "restart", Label: "restart"})
items = append(items, menu.Item{Val: "exec sh", Label: "exec sh"})
} }
if c.Meta["state"] == "exited" || c.Meta["state"] == "created" { if c.Meta["state"] == "exited" || c.Meta["state"] == "created" {
items = append(items, menu.Item{Val: "start", Label: "start"}) items = append(items, menu.Item{Val: "start", Label: "start"})
@ -156,6 +159,8 @@ func ContainerMenu() MenuFn {
nextMenu = SingleView nextMenu = SingleView
case "logs": case "logs":
nextMenu = LogMenu nextMenu = LogMenu
case "exec sh":
nextMenu = ExecSh
case "start": case "start":
nextMenu = Confirm(confirmTxt("start", c.GetMeta("name")), c.Start) nextMenu = Confirm(confirmTxt("start", c.GetMeta("name")), c.Start)
case "stop": case "stop":
@ -207,6 +212,24 @@ func LogMenu() MenuFn {
return nil return nil
} }
func ExecSh() MenuFn {
c := cursor.Selected()
if c == nil {
return nil
}
// Reset colors && clear screen && run sh
cmdName := fmt.Sprintf("echo '\033[0m' && clear && docker exec -it %s sh", c.GetMeta("name"))
cmd := exec.Command("bash", "-c", cmdName)
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
cmd.Run()
return nil
}
// Create a confirmation dialog with a given description string and // Create a confirmation dialog with a given description string and
// func to perform if confirmed // func to perform if confirmed
func Confirm(txt string, fn func()) MenuFn { func Confirm(txt string, fn func()) MenuFn {