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

65 lines
1.8 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
)
2022-03-19 03:26:30 +02:00
func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaSet *set.Set[string], diffName string, parseEmoji bool) [][]string {
2022-03-23 09:38:28 +02:00
var displayFunc func(*models.Commit, bool, bool, bool) []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)
return displayFunc(commit, cherryPicked, diffed, parseEmoji)
})
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-03-23 09:38:28 +02:00
func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, cherryPicked, diffed, parseEmoji bool) []string {
2021-07-16 14:06:01 +02:00
name := c.Name
if parseEmoji {
name = emoji.Sprint(name)
}
return []string{
2022-03-23 09:38:28 +02:00
reflogShaColor(cherryPicked, diffed).Sprint(c.ShortSha()),
style.FgMagenta.Sprint(utils.UnixToDate(c.UnixTimestamp)),
2022-03-23 09:38:28 +02:00
theme.DefaultTextColor.Sprint(name),
}
2020-03-21 03:18:26 +02:00
}
2022-03-23 09:38:28 +02:00
func getDisplayStringsForReflogCommit(c *models.Commit, cherryPicked, diffed, parseEmoji bool) []string {
2021-07-16 14:06:01 +02:00
name := c.Name
if parseEmoji {
name = emoji.Sprint(name)
}
return []string{
2022-03-23 09:38:28 +02:00
reflogShaColor(cherryPicked, diffed).Sprint(c.ShortSha()),
theme.DefaultTextColor.Sprint(name),
}
2020-03-21 03:18:26 +02:00
}