From 5868750abaa6de4d32909f99253765361f77ef30 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 16 Jul 2023 17:15:19 +1000 Subject: [PATCH] Move status panel presentation logic into presentation package --- pkg/gui/controllers/helpers/refresh_helper.go | 17 +--------- pkg/gui/presentation/status.go | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 pkg/gui/presentation/status.go diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index d3b5aae5f..310958ffd 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -16,7 +16,6 @@ import ( "github.com/jesseduffield/lazygit/pkg/gui/filetree" "github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts" "github.com/jesseduffield/lazygit/pkg/gui/presentation" - "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -626,24 +625,10 @@ func (self *RefreshHelper) refreshStatus() { // need to wait for branches to refresh return } - status := "" - - if currentBranch.IsRealBranch() { - status += presentation.ColoredBranchStatus(currentBranch, self.c.Tr) + " " - } workingTreeState := self.c.Git().Status.WorkingTreeState() - if workingTreeState != enums.REBASE_MODE_NONE { - status += style.FgYellow.Sprintf("(%s) ", presentation.FormatWorkingTreeStateLower(self.c.Tr, workingTreeState)) - } - - name := presentation.GetBranchTextStyle(currentBranch.Name).Sprint(currentBranch.Name) - repoName := utils.GetCurrentRepoName() mainWorktreeName := self.worktreeHelper.GetMainWorktreeName() - if repoName != mainWorktreeName { - repoName = fmt.Sprintf("%s(%s)", mainWorktreeName, style.FgBlue.Sprint(repoName)) - } - status += fmt.Sprintf("%s → %s ", repoName, name) + status := presentation.FormatStatus(currentBranch, mainWorktreeName, workingTreeState, self.c.Tr) self.c.SetViewContent(self.c.Views().Status, status) } diff --git a/pkg/gui/presentation/status.go b/pkg/gui/presentation/status.go new file mode 100644 index 000000000..e0288406f --- /dev/null +++ b/pkg/gui/presentation/status.go @@ -0,0 +1,32 @@ +package presentation + +import ( + "fmt" + + "github.com/jesseduffield/lazygit/pkg/commands/models" + "github.com/jesseduffield/lazygit/pkg/commands/types/enums" + "github.com/jesseduffield/lazygit/pkg/gui/style" + "github.com/jesseduffield/lazygit/pkg/i18n" + "github.com/jesseduffield/lazygit/pkg/utils" +) + +func FormatStatus(currentBranch *models.Branch, mainWorktreeName string, workingTreeState enums.RebaseMode, tr *i18n.TranslationSet) string { + status := "" + + if currentBranch.IsRealBranch() { + status += ColoredBranchStatus(currentBranch, tr) + " " + } + + if workingTreeState != enums.REBASE_MODE_NONE { + status += style.FgYellow.Sprintf("(%s) ", FormatWorkingTreeStateLower(tr, workingTreeState)) + } + + name := GetBranchTextStyle(currentBranch.Name).Sprint(currentBranch.Name) + repoName := utils.GetCurrentRepoName() + if repoName != mainWorktreeName { + repoName = fmt.Sprintf("%s(%s)", mainWorktreeName, style.FgCyan.Sprint(repoName)) + } + status += fmt.Sprintf("%s → %s ", repoName, name) + + return status +}