diff --git a/pkg/commands/container.go b/pkg/commands/container.go index cc896ae5..ad9f95a3 100644 --- a/pkg/commands/container.go +++ b/pkg/commands/container.go @@ -251,31 +251,38 @@ type ContainerCliStat struct { func (c *Container) GetDisplayStrings(isFocused bool) []string { image := strings.TrimPrefix(c.Container.Image, "sha256:") - return []string{c.GetDisplayStatus(), c.Name, c.GetDisplayCPUPerc(), utils.ColoredString(image, color.FgMagenta)} + return []string{c.GetDisplayStatus(), c.GetDisplaySubstatus(), c.Name, c.GetDisplayCPUPerc(), utils.ColoredString(image, color.FgMagenta)} } // GetDisplayStatus returns the colored status of the container func (c *Container) GetDisplayStatus() string { - state := c.Container.State - if c.Container.State == "exited" { - return utils.ColoredString(state+" ("+strconv.Itoa(c.Details.State.ExitCode)+")", c.GetColor()) - } - - return utils.ColoredString(state, c.GetColor()) + c.healthStatusString() + return utils.ColoredString(c.Container.State, c.GetColor()) } -func (c *Container) healthStatusString() string { +// GetDisplayStatus returns the exit code if the container has exited, and the health status if the container is running (and has a health check) +func (c *Container) GetDisplaySubstatus() string { + switch c.Container.State { + case "exited": + return utils.ColoredString( + fmt.Sprintf("(%s)", strconv.Itoa(c.Details.State.ExitCode)), c.GetColor(), + ) + case "running": + return c.getHealthStatus() + default: + return "" + } +} + +func (c *Container) getHealthStatus() string { healthStatusColorMap := map[string]color.Attribute{ "healthy": color.FgGreen, "unhealthy": color.FgRed, "starting": color.FgYellow, } - if c.Container.State != "running" { - return "" - } + healthStatus := c.Details.State.Health.Status if healthStatusColor, ok := healthStatusColorMap[healthStatus]; ok { - return utils.ColoredString(" ("+healthStatus+")", healthStatusColor) + return utils.ColoredString(fmt.Sprintf("(%s)", healthStatus), healthStatusColor) } return "" } diff --git a/pkg/commands/service.go b/pkg/commands/service.go index 59580ef4..a0642cb0 100644 --- a/pkg/commands/service.go +++ b/pkg/commands/service.go @@ -1,9 +1,10 @@ package commands import ( - "github.com/docker/docker/api/types/container" "os/exec" + "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types" "github.com/fatih/color" "github.com/jesseduffield/lazydocker/pkg/utils" @@ -24,11 +25,11 @@ type Service struct { func (s *Service) GetDisplayStrings(isFocused bool) []string { if s.Container == nil { - return []string{utils.ColoredString("none", color.FgBlue), s.Name, ""} + return []string{utils.ColoredString("none", color.FgBlue), "", s.Name, ""} } cont := s.Container - return []string{cont.GetDisplayStatus(), s.Name, cont.GetDisplayCPUPerc()} + return []string{cont.GetDisplayStatus(), cont.GetDisplaySubstatus(), s.Name, cont.GetDisplayCPUPerc()} } // Remove removes the service's containers diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index a955b79f..09c02501 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -1,6 +1,8 @@ package gui import ( + "strconv" + "github.com/jesseduffield/gocui" ) @@ -53,7 +55,7 @@ func (b *Binding) GetKey() string { return "PgDn" } - return string(key) + return strconv.Itoa(key) } // GetInitialKeybindings is a function. diff --git a/pkg/gui/volumes_panel.go b/pkg/gui/volumes_panel.go index 721c5169..fc2c5cad 100644 --- a/pkg/gui/volumes_panel.go +++ b/pkg/gui/volumes_panel.go @@ -97,7 +97,7 @@ func (gui *Gui) renderVolumeConfig(mainView *gocui.View, volume *commands.Volume } if volume.Volume.UsageData != nil { - output += utils.WithPadding("RefCount: ", padding) + string(volume.Volume.UsageData.RefCount) + "\n" + output += utils.WithPadding("RefCount: ", padding) + fmt.Sprintf("%d", volume.Volume.UsageData.RefCount) + "\n" output += utils.WithPadding("Size: ", padding) + utils.FormatBinaryBytes(int(volume.Volume.UsageData.Size)) + "\n" }