mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-22 15:11:02 +00:00
more progress
This commit is contained in:
parent
aa55ff1a8e
commit
fdc36903ac
6 changed files with 50 additions and 14 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
|
|
@ -98,6 +99,19 @@ func (c *DockerCommand) GetContainersAndServices() ([]*Container, []*Service, er
|
|||
}
|
||||
}
|
||||
|
||||
// sort services first by whether they have a linked container, and second by alphabetical order
|
||||
sort.Slice(services, func(i, j int) bool {
|
||||
if services[i].Container != nil && services[j].Container == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
if services[i].Container == nil && services[j].Container != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return services[i].Name < services[j].Name
|
||||
})
|
||||
|
||||
return containers, services, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ type Service struct {
|
|||
func (s *Service) GetDisplayStrings(isFocused bool) []string {
|
||||
|
||||
if s.Container == nil {
|
||||
return []string{"", utils.ColoredString(s.Name, color.FgWhite)}
|
||||
return []string{utils.ColoredString("none", color.FgBlack), utils.ColoredString(s.Name, color.FgWhite), ""}
|
||||
}
|
||||
|
||||
cont := s.Container
|
||||
return []string{utils.ColoredString(cont.Container.State, cont.GetColor()), utils.ColoredString(cont.Name, color.FgWhite), cont.Stats.CPUPerc}
|
||||
return []string{utils.ColoredString(cont.Container.State, cont.GetColor()), utils.ColoredString(s.Name, color.FgWhite), cont.Stats.CPUPerc}
|
||||
}
|
||||
|
||||
// Remove removes the service's containers
|
||||
|
|
|
|||
|
|
@ -269,7 +269,9 @@ func (gui *Gui) refreshContainersAndServices() error {
|
|||
fmt.Fprint(containersView, list)
|
||||
|
||||
if containersView == g.CurrentView() {
|
||||
return gui.handleContainerSelect(g, containersView)
|
||||
if err := gui.handleContainerSelect(g, containersView); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// doing the exact same thing for services
|
||||
|
|
@ -279,14 +281,14 @@ func (gui *Gui) refreshContainersAndServices() error {
|
|||
servicesView := gui.getServicesView()
|
||||
servicesView.Clear()
|
||||
isFocused = gui.g.CurrentView().Name() == "services"
|
||||
list, err = utils.RenderList(gui.State.Containers, utils.IsFocused(isFocused))
|
||||
list, err = utils.RenderList(gui.State.Services, utils.IsFocused(isFocused))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprint(servicesView, list)
|
||||
|
||||
if servicesView == g.CurrentView() {
|
||||
return gui.handleContainerSelect(g, servicesView)
|
||||
return gui.handleServiceSelect(g, servicesView)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ func NewGui(log *logrus.Entry, dockerCommand *commands.DockerCommand, oSCommand
|
|||
|
||||
initialState := guiState{
|
||||
Containers: make([]*commands.Container, 0),
|
||||
PreviousView: "containers",
|
||||
PreviousView: "services",
|
||||
Platform: *oSCommand.Platform,
|
||||
Panels: &panelStates{
|
||||
Services: &servicePanelState{SelectedLine: -1, ContextIndex: 0},
|
||||
|
|
@ -291,10 +291,13 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||
|
||||
usableSpace := height - 4
|
||||
|
||||
tallPanels := 3
|
||||
|
||||
vHeights := map[string]int{
|
||||
"status": 3,
|
||||
"containers": usableSpace/2 + usableSpace%2,
|
||||
"images": usableSpace / 2,
|
||||
"status": tallPanels,
|
||||
"services": usableSpace/tallPanels + usableSpace%tallPanels,
|
||||
"containers": usableSpace / tallPanels,
|
||||
"images": usableSpace / tallPanels,
|
||||
"options": 1,
|
||||
}
|
||||
|
||||
|
|
@ -305,11 +308,12 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||
}
|
||||
vHeights = map[string]int{
|
||||
"status": defaultHeight,
|
||||
"services": defaultHeight,
|
||||
"containers": defaultHeight,
|
||||
"images": defaultHeight,
|
||||
"options": defaultHeight,
|
||||
}
|
||||
vHeights[currentCyclebleView] = height - defaultHeight*2 - 1
|
||||
vHeights[currentCyclebleView] = height - defaultHeight*tallPanels - 1
|
||||
}
|
||||
|
||||
optionsVersionBoundary := width - max(len(utils.Decolorise(information)), 1)
|
||||
|
|
@ -341,7 +345,17 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||
v.FgColor = gocui.ColorWhite
|
||||
}
|
||||
|
||||
containersView, err := g.SetViewBeneath("containers", "status", vHeights["containers"])
|
||||
servicesView, err := g.SetViewBeneath("services", "status", vHeights["services"])
|
||||
if err != nil {
|
||||
if err.Error() != "unknown view" {
|
||||
return err
|
||||
}
|
||||
servicesView.Highlight = true
|
||||
servicesView.Title = gui.Tr.SLocalize("ServicesTitle")
|
||||
servicesView.FgColor = gocui.ColorWhite
|
||||
}
|
||||
|
||||
containersView, err := g.SetViewBeneath("containers", "services", vHeights["containers"])
|
||||
if err != nil {
|
||||
if err.Error() != "unknown view" {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/spkg/bom"
|
||||
)
|
||||
|
||||
var cyclableViews = []string{"status", "containers", "images"}
|
||||
var cyclableViews = []string{"status", "services", "containers", "images"}
|
||||
|
||||
func (gui *Gui) refreshSidePanels(g *gocui.Gui) error {
|
||||
if err := gui.refreshContainersAndServices(); err != nil {
|
||||
|
|
@ -83,6 +83,8 @@ func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error {
|
|||
return gui.handleMenuSelect(g, v)
|
||||
case "status":
|
||||
return gui.handleStatusSelect(g, v)
|
||||
case "services":
|
||||
return gui.handleServiceSelect(g, v)
|
||||
case "containers":
|
||||
return gui.handleContainerSelect(g, v)
|
||||
case "images":
|
||||
|
|
@ -100,8 +102,8 @@ func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error {
|
|||
func (gui *Gui) returnFocus(g *gocui.Gui, v *gocui.View) error {
|
||||
previousView, err := g.View(gui.State.PreviousView)
|
||||
if err != nil {
|
||||
// always fall back to containers view if there's no 'previous' view stored
|
||||
previousView, err = g.View("containers")
|
||||
// always fall back to services view if there's no 'previous' view stored
|
||||
previousView, err = g.View("services")
|
||||
if err != nil {
|
||||
gui.Log.Error(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -812,6 +812,10 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||
ID: "attach",
|
||||
Other: "attach",
|
||||
},
|
||||
&i18n.Message{
|
||||
ID: "ServicesTitle",
|
||||
Other: "Services",
|
||||
},
|
||||
&i18n.Message{
|
||||
ID: "ContainersTitle",
|
||||
Other: "Containers",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue