From 42acc552568ad5a1f643a9efe075c3a493d9f674 Mon Sep 17 00:00:00 2001 From: Jayson Rhynas Date: Thu, 29 Aug 2024 12:21:20 -0400 Subject: [PATCH] Added configuration options to hide side panels Every panel except "project" can be hidden. All panels are visible by default. initiallyFocusedViewName defaults to "project" if "services" and "containers" are hidden --- docs/Config.md | 7 +++++++ pkg/config/app_config.go | 19 +++++++++++++++++++ pkg/gui/arrangement.go | 16 ++++++++++++---- pkg/gui/containers_panel.go | 1 + pkg/gui/gui.go | 9 +++++++-- pkg/gui/images_panel.go | 1 + pkg/gui/networks_panel.go | 1 + pkg/gui/panels/side_list_panel.go | 7 +++++++ pkg/gui/services_panel.go | 1 + pkg/gui/volumes_panel.go | 1 + 10 files changed, 57 insertions(+), 6 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index e43bdf904..836f96825 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -48,6 +48,13 @@ gui: wrapMainPanel: true # Side panel width as a ratio of the screen's width sidePanelWidth: 0.333 + # Determines whether each side panel is shown or not + sidePanelVisibility: + services: true + containers: true + images: true + volumes: true + networks: true # Determines whether we show the bottom line (the one containing keybinding # info and the status of the app). showBottomLine: true diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 9c0ad4745..eab120c8d 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -74,6 +74,15 @@ type ThemeConfig struct { OptionsTextColor []string `yaml:"optionsTextColor,omitempty"` } +// SidePanelVisibilityConfig is for toggling visiblity of side panels. +type SidePanelVisibilityConfig struct { + Services bool `yaml:"services,omitempty"` + Containers bool `yaml:"containers,omitempty"` + Images bool `yaml:"images,omitempty"` + Volumes bool `yaml:"volumes,omitempty"` + Networks bool `yaml:"networks,omitempty"` +} + // GuiConfig is for configuring visual things like colors and whether we show or // hide things type GuiConfig struct { @@ -123,6 +132,9 @@ type GuiConfig struct { // If 0.333, then the side panels will be 1/3 of the screen's width SidePanelWidth float64 `yaml:"sidePanelWidth"` + // Determines which side panels to show. Each panel defaults to `true` (visible). + SidePanelVisibility SidePanelVisibilityConfig `yaml:"sidePanelVisibility,omitempty"` + // Determines whether we show the bottom line (the one containing keybinding // info and the status of the app). ShowBottomLine bool `yaml:"showBottomLine"` @@ -373,6 +385,13 @@ func GetDefaultConfig() UserConfig { WrapMainPanel: true, LegacySortContainers: false, SidePanelWidth: 0.3333, + SidePanelVisibility: SidePanelVisibilityConfig{ + Services: true, + Containers: true, + Images: true, + Volumes: true, + Networks: true, + }, ShowBottomLine: true, ExpandFocusedSidePanel: false, ScreenMode: "normal", diff --git a/pkg/gui/arrangement.go b/pkg/gui/arrangement.go index bcd4aa1cc..06edaf06f 100644 --- a/pkg/gui/arrangement.go +++ b/pkg/gui/arrangement.go @@ -175,11 +175,19 @@ func (gui *Gui) sidePanelChildren(width int, height int) []*boxlayout.Box { return defaultBox } - return append([]*boxlayout.Box{ - { + projectBox := &boxlayout.Box{ + Window: sideWindowNames[0], + Size: 3, + } + if len(sideWindowNames) == 1 { + projectBox = &boxlayout.Box{ Window: sideWindowNames[0], - Size: 3, - }, + Weight: 1, + } + } + + return append([]*boxlayout.Box{ + projectBox, }, lo.Map(sideWindowNames[1:], func(window string, _ int) *boxlayout.Box { return accordionBox(&boxlayout.Box{Window: window, Weight: 1}) })...) diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index 92aa95b37..11e311320 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -96,6 +96,7 @@ func (gui *Gui) getContainersPanel() *panels.SideListPanel[*commands.Container] return true }, + ConfigHidden: !gui.Config.UserConfig.Gui.SidePanelVisibility.Containers, GetTableCells: func(container *commands.Container) []string { return presentation.GetContainerDisplayStrings(&gui.Config.UserConfig.Gui, container) }, diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index fa6199f31..cb1f7f0be 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -459,10 +459,15 @@ func (gui *Gui) ShouldRefresh(key string) bool { } func (gui *Gui) initiallyFocusedViewName() string { - if gui.DockerCommand.InDockerComposeProject { + visiblePanels := gui.Config.UserConfig.Gui.SidePanelVisibility + + if gui.DockerCommand.InDockerComposeProject && visiblePanels.Services { return "services" + } else if visiblePanels.Containers { + return "containers" + } else { + return "project" } - return "containers" } func (gui *Gui) IgnoreStrings() []string { diff --git a/pkg/gui/images_panel.go b/pkg/gui/images_panel.go index 7b0d56437..8680b5c16 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, + ConfigHidden: !gui.Config.UserConfig.Gui.SidePanelVisibility.Images, } } diff --git a/pkg/gui/networks_panel.go b/pkg/gui/networks_panel.go index 4702d35dd..4962d95cf 100644 --- a/pkg/gui/networks_panel.go +++ b/pkg/gui/networks_panel.go @@ -44,6 +44,7 @@ func (gui *Gui) getNetworksPanel() *panels.SideListPanel[*commands.Network] { return a.Name < b.Name }, GetTableCells: presentation.GetNetworkDisplayStrings, + ConfigHidden: !gui.Config.UserConfig.Gui.SidePanelVisibility.Networks, } } diff --git a/pkg/gui/panels/side_list_panel.go b/pkg/gui/panels/side_list_panel.go index 2473e2ce2..c31b6a6af 100644 --- a/pkg/gui/panels/side_list_panel.go +++ b/pkg/gui/panels/side_list_panel.go @@ -57,6 +57,9 @@ type SideListPanel[T comparable] struct { // set this to true if you don't want to allow manual filtering via '/' DisableFilter bool + // set to true if config file wants this panel to be hidden + ConfigHidden bool + // This can be nil if you want to always show the panel Hide func() bool } @@ -263,6 +266,10 @@ func (self *SideListPanel[T]) IsFilterDisabled() bool { } func (self *SideListPanel[T]) IsHidden() bool { + if self.ConfigHidden { + return true + } + if self.Hide == nil { return false } diff --git a/pkg/gui/services_panel.go b/pkg/gui/services_panel.go index c9dd4d1d8..4a4ca1fdc 100644 --- a/pkg/gui/services_panel.go +++ b/pkg/gui/services_panel.go @@ -77,6 +77,7 @@ func (gui *Gui) getServicesPanel() *panels.SideListPanel[*commands.Service] { GetTableCells: func(service *commands.Service) []string { return presentation.GetServiceDisplayStrings(&gui.Config.UserConfig.Gui, service) }, + ConfigHidden: !gui.Config.UserConfig.Gui.SidePanelVisibility.Services, Hide: func() bool { return !gui.DockerCommand.InDockerComposeProject }, diff --git a/pkg/gui/volumes_panel.go b/pkg/gui/volumes_panel.go index 960859497..863dadfd3 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, + ConfigHidden: !gui.Config.UserConfig.Gui.SidePanelVisibility.Volumes, } }