diff --git a/pkg/commands/container.go b/pkg/commands/container.go index 9b56664d..2cb60854 100644 --- a/pkg/commands/container.go +++ b/pkg/commands/container.go @@ -9,6 +9,7 @@ import ( "sync" "github.com/docker/docker/api/types/container" + "github.com/samber/lo" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" @@ -51,7 +52,15 @@ type Container struct { func (c *Container) GetDisplayStrings(isFocused bool) []string { image := strings.TrimPrefix(c.Container.Image, "sha256:") - return []string{c.GetDisplayStatus(), c.GetDisplaySubstatus(), c.Name, c.GetDisplayCPUPerc(), utils.ColoredString(image, color.FgMagenta)} + return []string{c.GetDisplayStatus(), c.GetDisplaySubstatus(), c.Name, c.GetDisplayCPUPerc(), utils.ColoredString(image, color.FgMagenta), c.displayPorts()} +} + +func (c *Container) displayPorts() string { + portStrings := lo.Map(c.Container.Ports, func(port types.Port, _ int) string { + return fmt.Sprintf("%s:%d->%d/%s", port.IP, port.PublicPort, port.PrivatePort, port.Type) + }) + + return strings.Join(portStrings, ", ") } // GetDisplayStatus returns the colored status of the container diff --git a/pkg/commands/service.go b/pkg/commands/service.go index 269e119f..f45146bc 100644 --- a/pkg/commands/service.go +++ b/pkg/commands/service.go @@ -24,11 +24,11 @@ type Service struct { // GetDisplayStrings returns the dispaly string of Container 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(), cont.GetDisplaySubstatus(), s.Name, cont.GetDisplayCPUPerc()} + return []string{cont.GetDisplayStatus(), cont.GetDisplaySubstatus(), s.Name, cont.GetDisplayCPUPerc(), utils.ColoredString(cont.displayPorts(), color.FgYellow)} } // Remove removes the service's containers