From 1cf632002eda454763274296939211f43d29d840 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 27 Jul 2026 17:45:59 +0200 Subject: [PATCH] Make CurrentPagerName always return a name We don't want callers to need any additional logic, so pass in the translation set so that the function can decide what static text to return. This allows us to get rid of the CurrentPagerUsesGitConfigDiff method which is in the way for the refactoring we're about to do. --- pkg/config/pager_config.go | 29 ++++++++++++------------ pkg/config/pager_config_test.go | 17 ++++++++++---- pkg/gui/controllers/global_controller.go | 9 +------- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/pkg/config/pager_config.go b/pkg/config/pager_config.go index 01f92f584..b6514f671 100644 --- a/pkg/config/pager_config.go +++ b/pkg/config/pager_config.go @@ -4,6 +4,7 @@ import ( "strconv" "strings" + "github.com/jesseduffield/lazygit/pkg/i18n" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -93,23 +94,21 @@ func (self *PagerConfig) CurrentPagerIndex() (int, int) { } // CurrentPagerName returns a name for the current pager, suitable for showing -// to the user. It returns an empty string if no name can be derived; callers -// should substitute a localized fallback in that case. -func (self *PagerConfig) CurrentPagerName() string { +// to the user. +func (self *PagerConfig) CurrentPagerName(tr *i18n.TranslationSet) string { + name := "" currentPagerConfig := self.currentPagerConfig() - if currentPagerConfig == nil { - return "" + if currentPagerConfig != nil { + name = currentPagerConfig.displayName() } - return currentPagerConfig.displayName() -} - -// CurrentPagerUsesGitConfigDiff reports whether the current pager defers to -// git's own external diff config. Such an entry has no name we can derive (the -// actual command may even vary per file via .gitattributes), so callers show a -// generic label rather than treating it like the default no-pager entry. -func (self *PagerConfig) CurrentPagerUsesGitConfigDiff() bool { - currentPagerConfig := self.currentPagerConfig() - return currentPagerConfig != nil && currentPagerConfig.UseExternalDiffGitConfig + if name == "" { + if currentPagerConfig != nil && currentPagerConfig.UseExternalDiffGitConfig { + name = tr.ExternalDiffPagerName + } else { + name = tr.DefaultPagerName + } + } + return name } func (self *PagingConfig) displayName() string { diff --git a/pkg/config/pager_config_test.go b/pkg/config/pager_config_test.go index 7267b9228..117044afc 100644 --- a/pkg/config/pager_config_test.go +++ b/pkg/config/pager_config_test.go @@ -3,10 +3,13 @@ package config import ( "testing" + "github.com/jesseduffield/lazygit/pkg/i18n" "github.com/stretchr/testify/assert" ) func TestCurrentPagerName(t *testing.T) { + tr := i18n.EnglishTranslationSet() + scenarios := []struct { name string pager PagingConfig @@ -33,9 +36,14 @@ func TestCurrentPagerName(t *testing.T) { expected: "difft", }, { - name: "no name can be derived", + name: "no name can be derived for external diff", pager: PagingConfig{UseExternalDiffGitConfig: true}, - expected: "", + expected: tr.ExternalDiffPagerName, + }, + { + name: "no name can be derived for raw diff", + pager: PagingConfig{}, + expected: tr.DefaultPagerName, }, } @@ -45,7 +53,7 @@ func TestCurrentPagerName(t *testing.T) { userConfig.Git.Pagers = []PagingConfig{s.pager} config := NewPagerConfig(func() *UserConfig { return userConfig }) - assert.Equal(t, s.expected, config.CurrentPagerName()) + assert.Equal(t, s.expected, config.CurrentPagerName(tr)) }) } } @@ -53,7 +61,8 @@ func TestCurrentPagerName(t *testing.T) { func TestCurrentPagerNameWithoutPagers(t *testing.T) { config := NewPagerConfig(func() *UserConfig { return &UserConfig{} }) - assert.Equal(t, "", config.CurrentPagerName()) + tr := i18n.EnglishTranslationSet() + assert.Equal(t, tr.DefaultPagerName, config.CurrentPagerName(tr)) } func TestCyclePagers(t *testing.T) { diff --git a/pkg/gui/controllers/global_controller.go b/pkg/gui/controllers/global_controller.go index 77ef29070..3d3f77cd5 100644 --- a/pkg/gui/controllers/global_controller.go +++ b/pkg/gui/controllers/global_controller.go @@ -195,14 +195,7 @@ func (self *GlobalController) onPagerChanged() { pagerConfig := self.c.State().GetPagerConfig() current, total := pagerConfig.CurrentPagerIndex() - name := pagerConfig.CurrentPagerName() - if name == "" { - if pagerConfig.CurrentPagerUsesGitConfigDiff() { - name = self.c.Tr.ExternalDiffPagerName - } else { - name = self.c.Tr.DefaultPagerName - } - } + name := pagerConfig.CurrentPagerName(self.c.Tr) self.c.Toast(utils.ResolvePlaceholderString(self.c.Tr.SelectedPager, map[string]string{ "name": name, "current": strconv.Itoa(current + 1),