From 9c72d8a2b063154ef838bfb71d831700fa2deccc Mon Sep 17 00:00:00 2001 From: Louis DeLosSantos <louis.delos@gmail.com> Date: Fri, 29 Sep 2023 16:18:45 -0400 Subject: [PATCH] Add ability to force portrait mode A new gui config flag 'portraitMode':<string> is added to influence when LazyGit stacks its UI components on top of one another. The accepted values are 'auto', 'always', 'never'. 'auto': enter portrait mode when terminal becomes narrow enough 'always': always use portrait mode unconditional of the terminal dimensions 'never': never use portraid mode Signed-off-by: Louis DeLosSantos <louis.delos@gmail.com> --- docs/Config.md | 1 + pkg/config/user_config.go | 4 ++++ .../helpers/window_arrangement_helper.go | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index 6d50aca4c..fde550baf 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -85,6 +85,7 @@ gui: skipRewordInEditorWarning: false # for skipping the confirmation before launching the reword editor border: 'rounded' # one of 'single' | 'double' | 'rounded' | 'hidden' animateExplosion: true # shows an explosion animation when nuking the working tree + portraitMode: 'auto' # one of 'auto' | 'never' | 'always' git: paging: colorArg: always diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 027835693..d3d77b666 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -130,6 +130,9 @@ type GuiConfig struct { Border string `yaml:"border"` // If true, show a seriously epic explosion animation when nuking the working tree. AnimateExplosion bool `yaml:"animateExplosion"` + // Whether to stack UI components on top of each other. + // One of 'auto' (default) | 'always' | 'never' + PortraitMode string `yaml:"portraitMode"` } type ThemeConfig struct { @@ -619,6 +622,7 @@ func GetDefaultConfig() *UserConfig { SkipRewordInEditorWarning: false, Border: "rounded", AnimateExplosion: true, + PortraitMode: "auto", }, Git: GitConfig{ Paging: PagingConfig{ diff --git a/pkg/gui/controllers/helpers/window_arrangement_helper.go b/pkg/gui/controllers/helpers/window_arrangement_helper.go index c66233044..7f4261d8b 100644 --- a/pkg/gui/controllers/helpers/window_arrangement_helper.go +++ b/pkg/gui/controllers/helpers/window_arrangement_helper.go @@ -34,14 +34,24 @@ func NewWindowArrangementHelper( const INFO_SECTION_PADDING = " " +func (self *WindowArrangementHelper) shouldUsePortraitMode(width, height int) bool { + switch self.c.UserConfig.Gui.PortraitMode { + case "never": + return false + case "always": + return true + default: // "auto" or any garbage values in PortraitMode value + return width <= 84 && height > 45 + } +} + func (self *WindowArrangementHelper) GetWindowDimensions(informationStr string, appStatus string) map[string]boxlayout.Dimensions { width, height := self.c.GocuiGui().Size() sideSectionWeight, mainSectionWeight := self.getMidSectionWeights() sidePanelsDirection := boxlayout.COLUMN - portraitMode := width <= 84 && height > 45 - if portraitMode { + if self.shouldUsePortraitMode(width, height) { sidePanelsDirection = boxlayout.ROW }