diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index 7b8a172e..42e1be33 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -18,11 +18,11 @@ import ( // list panel functions func (gui *Gui) getContainerContexts() []string { - return []string{"logs", "stats", "config", "top"} + return []string{"logs", "stats", "env", "config", "top"} } func (gui *Gui) getContainerContextTitles() []string { - return []string{gui.Tr.LogsTitle, gui.Tr.StatsTitle, gui.Tr.ConfigTitle, gui.Tr.TopTitle} + return []string{gui.Tr.LogsTitle, gui.Tr.StatsTitle, gui.Tr.EnvTitle, gui.Tr.ConfigTitle, gui.Tr.TopTitle} } func (gui *Gui) getSelectedContainer() (*commands.Container, error) { @@ -75,6 +75,10 @@ func (gui *Gui) handleContainerSelect(g *gocui.Gui, v *gocui.View) error { if err := gui.renderContainerConfig(container); err != nil { return err } + case "env": + if err := gui.renderContainerEnv(container); err != nil { + return err + } case "stats": if err := gui.renderContainerStats(container); err != nil { return err @@ -90,6 +94,37 @@ func (gui *Gui) handleContainerSelect(g *gocui.Gui, v *gocui.View) error { return nil } +func (gui *Gui) renderContainerEnv(container *commands.Container) error { + mainView := gui.getMainView() + mainView.Autoscroll = false + mainView.Wrap = gui.Config.UserConfig.Gui.WrapMainPanel + outputList := []string{""} + envMapping := map[string]string{} + padding := 0 + if len(container.Details.Config.Env) > 0 { + for _, env := range container.Details.Config.Env { + splitEnv := strings.Split(env, "=") + // get the length of environment variable with longest name in order to determine padding + if len(splitEnv[0]) > padding { + padding = len(splitEnv[0]) + } + // if the value has = in it, lets say export "test=foo=bar" then split will result in the following + // {"test", "foo","bar"} hence join all the elements in the slice except the first one to get value + envMapping[utils.ColoredString(splitEnv[0], color.FgBlue)] = utils.ColoredString( + strings.Join(splitEnv[1:], "="), color.FgYellow) + } + padding += 5 + for envName, envValue := range envMapping { + outputList = append(outputList, fmt.Sprintf("%s: %s", utils.WithPadding(envName, padding), envValue)) + } + } else { + outputList[0] = "Nothing to display" + } + return gui.T.NewTask(func(stop chan struct{}) { + gui.renderString(gui.g, "main", strings.Join(outputList, "\n")) + }) +} + func (gui *Gui) renderContainerConfig(container *commands.Container) error { mainView := gui.getMainView() mainView.Autoscroll = false diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index e455567e..eae04630 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -64,6 +64,7 @@ func dutchSet() TranslationSet { ErrorTitle: "Fout", LogsTitle: "Logs", ConfigTitle: "Config", + EnvTitle: "Env", DockerComposeConfigTitle: "Docker-Compose Configuratie", TopTitle: "Top", StatsTitle: "Stats", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 8efb854e..cc9dd509 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -85,6 +85,7 @@ type TranslationSet struct { LogsTitle string ConfigTitle string + EnvTitle string DockerComposeConfigTitle string StatsTitle string CreditsTitle string @@ -166,6 +167,7 @@ func englishSet() TranslationSet { ErrorTitle: "Error", LogsTitle: "Logs", ConfigTitle: "Config", + EnvTitle: "Env", DockerComposeConfigTitle: "Docker-Compose Config", TopTitle: "Top", StatsTitle: "Stats", diff --git a/pkg/i18n/german.go b/pkg/i18n/german.go index 2c5a816e..33423368 100644 --- a/pkg/i18n/german.go +++ b/pkg/i18n/german.go @@ -63,6 +63,7 @@ func germanSet() TranslationSet { ErrorTitle: "Fehler", LogsTitle: "Protokoll", ConfigTitle: "Konfiguration", + EnvTitle: "Env", DockerComposeConfigTitle: "Docker-Compose Konfiguration", TopTitle: "Top", StatsTitle: "Statistiken", diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index 53681fa4..0a5e1cc3 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -63,6 +63,7 @@ func polishSet() TranslationSet { ErrorTitle: "Błąd", LogsTitle: "Logi", ConfigTitle: "Konfiguracja", + EnvTitle: "Env", DockerComposeConfigTitle: "Konfiguracja docker-compose", TopTitle: "Top", StatsTitle: "Staty", diff --git a/pkg/i18n/turkish.go b/pkg/i18n/turkish.go index a728dabf..bf3fe457 100644 --- a/pkg/i18n/turkish.go +++ b/pkg/i18n/turkish.go @@ -63,6 +63,7 @@ func turkishSet() TranslationSet { ErrorTitle: "Hata", LogsTitle: "Kayitlar", ConfigTitle: "Ayarlar", + EnvTitle: "Env", DockerComposeConfigTitle: "Docker-Compose Ayar", TopTitle: "Top", StatsTitle: "Durumlar",