diff --git a/pkg/gui/arrangement.go b/pkg/gui/arrangement.go index bcd4aa1c..4fc13a19 100644 --- a/pkg/gui/arrangement.go +++ b/pkg/gui/arrangement.go @@ -76,12 +76,8 @@ func (gui *Gui) getMidSectionWeights() (int, int) { if currentWindow == "main" && gui.State.ScreenMode == SCREEN_FULL { mainSectionWeight = 1 sideSectionWeight = 0 - } else { - if gui.State.ScreenMode == SCREEN_HALF { - mainSectionWeight = 1 - } else if gui.State.ScreenMode == SCREEN_FULL { - mainSectionWeight = 0 - } + } else if gui.State.ScreenMode == SCREEN_FULL { + mainSectionWeight = 0 } return sideSectionWeight, mainSectionWeight diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index 862fc4be..6f4a5e04 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -98,6 +98,7 @@ func (gui *Gui) getContainersPanel() *panels.SideListPanel[*commands.Container] return true }, GetTableCells: presentation.GetContainerDisplayStrings, + Title: gui.containersPanelTitle(), } } @@ -548,3 +549,11 @@ func (gui *Gui) openContainerInBrowser(container *commands.Container) error { link := fmt.Sprintf("http://%s:%d/", ip, port.PublicPort) return gui.OSCommand.OpenLink(link) } + +func (gui *Gui) containersPanelTitle() string { + if gui.Config.UserConfig.Gui.ShowAllContainers || !gui.DockerCommand.InDockerComposeProject { + return gui.Tr.ContainersTitle + } else { + return gui.Tr.StandaloneContainersTitle + } +} diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 1ffc8892..1a026a82 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -84,7 +84,7 @@ type guiState struct { // if true, we show containers with an 'exited' status in the containers panel ShowExitedContainers bool - ScreenMode WindowMaximisation + ScreenMode ScreenMode // Maintains the state of manual filtering i.e. typing in a substring // to filter on in the current panel. @@ -105,10 +105,10 @@ type filterState struct { // as in panel, not your terminal's window). Sometimes you want a bit more space // to see the contents of a panel, and this keeps track of how much maximisation // you've set -type WindowMaximisation int +type ScreenMode int const ( - SCREEN_NORMAL WindowMaximisation = iota + SCREEN_NORMAL ScreenMode = iota SCREEN_HALF SCREEN_FULL ) @@ -275,6 +275,8 @@ func (gui *Gui) setPanels() { Volumes: gui.getVolumesPanel(), Menu: gui.getMenuPanel(), } + + gui.setSidePanelHeaders() } func (gui *Gui) updateContainerDetails() error { diff --git a/pkg/gui/images_panel.go b/pkg/gui/images_panel.go index 6ef50fa9..29e67df0 100644 --- a/pkg/gui/images_panel.go +++ b/pkg/gui/images_panel.go @@ -62,6 +62,7 @@ func (gui *Gui) getImagesPanel() *panels.SideListPanel[*commands.Image] { return a.ID < b.ID }, GetTableCells: presentation.GetImageDisplayStrings, + Title: gui.Tr.ImagesTitle, } } diff --git a/pkg/gui/panels/side_list_panel.go b/pkg/gui/panels/side_list_panel.go index 2473e2ce..9c1320e3 100644 --- a/pkg/gui/panels/side_list_panel.go +++ b/pkg/gui/panels/side_list_panel.go @@ -25,6 +25,7 @@ type ISideListPanel interface { HandleClick() error HandlePrevMainTab() error HandleNextMainTab() error + GetTitle() string } // list panel at the side of the screen that renders content to the main panel @@ -59,6 +60,9 @@ type SideListPanel[T comparable] struct { // This can be nil if you want to always show the panel Hide func() bool + + // The title of the view + Title string } var _ ISideListPanel = &SideListPanel[int]{} @@ -269,3 +273,7 @@ func (self *SideListPanel[T]) IsHidden() bool { return self.Hide() } + +func (self *SideListPanel[T]) GetTitle() string { + return self.Title +} diff --git a/pkg/gui/project_panel.go b/pkg/gui/project_panel.go index bfc829f1..2f2f134a 100644 --- a/pkg/gui/project_panel.go +++ b/pkg/gui/project_panel.go @@ -69,6 +69,7 @@ func (gui *Gui) getProjectPanel() *panels.SideListPanel[*commands.Project] { GetTableCells: presentation.GetProjectDisplayStrings, // It doesn't make sense to filter a list of only one item. DisableFilter: true, + Title: gui.Tr.ProjectTitle, } } diff --git a/pkg/gui/services_panel.go b/pkg/gui/services_panel.go index 2c1caaec..46084f8c 100644 --- a/pkg/gui/services_panel.go +++ b/pkg/gui/services_panel.go @@ -78,6 +78,7 @@ func (gui *Gui) getServicesPanel() *panels.SideListPanel[*commands.Service] { Hide: func() bool { return !gui.DockerCommand.InDockerComposeProject }, + Title: gui.Tr.ServicesTitle, } } diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 8ddae589..26933716 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -280,29 +280,51 @@ func (gui *Gui) handleClickAux(v *gocui.View, itemCount int, selectedLine *int, func (gui *Gui) nextScreenMode() error { if gui.currentViewName() == "main" { - gui.State.ScreenMode = prevIntInCycle([]WindowMaximisation{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) - - return nil + gui.State.ScreenMode = prevIntInCycle([]ScreenMode{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) + } else { + gui.State.ScreenMode = nextIntInCycle([]ScreenMode{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) } - gui.State.ScreenMode = nextIntInCycle([]WindowMaximisation{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) + gui.setSidePanelHeaders() return nil } func (gui *Gui) prevScreenMode() error { if gui.currentViewName() == "main" { - gui.State.ScreenMode = nextIntInCycle([]WindowMaximisation{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) - - return nil + gui.State.ScreenMode = nextIntInCycle([]ScreenMode{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) + } else { + gui.State.ScreenMode = prevIntInCycle([]ScreenMode{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) } - gui.State.ScreenMode = prevIntInCycle([]WindowMaximisation{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) + gui.setSidePanelHeaders() return nil } -func nextIntInCycle(sl []WindowMaximisation, current WindowMaximisation) WindowMaximisation { +func (gui *Gui) setSidePanelHeaders() { + sidePanels := gui.allSidePanels() + + if gui.State.ScreenMode == SCREEN_NORMAL { + for _, panel := range sidePanels { + view := panel.GetView() + view.Tabs = nil + view.TabIndex = 0 + view.Title = panel.GetTitle() + } + } else { + filteredSidePanels := lo.Filter(sidePanels, func(panel panels.ISideListPanel, _ int) bool { return !panel.IsHidden() }) + panelTitles := lo.Map(filteredSidePanels, func(panel panels.ISideListPanel, _ int) string { return panel.GetTitle() }) + for i, panel := range filteredSidePanels { + view := panel.GetView() + view.Tabs = panelTitles + view.TabIndex = i + view.Title = "" + } + } +} + +func nextIntInCycle(sl []ScreenMode, current ScreenMode) ScreenMode { for i, val := range sl { if val == current { if i == len(sl)-1 { @@ -314,7 +336,7 @@ func nextIntInCycle(sl []WindowMaximisation, current WindowMaximisation) WindowM return sl[0] } -func prevIntInCycle(sl []WindowMaximisation, current WindowMaximisation) WindowMaximisation { +func prevIntInCycle(sl []ScreenMode, current ScreenMode) ScreenMode { for i, val := range sl { if val == current { if i > 0 { diff --git a/pkg/gui/views.go b/pkg/gui/views.go index 05b9db5f..060b3a23 100644 --- a/pkg/gui/views.go +++ b/pkg/gui/views.go @@ -105,26 +105,16 @@ func (gui *Gui) createAllViews() error { // when you run a docker container with the -it flags (interactive mode) it adds carriage returns for some reason. This is not docker's fault, it's an os-level default. gui.Views.Main.IgnoreCarriageReturns = true - gui.Views.Project.Title = gui.Tr.ProjectTitle - gui.Views.Services.Highlight = true - gui.Views.Services.Title = gui.Tr.ServicesTitle gui.Views.Services.SelBgColor = selectedLineBgColor gui.Views.Containers.Highlight = true gui.Views.Containers.SelBgColor = selectedLineBgColor - if gui.Config.UserConfig.Gui.ShowAllContainers || !gui.DockerCommand.InDockerComposeProject { - gui.Views.Containers.Title = gui.Tr.ContainersTitle - } else { - gui.Views.Containers.Title = gui.Tr.StandaloneContainersTitle - } gui.Views.Images.Highlight = true - gui.Views.Images.Title = gui.Tr.ImagesTitle gui.Views.Images.SelBgColor = selectedLineBgColor gui.Views.Volumes.Highlight = true - gui.Views.Volumes.Title = gui.Tr.VolumesTitle gui.Views.Volumes.SelBgColor = selectedLineBgColor gui.Views.Options.Frame = false diff --git a/pkg/gui/volumes_panel.go b/pkg/gui/volumes_panel.go index 96085949..33e00392 100644 --- a/pkg/gui/volumes_panel.go +++ b/pkg/gui/volumes_panel.go @@ -50,6 +50,7 @@ func (gui *Gui) getVolumesPanel() *panels.SideListPanel[*commands.Volume] { return a.Name < b.Name }, GetTableCells: presentation.GetVolumeDisplayStrings, + Title: gui.Tr.VolumesTitle, } }