Add a helper function for formatting list section headers

We want to change their design, and we want to do it only in one place.
This commit is contained in:
Stefan Haller 2026-07-25 08:50:00 +02:00
parent 67c81c5b14
commit 22db808a01
4 changed files with 11 additions and 8 deletions

View file

@ -1,6 +1,7 @@
package context
import (
"fmt"
"strings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
@ -9,6 +10,10 @@ import (
"golang.org/x/exp/slices"
)
func formatListSectionHeader(label string) string {
return fmt.Sprintf("--- %s ---", label)
}
type NonModelItem struct {
// Where in the model this should be inserted
Index int

View file

@ -1,7 +1,6 @@
package context
import (
"fmt"
"log"
"strings"
"sync/atomic"
@ -72,7 +71,7 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
if c.Model().WorkingTreeStateAtLastCommitRefresh.Rebasing {
result = append(result, &NonModelItem{
Index: 0,
Content: fmt.Sprintf("--- %s ---", c.Tr.PendingRebaseTodosSectionHeader),
Content: formatListSectionHeader(c.Tr.PendingRebaseTodosSectionHeader),
})
}
@ -91,7 +90,7 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
c.Tr.PendingRevertsSectionHeader)
result = append(result, &NonModelItem{
Index: firstCherryPickOrRevertTodo,
Content: fmt.Sprintf("--- %s ---", label),
Content: formatListSectionHeader(label),
})
}
@ -104,7 +103,7 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
}
result = append(result, &NonModelItem{
Index: firstRealCommit,
Content: fmt.Sprintf("--- %s ---", c.Tr.CommitsSectionHeader),
Content: formatListSectionHeader(c.Tr.CommitsSectionHeader),
})
}

View file

@ -198,7 +198,7 @@ func (self *MenuViewModel) GetNonModelItems() []*NonModelItem {
result = append(result, &NonModelItem{
Index: i,
Column: 1,
Content: style.FgGreen.SetBold().Sprintf("--- %s ---", menuItem.Section.Title),
Content: style.FgGreen.SetBold().Sprint(formatListSectionHeader(menuItem.Section.Title)),
})
prevSection = menuItem.Section
}

View file

@ -1,7 +1,6 @@
package context
import (
"fmt"
"time"
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
@ -90,7 +89,7 @@ func NewSubCommitsContext(
}
result = append(result, &NonModelItem{
Index: upstreamIdx,
Content: fmt.Sprintf("--- %s ---", c.Tr.DivergenceSectionHeaderRemote),
Content: formatListSectionHeader(c.Tr.DivergenceSectionHeaderRemote),
})
_, localIdx, found := lo.FindIndexOf(
@ -100,7 +99,7 @@ func NewSubCommitsContext(
}
result = append(result, &NonModelItem{
Index: localIdx,
Content: fmt.Sprintf("--- %s ---", c.Tr.DivergenceSectionHeaderLocal),
Content: formatListSectionHeader(c.Tr.DivergenceSectionHeaderLocal),
})
}