2020-03-21 12:18:26 +11:00
|
|
|
package presentation
|
|
|
|
|
|
|
|
import (
|
2023-05-26 16:38:58 +10:00
|
|
|
"time"
|
|
|
|
|
2022-03-19 12:26:30 +11:00
|
|
|
"github.com/jesseduffield/generics/set"
|
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"
|
2023-07-24 13:06:42 +10:00
|
|
|
"github.com/samber/lo"
|
2020-03-21 12:18:26 +11:00
|
|
|
)
|
|
|
|
|
2023-05-26 16:38:58 +10:00
|
|
|
func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaSet *set.Set[string], diffName string, now time.Time, timeFormat string, shortTimeFormat string, parseEmoji bool) [][]string {
|
2022-07-30 08:10:29 +02:00
|
|
|
var displayFunc func(*models.Commit, reflogCommitDisplayAttributes) []string
|
2020-03-21 12:18:26 +11:00
|
|
|
if fullDescription {
|
|
|
|
displayFunc = getFullDescriptionDisplayStringsForReflogCommit
|
|
|
|
} else {
|
|
|
|
displayFunc = getDisplayStringsForReflogCommit
|
|
|
|
}
|
|
|
|
|
2023-07-24 13:06:42 +10:00
|
|
|
return lo.Map(commits, func(commit *models.Commit, _ int) []string {
|
2022-03-19 19:12:58 +11:00
|
|
|
diffed := commit.Sha == diffName
|
|
|
|
cherryPicked := cherryPickedCommitShaSet.Includes(commit.Sha)
|
2022-07-30 08:10:29 +02:00
|
|
|
return displayFunc(commit,
|
|
|
|
reflogCommitDisplayAttributes{
|
2023-05-26 16:38:58 +10:00
|
|
|
cherryPicked: cherryPicked,
|
|
|
|
diffed: diffed,
|
|
|
|
parseEmoji: parseEmoji,
|
|
|
|
timeFormat: timeFormat,
|
|
|
|
shortTimeFormat: shortTimeFormat,
|
|
|
|
now: now,
|
2022-07-30 08:10:29 +02:00
|
|
|
})
|
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-07-30 08:10:29 +02:00
|
|
|
type reflogCommitDisplayAttributes struct {
|
2023-05-26 16:38:58 +10:00
|
|
|
cherryPicked bool
|
|
|
|
diffed bool
|
|
|
|
parseEmoji bool
|
|
|
|
timeFormat string
|
|
|
|
shortTimeFormat string
|
|
|
|
now time.Time
|
2022-07-30 08:10:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-03-27 19:12:15 +11:00
|
|
|
return []string{
|
2022-07-30 08:10:29 +02:00
|
|
|
reflogShaColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortSha()),
|
2023-05-26 16:38:58 +10:00
|
|
|
style.FgMagenta.Sprint(utils.UnixToDateSmart(attrs.now, c.UnixTimestamp, attrs.timeFormat, attrs.shortTimeFormat)),
|
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-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)
|
|
|
|
}
|
|
|
|
|
2020-08-22 11:57:44 +10:00
|
|
|
return []string{
|
2022-07-30 08:10:29 +02:00
|
|
|
reflogShaColor(attrs.cherryPicked, attrs.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
|
|
|
}
|