fixup! WIP Add showDivergenceFromBaseBranch config

This commit is contained in:
Stefan Haller 2024-05-15 19:36:41 +02:00 committed by Jesse Duffield
parent 4d2177725f
commit b23ea3b190
3 changed files with 31 additions and 9 deletions

View file

@ -128,7 +128,7 @@ type GuiConfig struct {
// If true, show commit hashes alongside branch names in the branches view. // If true, show commit hashes alongside branch names in the branches view.
ShowBranchCommitHash bool `yaml:"showBranchCommitHash"` ShowBranchCommitHash bool `yaml:"showBranchCommitHash"`
// Whether to show the divergence from the base branch in the branches view. // 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 // Height of the command log view
CommandLogSize int `yaml:"commandLogSize" jsonschema:"minimum=0"` CommandLogSize int `yaml:"commandLogSize" jsonschema:"minimum=0"`
// Whether to split the main window when viewing file changes. // Whether to split the main window when viewing file changes.
@ -683,7 +683,7 @@ func GetDefaultConfig() *UserConfig {
ShowFileIcons: true, ShowFileIcons: true,
CommitHashLength: 8, CommitHashLength: 8,
ShowBranchCommitHash: false, ShowBranchCommitHash: false,
ShowDivergenceFromBaseBranch: "onlyBehind", ShowDivergenceFromBaseBranch: "onlyBehindArrowAndNumber",
CommandLogSize: 8, CommandLogSize: 8,
SplitDiff: "auto", SplitDiff: "auto",
SkipRewordInEditorWarning: false, SkipRewordInEditorWarning: false,

View file

@ -173,13 +173,21 @@ func BranchStatus(
} }
if userConfig.Gui.ShowDivergenceFromBaseBranch != "off" { if userConfig.Gui.ShowDivergenceFromBaseBranch != "off" {
showNumbers := userConfig.Gui.ShowDivergenceFromBaseBranch == "onlyBehindArrowAndNumber" ||
userConfig.Gui.ShowDivergenceFromBaseBranch == "behindAndAheadArrowsAndNumbers"
behind := branch.BehindBaseBranch.Load() behind := branch.BehindBaseBranch.Load()
if userConfig.Gui.ShowDivergenceFromBaseBranch == "onlyBehind" { if userConfig.Gui.ShowDivergenceFromBaseBranch == "onlyBehindArrow" ||
userConfig.Gui.ShowDivergenceFromBaseBranch == "onlyBehindArrowAndNumber" {
if behind != 0 { if behind != 0 {
if result != "" { if result != "" {
result += " " result += " "
} }
result += style.FgCyan.Sprintf("↓%d", behind) if showNumbers {
result += style.FgCyan.Sprintf("↓%d", behind)
} else {
result += style.FgCyan.Sprintf("↓")
}
} }
} else { } else {
ahead := branch.AheadOfBaseBranch.Load() ahead := branch.AheadOfBaseBranch.Load()
@ -188,11 +196,23 @@ func BranchStatus(
result += " " result += " "
} }
if ahead != 0 && behind != 0 { 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 { } else if behind != 0 {
result += style.FgCyan.Sprintf("↓%d", behind) if showNumbers {
result += style.FgCyan.Sprintf("↓%d", behind)
} else {
result += style.FgCyan.Sprint("↓")
}
} else { } else {
result += style.FgCyan.Sprintf("↑%d", ahead) if showNumbers {
result += style.FgCyan.Sprintf("↑%d", ahead)
} else {
result += style.FgCyan.Sprint("↑")
}
} }
} }
} }

View file

@ -323,8 +323,10 @@
"type": "string", "type": "string",
"enum": [ "enum": [
"off", "off",
"onlyBehind", "onlyBehindArrow",
"behindAndAhead" "onlyBehindArrowAndNumber",
"behindAndAheadArrows",
"behindAndAheadArrowsAndNumbers"
], ],
"description": "Whether to show the divergence from the base branch in the branches view.", "description": "Whether to show the divergence from the base branch in the branches view.",
"default": "onlyBehind" "default": "onlyBehind"