mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
better alignment for health check
This commit is contained in:
parent
386334b1f0
commit
1dd0875323
2 changed files with 23 additions and 15 deletions
|
|
@ -251,31 +251,38 @@ type ContainerCliStat struct {
|
||||||
func (c *Container) GetDisplayStrings(isFocused bool) []string {
|
func (c *Container) GetDisplayStrings(isFocused bool) []string {
|
||||||
image := strings.TrimPrefix(c.Container.Image, "sha256:")
|
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
|
// GetDisplayStatus returns the colored status of the container
|
||||||
func (c *Container) GetDisplayStatus() string {
|
func (c *Container) GetDisplayStatus() string {
|
||||||
state := c.Container.State
|
return utils.ColoredString(c.Container.State, c.GetColor())
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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{
|
healthStatusColorMap := map[string]color.Attribute{
|
||||||
"healthy": color.FgGreen,
|
"healthy": color.FgGreen,
|
||||||
"unhealthy": color.FgRed,
|
"unhealthy": color.FgRed,
|
||||||
"starting": color.FgYellow,
|
"starting": color.FgYellow,
|
||||||
}
|
}
|
||||||
if c.Container.State != "running" {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
healthStatus := c.Details.State.Health.Status
|
healthStatus := c.Details.State.Health.Status
|
||||||
if healthStatusColor, ok := healthStatusColorMap[healthStatus]; ok {
|
if healthStatusColor, ok := healthStatusColorMap[healthStatus]; ok {
|
||||||
return utils.ColoredString(" ("+healthStatus+")", healthStatusColor)
|
return utils.ColoredString(fmt.Sprintf("(%s)", healthStatus), healthStatusColor)
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/docker/docker/api/types/container"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types/container"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/utils"
|
"github.com/jesseduffield/lazydocker/pkg/utils"
|
||||||
|
|
@ -24,11 +25,11 @@ type Service struct {
|
||||||
func (s *Service) GetDisplayStrings(isFocused bool) []string {
|
func (s *Service) GetDisplayStrings(isFocused bool) []string {
|
||||||
|
|
||||||
if s.Container == nil {
|
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
|
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
|
// Remove removes the service's containers
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue