Merge pull request #237 from jesseduffield/health-check-alignment

better alignment for health check
This commit is contained in:
Jesse Duffield 2020-09-23 20:21:17 +10:00 committed by GitHub
commit 197ff321d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 17 deletions

View file

@ -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 ""
}

View file

@ -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

View file

@ -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.

View file

@ -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"
}