2020-03-21 12:18:26 +11:00
|
|
|
package presentation
|
|
|
|
|
|
|
|
import (
|
2022-03-19 12:26:30 +11:00
|
|
|
"github.com/jesseduffield/generics/set"
|
2022-03-19 19:12:58 +11:00
|
|
|
"github.com/jesseduffield/generics/slices"
|
2020-09-29 20:28:39 +10:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
2021-07-27 15:00:37 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
2020-03-21 12:18:26 +11: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 12:18:26 +11:00
|
|
|
)
|
|
|
|
|
2022-05-13 21:56:07 +09:00
|
|
|
func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaSet *set.Set[string], diffName string, timeFormat string, parseEmoji bool) [][]string {
|
|
|
|
var displayFunc func(*models.Commit, string, bool, bool, bool) []string
|
2020-03-21 12:18:26 +11:00
|
|
|
if fullDescription {
|
|
|
|
displayFunc = getFullDescriptionDisplayStringsForReflogCommit
|
|
|
|
} else {
|
|
|
|
displayFunc = getDisplayStringsForReflogCommit
|
|
|
|
}
|
|
|
|
|
2022-03-19 19:12:58 +11:00
|
|
|
return slices.Map(commits, func(commit *models.Commit) []string {
|
|
|
|
diffed := commit.Sha == diffName
|
|
|
|
cherryPicked := cherryPickedCommitShaSet.Includes(commit.Sha)
|
2022-05-13 21:56:07 +09:00
|
|
|
return displayFunc(commit, timeFormat, cherryPicked, diffed, parseEmoji)
|
2022-03-19 19:12:58 +11:00
|
|
|
})
|
2020-03-21 12:18:26 +11:00
|
|
|
}
|
|
|
|
|
2022-03-23 18:38:28 +11:00
|
|
|
func reflogShaColor(cherryPicked, diffed bool) style.TextStyle {
|
|
|
|
if diffed {
|
|
|
|
return theme.DiffTerminalColor
|
|
|
|
}
|
|
|
|
|
2021-07-27 15:00:37 +02:00
|
|
|
shaColor := style.FgBlue
|
2022-03-23 18:38:28 +11:00
|
|
|
if cherryPicked {
|
2021-09-29 12:53:31 +01:00
|
|
|
shaColor = theme.CherryPickedCommitTextStyle
|
2020-08-22 11:57:44 +10:00
|
|
|
}
|
|
|
|
|
2022-03-23 18:38:28 +11:00
|
|
|
return shaColor
|
2020-08-22 11:57:44 +10:00
|
|
|
}
|
|
|
|
|
2022-05-13 21:56:07 +09:00
|
|
|
func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, timeFormat string, cherryPicked, diffed, parseEmoji bool) []string {
|
2021-07-16 14:06:01 +02:00
|
|
|
name := c.Name
|
|
|
|
if parseEmoji {
|
|
|
|
name = emoji.Sprint(name)
|
|
|
|
}
|
|
|
|
|
2020-03-27 19:12:15 +11:00
|
|
|
return []string{
|
2022-03-23 18:38:28 +11:00
|
|
|
reflogShaColor(cherryPicked, diffed).Sprint(c.ShortSha()),
|
2022-05-13 21:56:07 +09:00
|
|
|
style.FgMagenta.Sprint(utils.UnixToDate(c.UnixTimestamp, timeFormat)),
|
2022-03-23 18:38:28 +11:00
|
|
|
theme.DefaultTextColor.Sprint(name),
|
2020-03-27 19:12:15 +11:00
|
|
|
}
|
2020-03-21 12:18:26 +11:00
|
|
|
}
|
|
|
|
|
2022-05-13 21:56:07 +09:00
|
|
|
func getDisplayStringsForReflogCommit(c *models.Commit, timeFormat string, cherryPicked, diffed, parseEmoji bool) []string {
|
2021-07-16 14:06:01 +02:00
|
|
|
name := c.Name
|
|
|
|
if parseEmoji {
|
|
|
|
name = emoji.Sprint(name)
|
|
|
|
}
|
|
|
|
|
2020-08-22 11:57:44 +10:00
|
|
|
return []string{
|
2022-03-23 18:38:28 +11:00
|
|
|
reflogShaColor(cherryPicked, diffed).Sprint(c.ShortSha()),
|
2021-07-27 15:00:37 +02:00
|
|
|
theme.DefaultTextColor.Sprint(name),
|
2020-08-22 11:57:44 +10:00
|
|
|
}
|
2020-03-21 12:18:26 +11:00
|
|
|
}
|