From b23ea3b19072354938d408f3fcb9cdb460c3a895 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 15 May 2024 19:36:41 +0200 Subject: [PATCH] fixup! WIP Add showDivergenceFromBaseBranch config --- pkg/config/user_config.go | 4 ++-- pkg/gui/presentation/branches.go | 30 +++++++++++++++++++++++++----- schema/config.json | 6 ++++-- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index fc8cddffb..8f8a47ed8 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -128,7 +128,7 @@ type GuiConfig struct { // If true, show commit hashes alongside branch names in the branches view. ShowBranchCommitHash bool `yaml:"showBranchCommitHash"` // Whether to show the divergence from the base branch in the branches view. - ShowDivergenceFromBaseBranch string `yaml:"showDivergenceFromBaseBranch" jsonschema:"enum=off,enum=onlyBehind,enum=behindAndAhead"` + ShowDivergenceFromBaseBranch string `yaml:"showDivergenceFromBaseBranch" jsonschema:"enum=off,enum=onlyBehindArrow,enum=onlyBehindArrowAndNumber,enum=behindAndAheadArrows,enum=behindAndAheadArrowsAndNumbers"` // Height of the command log view CommandLogSize int `yaml:"commandLogSize" jsonschema:"minimum=0"` // Whether to split the main window when viewing file changes. @@ -683,7 +683,7 @@ func GetDefaultConfig() *UserConfig { ShowFileIcons: true, CommitHashLength: 8, ShowBranchCommitHash: false, - ShowDivergenceFromBaseBranch: "onlyBehind", + ShowDivergenceFromBaseBranch: "onlyBehindArrowAndNumber", CommandLogSize: 8, SplitDiff: "auto", SkipRewordInEditorWarning: false, diff --git a/pkg/gui/presentation/branches.go b/pkg/gui/presentation/branches.go index 8829821df..4013dda41 100644 --- a/pkg/gui/presentation/branches.go +++ b/pkg/gui/presentation/branches.go @@ -173,13 +173,21 @@ func BranchStatus( } if userConfig.Gui.ShowDivergenceFromBaseBranch != "off" { + showNumbers := userConfig.Gui.ShowDivergenceFromBaseBranch == "onlyBehindArrowAndNumber" || + userConfig.Gui.ShowDivergenceFromBaseBranch == "behindAndAheadArrowsAndNumbers" + behind := branch.BehindBaseBranch.Load() - if userConfig.Gui.ShowDivergenceFromBaseBranch == "onlyBehind" { + if userConfig.Gui.ShowDivergenceFromBaseBranch == "onlyBehindArrow" || + userConfig.Gui.ShowDivergenceFromBaseBranch == "onlyBehindArrowAndNumber" { if behind != 0 { if result != "" { result += " " } - result += style.FgCyan.Sprintf("↓%d", behind) + if showNumbers { + result += style.FgCyan.Sprintf("↓%d", behind) + } else { + result += style.FgCyan.Sprintf("↓") + } } } else { ahead := branch.AheadOfBaseBranch.Load() @@ -188,11 +196,23 @@ func BranchStatus( result += " " } if ahead != 0 && behind != 0 { - result += style.FgCyan.Sprintf("↓%d↑%d", behind, ahead) + if showNumbers { + result += style.FgCyan.Sprintf("↓%d↑%d", behind, ahead) + } else { + result += style.FgCyan.Sprint("↕") + } } else if behind != 0 { - result += style.FgCyan.Sprintf("↓%d", behind) + if showNumbers { + result += style.FgCyan.Sprintf("↓%d", behind) + } else { + result += style.FgCyan.Sprint("↓") + } } else { - result += style.FgCyan.Sprintf("↑%d", ahead) + if showNumbers { + result += style.FgCyan.Sprintf("↑%d", ahead) + } else { + result += style.FgCyan.Sprint("↑") + } } } } diff --git a/schema/config.json b/schema/config.json index 1eb9d3aa4..eebc58070 100644 --- a/schema/config.json +++ b/schema/config.json @@ -323,8 +323,10 @@ "type": "string", "enum": [ "off", - "onlyBehind", - "behindAndAhead" + "onlyBehindArrow", + "onlyBehindArrowAndNumber", + "behindAndAheadArrows", + "behindAndAheadArrowsAndNumbers" ], "description": "Whether to show the divergence from the base branch in the branches view.", "default": "onlyBehind"