2020-03-21 03:18:26 +02:00
|
|
|
package presentation
|
|
|
|
|
|
|
|
import (
|
2023-05-26 08:38:58 +02:00
|
|
|
"time"
|
|
|
|
|
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"
|
2020-09-29 12:28:39 +02: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 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
|
|
|
)
|
|
|
|
|
2023-05-26 08:38:58 +02: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 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{
|
2023-05-26 08:38:58 +02:00
|
|
|
cherryPicked: cherryPicked,
|
|
|
|
diffed: diffed,
|
|
|
|
parseEmoji: parseEmoji,
|
|
|
|
timeFormat: timeFormat,
|
|
|
|
shortTimeFormat: shortTimeFormat,
|
|
|
|
now: now,
|
2022-07-30 08:10:29 +02:00
|
|
|
})
|
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
|
|
|
|
}
|
|
|
|
|
2021-07-27 15:00:37 +02:00
|
|
|
shaColor := style.FgBlue
|
2022-03-23 09:38:28 +02:00
|
|
|
if cherryPicked {
|
2021-09-29 13:53:31 +02:00
|
|
|
shaColor = theme.CherryPickedCommitTextStyle
|
2020-08-22 03:57:44 +02:00
|
|
|
}
|
|
|
|
|
2022-03-23 09:38:28 +02:00
|
|
|
return shaColor
|
2020-08-22 03:57:44 +02:00
|
|
|
}
|
|
|
|
|
2022-07-30 08:10:29 +02:00
|
|
|
type reflogCommitDisplayAttributes struct {
|
2023-05-26 08:38:58 +02: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 10:12:15 +02:00
|
|
|
return []string{
|
2022-07-30 08:10:29 +02:00
|
|
|
reflogShaColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortSha()),
|
2023-05-26 08:38:58 +02:00
|
|
|
style.FgMagenta.Sprint(utils.UnixToDateSmart(attrs.now, c.UnixTimestamp, attrs.timeFormat, attrs.shortTimeFormat)),
|
2022-03-23 09:38:28 +02:00
|
|
|
theme.DefaultTextColor.Sprint(name),
|
2020-03-27 10:12:15 +02:00
|
|
|
}
|
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)
|
|
|
|
}
|
|
|
|
|
2020-08-22 03:57:44 +02: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 03:57:44 +02:00
|
|
|
}
|
2020-03-21 03:18:26 +02:00
|
|
|
}
|