better screen mode approach

pull/408/head
Jesse Duffield 2 years ago
parent 553b9857cd
commit f541b6b55a

@ -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

@ -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
}
}

@ -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 {

@ -62,6 +62,7 @@ func (gui *Gui) getImagesPanel() *panels.SideListPanel[*commands.Image] {
return a.ID < b.ID
},
GetTableCells: presentation.GetImageDisplayStrings,
Title: gui.Tr.ImagesTitle,
}
}

@ -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
}

@ -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,
}
}

@ -78,6 +78,7 @@ func (gui *Gui) getServicesPanel() *panels.SideListPanel[*commands.Service] {
Hide: func() bool {
return !gui.DockerCommand.InDockerComposeProject
},
Title: gui.Tr.ServicesTitle,
}
}

@ -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 {

@ -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

@ -50,6 +50,7 @@ func (gui *Gui) getVolumesPanel() *panels.SideListPanel[*commands.Volume] {
return a.Name < b.Name
},
GetTableCells: presentation.GetVolumeDisplayStrings,
Title: gui.Tr.VolumesTitle,
}
}

Loading…
Cancel
Save