1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-05 15:15:49 +02:00

diff colour for reflog commits

This commit is contained in:
Jesse Duffield 2022-03-23 18:38:28 +11:00
parent 8fb47fb7d6
commit 5ded030a88

View File

@ -11,7 +11,7 @@ import (
func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool, diffName string, parseEmoji bool) [][]string { func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool, diffName string, parseEmoji bool) [][]string {
lines := make([][]string, len(commits)) lines := make([][]string, len(commits))
var displayFunc func(*models.Commit, map[string]bool, bool, bool) []string var displayFunc func(*models.Commit, bool, bool, bool) []string
if fullDescription { if fullDescription {
displayFunc = getFullDescriptionDisplayStringsForReflogCommit displayFunc = getFullDescriptionDisplayStringsForReflogCommit
} else { } else {
@ -20,47 +20,47 @@ func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription
for i := range commits { for i := range commits {
diffed := commits[i].Sha == diffName diffed := commits[i].Sha == diffName
lines[i] = displayFunc(commits[i], cherryPickedCommitShaMap, diffed, parseEmoji) cherryPicked := cherryPickedCommitShaMap[commits[i].Sha]
lines[i] = displayFunc(commits[i], cherryPicked, diffed, parseEmoji)
} }
return lines return lines
} }
func coloredReflogSha(c *models.Commit, cherryPickedCommitShaMap map[string]bool) string { func reflogShaColor(cherryPicked, diffed bool) style.TextStyle {
if diffed {
return theme.DiffTerminalColor
}
shaColor := style.FgBlue shaColor := style.FgBlue
if cherryPickedCommitShaMap[c.Sha] { if cherryPicked {
shaColor = theme.CherryPickedCommitTextStyle shaColor = theme.CherryPickedCommitTextStyle
} }
return shaColor.Sprint(c.ShortSha()) return shaColor
} }
func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, cherryPickedCommitShaMap map[string]bool, diffed, parseEmoji bool) []string { func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, cherryPicked, diffed, parseEmoji bool) []string {
colorAttr := theme.DefaultTextColor
if diffed {
colorAttr = theme.DiffTerminalColor
}
name := c.Name name := c.Name
if parseEmoji { if parseEmoji {
name = emoji.Sprint(name) name = emoji.Sprint(name)
} }
return []string{ return []string{
coloredReflogSha(c, cherryPickedCommitShaMap), reflogShaColor(cherryPicked, diffed).Sprint(c.ShortSha()),
style.FgMagenta.Sprint(utils.UnixToDate(c.UnixTimestamp)), style.FgMagenta.Sprint(utils.UnixToDate(c.UnixTimestamp)),
colorAttr.Sprint(name), theme.DefaultTextColor.Sprint(name),
} }
} }
func getDisplayStringsForReflogCommit(c *models.Commit, cherryPickedCommitShaMap map[string]bool, diffed, parseEmoji bool) []string { func getDisplayStringsForReflogCommit(c *models.Commit, cherryPicked, diffed, parseEmoji bool) []string {
name := c.Name name := c.Name
if parseEmoji { if parseEmoji {
name = emoji.Sprint(name) name = emoji.Sprint(name)
} }
return []string{ return []string{
coloredReflogSha(c, cherryPickedCommitShaMap), reflogShaColor(cherryPicked, diffed).Sprint(c.ShortSha()),
theme.DefaultTextColor.Sprint(name), theme.DefaultTextColor.Sprint(name),
} }
} }