1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

Remove ColoredBranchStatus and branchStatusColor

Previously the entire status was colored in a single color, so the API made
sense. This is going to change in the next commit, so now we must include the
color in the string returned from BranchStatus(), which means that callers who
need to do hit detection or measure the length need to decolorize it.

While we're at it, switch the order of ↑3↓7 to ↓7↑3. For some reason that I
can't really explain I find it more logical this way. The software out there is
pretty undecided about it, it seems: VS Code puts ↓7 first, and so does the
shell prompt that comes with git; git status and git branch -v put "ahead" first
though. Shrug.
This commit is contained in:
Stefan Haller
2024-05-02 20:05:16 +02:00
parent 8c385731f7
commit 5b613f5bc7
10 changed files with 26 additions and 48 deletions

View File

@ -56,7 +56,7 @@ func getBranchDisplayStrings(
// Recency is always three characters, plus one for the space
availableWidth := viewWidth - 4
if len(branchStatus) > 0 {
availableWidth -= runewidth.StringWidth(branchStatus) + 1
availableWidth -= runewidth.StringWidth(utils.Decolorise(branchStatus)) + 1
}
if icons.IsIconEnabled() {
availableWidth -= 2 // one for the icon, one for the space
@ -89,8 +89,7 @@ func getBranchDisplayStrings(
coloredName = fmt.Sprintf("%s %s", coloredName, style.FgDefault.Sprint(worktreeIcon))
}
if len(branchStatus) > 0 {
coloredStatus := branchStatusColor(b, itemOperation).Sprint(branchStatus)
coloredName = fmt.Sprintf("%s %s", coloredName, coloredStatus)
coloredName = fmt.Sprintf("%s %s", coloredName, branchStatus)
}
recencyColor := style.FgCyan
@ -144,30 +143,6 @@ func GetBranchTextStyle(name string) style.TextStyle {
}
}
func branchStatusColor(branch *models.Branch, itemOperation types.ItemOperation) style.TextStyle {
colour := style.FgYellow
if itemOperation != types.ItemOperationNone {
colour = style.FgCyan
} else if branch.UpstreamGone {
colour = style.FgRed
} else if branch.MatchesUpstream() {
colour = style.FgGreen
} else if branch.RemoteBranchNotStoredLocally() {
colour = style.FgMagenta
}
return colour
}
func ColoredBranchStatus(
branch *models.Branch,
itemOperation types.ItemOperation,
tr *i18n.TranslationSet,
userConfig *config.UserConfig,
) string {
return branchStatusColor(branch, itemOperation).Sprint(BranchStatus(branch, itemOperation, tr, time.Now(), userConfig))
}
func BranchStatus(
branch *models.Branch,
itemOperation types.ItemOperation,
@ -177,7 +152,7 @@ func BranchStatus(
) string {
itemOperationStr := ItemOperationToString(itemOperation, tr)
if itemOperationStr != "" {
return itemOperationStr + " " + utils.Loader(now, userConfig.Gui.Spinner)
return style.FgCyan.Sprintf("%s %s", itemOperationStr, utils.Loader(now, userConfig.Gui.Spinner))
}
if !branch.IsTrackingRemote() {
@ -185,25 +160,27 @@ func BranchStatus(
}
if branch.UpstreamGone {
return tr.UpstreamGone
return style.FgRed.Sprint(tr.UpstreamGone)
}
if branch.MatchesUpstream() {
return "✓"
return style.FgGreen.Sprint("✓")
}
if branch.RemoteBranchNotStoredLocally() {
return "?"
return style.FgMagenta.Sprint("?")
}
result := ""
if branch.IsAheadForPull() {
result = fmt.Sprintf("↑%s", branch.AheadForPull)
if branch.IsBehindForPull() && branch.IsAheadForPull() {
return style.FgYellow.Sprintf("↓%s↑%s", branch.BehindForPull, branch.AheadForPull)
}
if branch.IsBehindForPull() {
result = fmt.Sprintf("%s↓%s", result, branch.BehindForPull)
return style.FgYellow.Sprintf("↓%s", branch.BehindForPull)
}
if branch.IsAheadForPull() {
return style.FgYellow.Sprintf("↑%s", branch.AheadForPull)
}
return result
return ""
}
func SetCustomBranches(customBranchColors map[string]string) {