1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2026-06-20 01:19:23 +02:00

Allow customizing the window width/height thresholds for when to use portrait mode (#5452)

This commit is contained in:
Stefan Haller
2026-03-31 13:10:51 +02:00
committed by GitHub
5 changed files with 129 additions and 3 deletions
+10
View File
@@ -298,6 +298,16 @@ gui:
# One of 'auto' (default) | 'always' | 'never' # One of 'auto' (default) | 'always' | 'never'
portraitMode: auto portraitMode: auto
# In 'auto' mode, portrait mode will be used if the window width is less than or
# equal to portraitModeAutoMaxWidth and the window height is greater than or
# equal to portraitModeAutoMinHeight. Unused when portraitMode is not 'auto'.
portraitModeAutoMaxWidth: 84
# In 'auto' mode, portrait mode will be used if the window width is less than or
# equal to portraitModeAutoMaxWidth and the window height is greater than or
# equal to portraitModeAutoMinHeight. Unused when portraitMode is not 'auto'.
portraitModeAutoMinHeight: 46
# How things are filtered when typing '/'. # How things are filtered when typing '/'.
# One of 'substring' (default) | 'fuzzy' # One of 'substring' (default) | 'fuzzy'
filterMode: substring filterMode: substring
+6
View File
@@ -187,6 +187,10 @@ type GuiConfig struct {
// Whether to stack UI components on top of each other. // Whether to stack UI components on top of each other.
// One of 'auto' (default) | 'always' | 'never' // One of 'auto' (default) | 'always' | 'never'
PortraitMode string `yaml:"portraitMode"` PortraitMode string `yaml:"portraitMode"`
// In 'auto' mode, portrait mode will be used if the window width is less than or equal to portraitModeAutoMaxWidth and the window height is greater than or equal to portraitModeAutoMinHeight. Unused when portraitMode is not 'auto'.
PortraitModeAutoMaxWidth int `yaml:"portraitModeAutoMaxWidth"`
// In 'auto' mode, portrait mode will be used if the window width is less than or equal to portraitModeAutoMaxWidth and the window height is greater than or equal to portraitModeAutoMinHeight. Unused when portraitMode is not 'auto'.
PortraitModeAutoMinHeight int `yaml:"portraitModeAutoMinHeight"`
// How things are filtered when typing '/'. // How things are filtered when typing '/'.
// One of 'substring' (default) | 'fuzzy' // One of 'substring' (default) | 'fuzzy'
FilterMode string `yaml:"filterMode" jsonschema:"enum=substring,enum=fuzzy"` FilterMode string `yaml:"filterMode" jsonschema:"enum=substring,enum=fuzzy"`
@@ -820,6 +824,8 @@ func GetDefaultConfig() *UserConfig {
Border: "rounded", Border: "rounded",
AnimateExplosion: true, AnimateExplosion: true,
PortraitMode: "auto", PortraitMode: "auto",
PortraitModeAutoMaxWidth: 84,
PortraitModeAutoMinHeight: 46,
FilterMode: "substring", FilterMode: "substring",
Spinner: SpinnerConfig{ Spinner: SpinnerConfig{
Frames: []string{"|", "/", "-", "\\"}, Frames: []string{"|", "/", "-", "\\"},
@@ -116,7 +116,8 @@ func shouldUsePortraitMode(args WindowArrangementArgs) bool {
case "always": case "always":
return true return true
default: // "auto" or any garbage values in PortraitMode value default: // "auto" or any garbage values in PortraitMode value
return args.Width <= 84 && args.Height > 45 return args.Width <= args.UserConfig.Gui.PortraitModeAutoMaxWidth &&
args.Height >= args.UserConfig.Gui.PortraitModeAutoMinHeight
} }
} }
@@ -285,7 +285,7 @@ func TestGetWindowDimensions(t *testing.T) {
{ {
name: "half screen mode, enlargedSideViewLocation left", name: "half screen mode, enlargedSideViewLocation left",
mutateArgs: func(args *WindowArrangementArgs) { mutateArgs: func(args *WindowArrangementArgs) {
args.Height = 20 // smaller height because we don't more here args.Height = 20 // smaller height because we don't need more here
args.ScreenMode = types.SCREEN_HALF args.ScreenMode = types.SCREEN_HALF
args.UserConfig.Gui.EnlargedSideViewLocation = "left" args.UserConfig.Gui.EnlargedSideViewLocation = "left"
}, },
@@ -317,7 +317,7 @@ func TestGetWindowDimensions(t *testing.T) {
{ {
name: "half screen mode, enlargedSideViewLocation top", name: "half screen mode, enlargedSideViewLocation top",
mutateArgs: func(args *WindowArrangementArgs) { mutateArgs: func(args *WindowArrangementArgs) {
args.Height = 20 // smaller height because we don't more here args.Height = 20 // smaller height because we don't need more here
args.ScreenMode = types.SCREEN_HALF args.ScreenMode = types.SCREEN_HALF
args.UserConfig.Gui.EnlargedSideViewLocation = "top" args.UserConfig.Gui.EnlargedSideViewLocation = "top"
}, },
@@ -346,6 +346,105 @@ func TestGetWindowDimensions(t *testing.T) {
B: information B: information
`, `,
}, },
{
name: "portrait auto mode, enabled",
mutateArgs: func(args *WindowArrangementArgs) {
args.Width = 50
args.Height = 20
args.UserConfig.Gui.PortraitModeAutoMaxWidth = 50
args.UserConfig.Gui.PortraitModeAutoMinHeight = 20
},
expected: `
<status──────────────────────────────────────────>
╭files───────────────────────────────────────────╮
│ │
╰────────────────────────────────────────────────╯
<branches────────────────────────────────────────>
<commits─────────────────────────────────────────>
<stash───────────────────────────────────────────>
╭main────────────────────────────────────────────╮
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
╰────────────────────────────────────────────────╯
<options─────────────────────────────>A<B────────>
A: statusSpacer1
B: information
`,
},
{
name: "portrait auto mode, disabled because width is too large",
mutateArgs: func(args *WindowArrangementArgs) {
args.Width = 50
args.Height = 20
args.UserConfig.Gui.PortraitModeAutoMaxWidth = 49
args.UserConfig.Gui.PortraitModeAutoMinHeight = 20
},
expected: `
<status─────────>╭main───────────────────────────╮
╭files──────────╮│ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
╰───────────────╯│ │
<branches───────>│ │
<commits────────>│ │
<stash──────────>╰───────────────────────────────╯
<options─────────────────────────────>A<B────────>
A: statusSpacer1
B: information
`,
},
{
name: "portrait auto mode, disabled because height is too small",
mutateArgs: func(args *WindowArrangementArgs) {
args.Width = 50
args.Height = 20
args.UserConfig.Gui.PortraitModeAutoMaxWidth = 50
args.UserConfig.Gui.PortraitModeAutoMinHeight = 21
},
expected: `
<status─────────>╭main───────────────────────────╮
╭files──────────╮│ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
╰───────────────╯│ │
<branches───────>│ │
<commits────────>│ │
<stash──────────>╰───────────────────────────────╯
<options─────────────────────────────>A<B────────>
A: statusSpacer1
B: information
`,
},
{ {
name: "search mode", name: "search mode",
mutateArgs: func(args *WindowArrangementArgs) { mutateArgs: func(args *WindowArrangementArgs) {
+10
View File
@@ -769,6 +769,16 @@
"description": "Whether to stack UI components on top of each other.\nOne of 'auto' (default) | 'always' | 'never'", "description": "Whether to stack UI components on top of each other.\nOne of 'auto' (default) | 'always' | 'never'",
"default": "auto" "default": "auto"
}, },
"portraitModeAutoMaxWidth": {
"type": "integer",
"description": "In 'auto' mode, portrait mode will be used if the window width is less than or equal to portraitModeAutoMaxWidth and the window height is greater than or equal to portraitModeAutoMinHeight. Unused when portraitMode is not 'auto'.",
"default": 84
},
"portraitModeAutoMinHeight": {
"type": "integer",
"description": "In 'auto' mode, portrait mode will be used if the window width is less than or equal to portraitModeAutoMaxWidth and the window height is greater than or equal to portraitModeAutoMinHeight. Unused when portraitMode is not 'auto'.",
"default": 46
},
"filterMode": { "filterMode": {
"type": "string", "type": "string",
"enum": [ "enum": [