From d70dd5123dfca5248ab9f2396307c46eff96bcb4 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 26 Nov 2023 13:11:50 +0100 Subject: [PATCH] Add config setting for side panel location (left or top) in half screen mode --- docs/Config.md | 1 + pkg/config/user_config.go | 6 ++ .../helpers/window_arrangement_helper.go | 10 ++- .../helpers/window_arrangement_helper_test.go | 64 +++++++++++++++++++ schema/config.json | 5 ++ 5 files changed, 85 insertions(+), 1 deletion(-) diff --git a/docs/Config.md b/docs/Config.md index 2f1f57ecc23..741a2c2b90a 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -40,6 +40,7 @@ gui: sidePanelWidth: 0.3333 # number from 0 to 1 expandFocusedSidePanel: false mainPanelSplitMode: 'flexible' # one of 'horizontal' | 'flexible' | 'vertical' + enlargedSideViewLocation: 'left' # one of 'left' | 'top' language: 'auto' # one of 'auto' | 'en' | 'zh-CN' | 'zh-TW' | 'pl' | 'nl' | 'ja' | 'ko' | 'ru' timeFormat: '02 Jan 06' # https://pkg.go.dev/time#Time.Format shortTimeFormat: '3:04PM' diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 2392d49cf6e..ffc27eb88d6 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -84,6 +84,11 @@ type GuiConfig struct { // - 'vertical': split the window vertically // - 'flexible': (default) split the window horizontally if the window is wide enough, otherwise split vertically MainPanelSplitMode string `yaml:"mainPanelSplitMode" jsonschema:"enum=horizontal,enum=flexible,enum=vertical"` + // How the window is split when in half screen mode (i.e. after hitting '+' once). + // Possible values: + // - 'left': split the window horizontally (side panel on the left, main view on the right) + // - 'top': split the window vertically (side panel on top, main view below) + EnlargedSideViewLocation string `yaml:"enlargedSideViewLocation"` // One of 'auto' (default) | 'en' | 'zh-CN' | 'zh-TW' | 'pl' | 'nl' | 'ja' | 'ko' | 'ru' Language string `yaml:"language" jsonschema:"enum=auto,enum=en,enum=zh-TW,enum=zh-CN,enum=pl,enum=nl,enum=ja,enum=ko,enum=ru"` // Format used when displaying time e.g. commit time. @@ -604,6 +609,7 @@ func GetDefaultConfig() *UserConfig { SidePanelWidth: 0.3333, ExpandFocusedSidePanel: false, MainPanelSplitMode: "flexible", + EnlargedSideViewLocation: "left", Language: "auto", TimeFormat: "02 Jan 06", ShortTimeFormat: time.Kitchen, diff --git a/pkg/gui/controllers/helpers/window_arrangement_helper.go b/pkg/gui/controllers/helpers/window_arrangement_helper.go index 0d9b119e360..8615769dc1b 100644 --- a/pkg/gui/controllers/helpers/window_arrangement_helper.go +++ b/pkg/gui/controllers/helpers/window_arrangement_helper.go @@ -107,6 +107,10 @@ func (self *WindowArrangementHelper) GetWindowDimensions(informationStr string, } func shouldUsePortraitMode(args WindowArrangementArgs) bool { + if args.ScreenMode == types.SCREEN_HALF { + return args.UserConfig.Gui.EnlargedSideViewLocation == "top" + } + switch args.UserConfig.Gui.PortraitMode { case "never": return false @@ -241,7 +245,11 @@ func getMidSectionWeights(args WindowArrangementArgs) (int, int) { } } else { if args.ScreenMode == types.SCREEN_HALF { - mainSectionWeight = 1 + if args.UserConfig.Gui.EnlargedSideViewLocation == "top" { + mainSectionWeight = 2 + } else { + mainSectionWeight = 1 + } } else if args.ScreenMode == types.SCREEN_FULL { mainSectionWeight = 0 } diff --git a/pkg/gui/controllers/helpers/window_arrangement_helper_test.go b/pkg/gui/controllers/helpers/window_arrangement_helper_test.go index 4e299ec2e9f..9c455ff331d 100644 --- a/pkg/gui/controllers/helpers/window_arrangement_helper_test.go +++ b/pkg/gui/controllers/helpers/window_arrangement_helper_test.go @@ -121,6 +121,70 @@ func TestGetWindowDimensions(t *testing.T) { B: information `, }, + { + name: "half screen mode, enlargedSideViewLocation left", + mutateArgs: func(args *WindowArrangementArgs) { + args.Height = 20 // smaller height because we don't more here + args.ScreenMode = types.SCREEN_HALF + args.UserConfig.Gui.EnlargedSideViewLocation = "left" + }, + expected: ` + ╭status──────────────────────────────╮╭main───────────────────────────────╮ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + │ ││ │ + ╰────────────────────────────────────╯╰───────────────────────────────────╯ + A + A: statusSpacer1 + B: information + `, + }, + { + name: "half screen mode, enlargedSideViewLocation top", + mutateArgs: func(args *WindowArrangementArgs) { + args.Height = 20 // smaller height because we don't more here + args.ScreenMode = types.SCREEN_HALF + args.UserConfig.Gui.EnlargedSideViewLocation = "top" + }, + expected: ` + ╭status───────────────────────────────────────────────────────────────────╮ + │ │ + │ │ + │ │ + │ │ + │ │ + ╰─────────────────────────────────────────────────────────────────────────╯ + ╭main─────────────────────────────────────────────────────────────────────╮ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + ╰─────────────────────────────────────────────────────────────────────────╯ + A + A: statusSpacer1 + B: information + `, + }, { name: "search mode", mutateArgs: func(args *WindowArrangementArgs) { diff --git a/schema/config.json b/schema/config.json index 45976cbb920..a5cbc0b6726 100644 --- a/schema/config.json +++ b/schema/config.json @@ -81,6 +81,11 @@ "description": "Sometimes the main window is split in two (e.g. when the selected file has both staged and unstaged changes). This setting controls how the two sections are split.\nOptions are:\n- 'horizontal': split the window horizontally\n- 'vertical': split the window vertically\n- 'flexible': (default) split the window horizontally if the window is wide enough, otherwise split vertically", "default": "flexible" }, + "enlargedSideViewLocation": { + "type": "string", + "description": "How the window is split when in half screen mode (i.e. after hitting '+' once).\nPossible values:\n- 'left': split the window horizontally (side panel on the left, main view on the right)\n- 'top': split the window vertically (side panel on top, main view below)", + "default": "left" + }, "language": { "type": "string", "enum": [