2020-03-21 03:18:26 +02:00
|
|
|
package presentation
|
|
|
|
|
|
|
|
import (
|
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
|
|
|
)
|
|
|
|
|
2021-07-16 14:06:01 +02:00
|
|
|
func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool, diffName string, parseEmoji bool) [][]string {
|
2020-03-21 03:18:26 +02:00
|
|
|
lines := make([][]string, len(commits))
|
|
|
|
|
2021-07-16 14:06:01 +02:00
|
|
|
var displayFunc func(*models.Commit, map[string]bool, bool, bool) []string
|
2020-03-21 03:18:26 +02:00
|
|
|
if fullDescription {
|
|
|
|
displayFunc = getFullDescriptionDisplayStringsForReflogCommit
|
|
|
|
} else {
|
|
|
|
displayFunc = getDisplayStringsForReflogCommit
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range commits {
|
2020-03-29 05:34:17 +02:00
|
|
|
diffed := commits[i].Sha == diffName
|
2021-07-16 14:06:01 +02:00
|
|
|
lines[i] = displayFunc(commits[i], cherryPickedCommitShaMap, diffed, parseEmoji)
|
2020-03-21 03:18:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return lines
|
|
|
|
}
|
|
|
|
|
2020-09-29 10:36:54 +02:00
|
|
|
func coloredReflogSha(c *models.Commit, cherryPickedCommitShaMap map[string]bool) string {
|
2021-07-27 15:00:37 +02:00
|
|
|
shaColor := style.FgBlue
|
2020-08-22 03:57:44 +02:00
|
|
|
if cherryPickedCommitShaMap[c.Sha] {
|
2021-09-29 13:53:31 +02:00
|
|
|
shaColor = theme.CherryPickedCommitTextStyle
|
2020-08-22 03:57:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return shaColor.Sprint(c.ShortSha())
|
|
|
|
}
|
|
|
|
|
2021-07-16 14:06:01 +02:00
|
|
|
func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, cherryPickedCommitShaMap map[string]bool, diffed, parseEmoji bool) []string {
|
2020-03-29 05:34:17 +02:00
|
|
|
colorAttr := theme.DefaultTextColor
|
|
|
|
if diffed {
|
|
|
|
colorAttr = theme.DiffTerminalColor
|
|
|
|
}
|
2020-03-21 03:18:26 +02:00
|
|
|
|
2021-07-16 14:06:01 +02:00
|
|
|
name := c.Name
|
|
|
|
if parseEmoji {
|
|
|
|
name = emoji.Sprint(name)
|
|
|
|
}
|
|
|
|
|
2020-03-27 10:12:15 +02:00
|
|
|
return []string{
|
2020-08-22 03:57:44 +02:00
|
|
|
coloredReflogSha(c, cherryPickedCommitShaMap),
|
2021-07-27 15:00:37 +02:00
|
|
|
style.FgMagenta.Sprint(utils.UnixToDate(c.UnixTimestamp)),
|
|
|
|
colorAttr.Sprint(name),
|
2020-03-27 10:12:15 +02:00
|
|
|
}
|
2020-03-21 03:18:26 +02:00
|
|
|
}
|
|
|
|
|
2021-07-16 14:06:01 +02:00
|
|
|
func getDisplayStringsForReflogCommit(c *models.Commit, cherryPickedCommitShaMap map[string]bool, diffed, parseEmoji bool) []string {
|
|
|
|
name := c.Name
|
|
|
|
if parseEmoji {
|
|
|
|
name = emoji.Sprint(name)
|
|
|
|
}
|
|
|
|
|
2020-08-22 03:57:44 +02:00
|
|
|
return []string{
|
|
|
|
coloredReflogSha(c, cherryPickedCommitShaMap),
|
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
|
|
|
}
|