Skip to content

Commit

Permalink
Add config setting for splitting window vertically in half screen mode (
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaller authored Jan 9, 2024
2 parents 15da702 + d70dd51 commit 33f933b
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion pkg/gui/controllers/helpers/window_arrangement_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
64 changes: 64 additions & 0 deletions pkg/gui/controllers/helpers/window_arrangement_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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───────────────────────────────╮
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
╰────────────────────────────────────╯╰───────────────────────────────────╯
<options──────────────────────────────────────────────────────>A<B────────>
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─────────────────────────────────────────────────────────────────────╮
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
╰─────────────────────────────────────────────────────────────────────────╯
<options──────────────────────────────────────────────────────>A<B────────>
A: statusSpacer1
B: information
`,
},
{
name: "search mode",
mutateArgs: func(args *WindowArrangementArgs) {
Expand Down
5 changes: 5 additions & 0 deletions schema/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit 33f933b

Please sign in to comment.