diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index 6b1c49f2..02fabfe8 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -74,6 +74,7 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat Config: config, Client: cli, ErrorChan: errorChan, + ShowExited: true, InDockerComposeProject: true, } @@ -214,10 +215,8 @@ func (c *DockerCommand) RefreshContainersAndServices() error { c.assignContainersToServices(containers, services) - var displayContainers []*Container - if c.Config.UserConfig.Gui.ShowAllContainers { - displayContainers = containers - } else { + var displayContainers = containers + if !c.Config.UserConfig.Gui.ShowAllContainers { displayContainers = c.obtainStandaloneContainers(containers, services) } @@ -236,7 +235,7 @@ func (c *DockerCommand) RefreshContainersAndServices() error { c.Containers = containers c.Services = services - c.DisplayContainers = displayContainers + c.DisplayContainers = c.filterOutExited(displayContainers) return nil } @@ -254,6 +253,20 @@ L: } } +// filterOutExited filters out the exited containers if c.ShowExited is false +func (c *DockerCommand) filterOutExited(containers []*Container) []*Container { + if c.ShowExited { + return containers + } + toReturn := []*Container{} + for _, container := range containers { + if container.Container.State != "exited" { + toReturn = append(toReturn, container) + } + } + return toReturn +} + // obtainStandaloneContainers returns standalone containers. Standalone containers are containers which are either one-off containers, or whose service is not part of this docker-compose context func (c *DockerCommand) obtainStandaloneContainers(containers []*Container, services []*Service) []*Container { standaloneContainers := []*Container{} diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index 06b8267c..d1c61f5e 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -277,17 +277,8 @@ func (gui *Gui) refreshContainersAndServices() error { gui.g.Update(func(g *gocui.Gui) error { containersView.Clear() isFocused := gui.g.CurrentView().Name() == "containers" - toRender := gui.DockerCommand.DisplayContainers - if !gui.DockerCommand.ShowExited { - toRender = []*commands.Container{} - for _, container := range gui.DockerCommand.DisplayContainers { - if container.Container.State != "exited" { - toRender = append(toRender, container) - } - } - } - list, err := utils.RenderList(toRender, utils.IsFocused(isFocused)) + list, err := utils.RenderList(gui.DockerCommand.DisplayContainers, utils.IsFocused(isFocused)) if err != nil { return err }