more progress

This commit is contained in:
Jesse Duffield 2019-06-02 01:00:12 +10:00
parent aa55ff1a8e
commit fdc36903ac
6 changed files with 50 additions and 14 deletions

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"sort"
"strings" "strings"
"github.com/docker/docker/api/types" "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 return containers, services, nil
} }

View file

@ -23,11 +23,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(s.Name, color.FgWhite)} return []string{utils.ColoredString("none", color.FgBlack), utils.ColoredString(s.Name, color.FgWhite), ""}
} }
cont := s.Container 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 // Remove removes the service's containers

View file

@ -269,7 +269,9 @@ func (gui *Gui) refreshContainersAndServices() error {
fmt.Fprint(containersView, list) fmt.Fprint(containersView, list)
if containersView == g.CurrentView() { 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 // doing the exact same thing for services
@ -279,14 +281,14 @@ func (gui *Gui) refreshContainersAndServices() error {
servicesView := gui.getServicesView() servicesView := gui.getServicesView()
servicesView.Clear() servicesView.Clear()
isFocused = gui.g.CurrentView().Name() == "services" 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 { if err != nil {
return err return err
} }
fmt.Fprint(servicesView, list) fmt.Fprint(servicesView, list)
if servicesView == g.CurrentView() { if servicesView == g.CurrentView() {
return gui.handleContainerSelect(g, servicesView) return gui.handleServiceSelect(g, servicesView)
} }
return nil return nil
}) })

View file

@ -128,7 +128,7 @@ func NewGui(log *logrus.Entry, dockerCommand *commands.DockerCommand, oSCommand
initialState := guiState{ initialState := guiState{
Containers: make([]*commands.Container, 0), Containers: make([]*commands.Container, 0),
PreviousView: "containers", PreviousView: "services",
Platform: *oSCommand.Platform, Platform: *oSCommand.Platform,
Panels: &panelStates{ Panels: &panelStates{
Services: &servicePanelState{SelectedLine: -1, ContextIndex: 0}, Services: &servicePanelState{SelectedLine: -1, ContextIndex: 0},
@ -291,10 +291,13 @@ func (gui *Gui) layout(g *gocui.Gui) error {
usableSpace := height - 4 usableSpace := height - 4
tallPanels := 3
vHeights := map[string]int{ vHeights := map[string]int{
"status": 3, "status": tallPanels,
"containers": usableSpace/2 + usableSpace%2, "services": usableSpace/tallPanels + usableSpace%tallPanels,
"images": usableSpace / 2, "containers": usableSpace / tallPanels,
"images": usableSpace / tallPanels,
"options": 1, "options": 1,
} }
@ -305,11 +308,12 @@ func (gui *Gui) layout(g *gocui.Gui) error {
} }
vHeights = map[string]int{ vHeights = map[string]int{
"status": defaultHeight, "status": defaultHeight,
"services": defaultHeight,
"containers": defaultHeight, "containers": defaultHeight,
"images": defaultHeight, "images": defaultHeight,
"options": defaultHeight, "options": defaultHeight,
} }
vHeights[currentCyclebleView] = height - defaultHeight*2 - 1 vHeights[currentCyclebleView] = height - defaultHeight*tallPanels - 1
} }
optionsVersionBoundary := width - max(len(utils.Decolorise(information)), 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 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 != nil {
if err.Error() != "unknown view" { if err.Error() != "unknown view" {
return err return err

View file

@ -10,7 +10,7 @@ import (
"github.com/spkg/bom" "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 { func (gui *Gui) refreshSidePanels(g *gocui.Gui) error {
if err := gui.refreshContainersAndServices(); err != nil { 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) return gui.handleMenuSelect(g, v)
case "status": case "status":
return gui.handleStatusSelect(g, v) return gui.handleStatusSelect(g, v)
case "services":
return gui.handleServiceSelect(g, v)
case "containers": case "containers":
return gui.handleContainerSelect(g, v) return gui.handleContainerSelect(g, v)
case "images": 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 { func (gui *Gui) returnFocus(g *gocui.Gui, v *gocui.View) error {
previousView, err := g.View(gui.State.PreviousView) previousView, err := g.View(gui.State.PreviousView)
if err != nil { if err != nil {
// always fall back to containers view if there's no 'previous' view stored // always fall back to services view if there's no 'previous' view stored
previousView, err = g.View("containers") previousView, err = g.View("services")
if err != nil { if err != nil {
gui.Log.Error(err) gui.Log.Error(err)
} }

View file

@ -812,6 +812,10 @@ func addEnglish(i18nObject *i18n.Bundle) error {
ID: "attach", ID: "attach",
Other: "attach", Other: "attach",
}, },
&i18n.Message{
ID: "ServicesTitle",
Other: "Services",
},
&i18n.Message{ &i18n.Message{
ID: "ContainersTitle", ID: "ContainersTitle",
Other: "Containers", Other: "Containers",