1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/presentation/reflog_commits.go

78 lines
2.2 KiB
Go
Raw Normal View History

2020-03-21 03:18:26 +02:00
package presentation
import (
2022-03-19 03:26:30 +02:00
"github.com/jesseduffield/generics/set"
2022-03-19 10:12:58 +02:00
"github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/style"
2020-03-21 03:18:26 +02:00
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils"
2021-07-16 14:06:01 +02:00
"github.com/kyokomi/emoji/v2"
2020-03-21 03:18:26 +02:00
)
func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaSet *set.Set[string], diffName string, timeFormat string, parseEmoji bool) [][]string {
2022-07-30 08:10:29 +02:00
var displayFunc func(*models.Commit, reflogCommitDisplayAttributes) []string
2020-03-21 03:18:26 +02:00
if fullDescription {
displayFunc = getFullDescriptionDisplayStringsForReflogCommit
} else {
displayFunc = getDisplayStringsForReflogCommit
}
2022-03-19 10:12:58 +02:00
return slices.Map(commits, func(commit *models.Commit) []string {
diffed := commit.Sha == diffName
cherryPicked := cherryPickedCommitShaSet.Includes(commit.Sha)
2022-07-30 08:10:29 +02:00
return displayFunc(commit,
reflogCommitDisplayAttributes{
cherryPicked: cherryPicked,
diffed: diffed,
parseEmoji: parseEmoji,
timeFormat: timeFormat,
})
2022-03-19 10:12:58 +02:00
})
2020-03-21 03:18:26 +02:00
}
2022-03-23 09:38:28 +02:00
func reflogShaColor(cherryPicked, diffed bool) style.TextStyle {
if diffed {
return theme.DiffTerminalColor
}
shaColor := style.FgBlue
2022-03-23 09:38:28 +02:00
if cherryPicked {
shaColor = theme.CherryPickedCommitTextStyle
}
2022-03-23 09:38:28 +02:00
return shaColor
}
2022-07-30 08:10:29 +02:00
type reflogCommitDisplayAttributes struct {
cherryPicked bool
diffed bool
parseEmoji bool
timeFormat string
}
func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, attrs reflogCommitDisplayAttributes) []string {
2021-07-16 14:06:01 +02:00
name := c.Name
2022-07-30 08:10:29 +02:00
if attrs.parseEmoji {
2021-07-16 14:06:01 +02:00
name = emoji.Sprint(name)
}
return []string{
2022-07-30 08:10:29 +02:00
reflogShaColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortSha()),
style.FgMagenta.Sprint(utils.UnixToDate(c.UnixTimestamp, attrs.timeFormat)),
2022-03-23 09:38:28 +02:00
theme.DefaultTextColor.Sprint(name),
}
2020-03-21 03:18:26 +02:00
}
2022-07-30 08:10:29 +02:00
func getDisplayStringsForReflogCommit(c *models.Commit, attrs reflogCommitDisplayAttributes) []string {
2021-07-16 14:06:01 +02:00
name := c.Name
2022-07-30 08:10:29 +02:00
if attrs.parseEmoji {
2021-07-16 14:06:01 +02:00
name = emoji.Sprint(name)
}
return []string{
2022-07-30 08:10:29 +02:00
reflogShaColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortSha()),
theme.DefaultTextColor.Sprint(name),
}
2020-03-21 03:18:26 +02:00
}