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

67 lines
1.9 KiB
Go
Raw Normal View History

2020-03-21 03:18:26 +02:00
package presentation
import (
"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
)
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 {
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 {
shaColor := style.FgBlue
if cherryPickedCommitShaMap[c.Sha] {
shaColor = theme.CherryPickedCommitTextStyle
}
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 {
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)
}
return []string{
coloredReflogSha(c, cherryPickedCommitShaMap),
style.FgMagenta.Sprint(utils.UnixToDate(c.UnixTimestamp)),
colorAttr.Sprint(name),
}
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)
}
return []string{
coloredReflogSha(c, cherryPickedCommitShaMap),
theme.DefaultTextColor.Sprint(name),
}
2020-03-21 03:18:26 +02:00
}