2020-03-21 12:18:26 +11:00
|
|
|
package presentation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/fatih/color"
|
2020-09-29 20:28:39 +10:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
2020-03-21 12:18:26 +11:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
|
|
|
)
|
|
|
|
|
2020-09-29 18:36:54 +10:00
|
|
|
func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool, diffName string) [][]string {
|
2020-03-21 12:18:26 +11:00
|
|
|
lines := make([][]string, len(commits))
|
|
|
|
|
2020-09-29 18:36:54 +10:00
|
|
|
var displayFunc func(*models.Commit, map[string]bool, bool) []string
|
2020-03-21 12:18:26 +11:00
|
|
|
if fullDescription {
|
|
|
|
displayFunc = getFullDescriptionDisplayStringsForReflogCommit
|
|
|
|
} else {
|
|
|
|
displayFunc = getDisplayStringsForReflogCommit
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range commits {
|
2020-03-29 14:34:17 +11:00
|
|
|
diffed := commits[i].Sha == diffName
|
2020-08-22 11:57:44 +10:00
|
|
|
lines[i] = displayFunc(commits[i], cherryPickedCommitShaMap, diffed)
|
2020-03-21 12:18:26 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
return lines
|
|
|
|
}
|
|
|
|
|
2020-09-29 18:36:54 +10:00
|
|
|
func coloredReflogSha(c *models.Commit, cherryPickedCommitShaMap map[string]bool) string {
|
2020-08-22 11:57:44 +10:00
|
|
|
var shaColor *color.Color
|
|
|
|
if cherryPickedCommitShaMap[c.Sha] {
|
|
|
|
shaColor = color.New(color.FgCyan, color.BgBlue)
|
|
|
|
} else {
|
|
|
|
shaColor = color.New(color.FgBlue)
|
|
|
|
}
|
|
|
|
|
|
|
|
return shaColor.Sprint(c.ShortSha())
|
|
|
|
}
|
|
|
|
|
2020-09-29 18:36:54 +10:00
|
|
|
func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string {
|
2020-03-29 14:34:17 +11:00
|
|
|
colorAttr := theme.DefaultTextColor
|
|
|
|
if diffed {
|
|
|
|
colorAttr = theme.DiffTerminalColor
|
|
|
|
}
|
2020-03-21 12:18:26 +11:00
|
|
|
|
2020-03-27 19:12:15 +11:00
|
|
|
return []string{
|
2020-08-22 11:57:44 +10:00
|
|
|
coloredReflogSha(c, cherryPickedCommitShaMap),
|
2020-03-27 19:12:15 +11:00
|
|
|
utils.ColoredString(utils.UnixToDate(c.UnixTimestamp), color.FgMagenta),
|
2020-03-29 14:34:17 +11:00
|
|
|
utils.ColoredString(c.Name, colorAttr),
|
2020-03-27 19:12:15 +11:00
|
|
|
}
|
2020-03-21 12:18:26 +11:00
|
|
|
}
|
|
|
|
|
2020-09-29 18:36:54 +10:00
|
|
|
func getDisplayStringsForReflogCommit(c *models.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string {
|
2020-03-21 12:18:26 +11:00
|
|
|
defaultColor := color.New(theme.DefaultTextColor)
|
|
|
|
|
2020-08-22 11:57:44 +10:00
|
|
|
return []string{
|
|
|
|
coloredReflogSha(c, cherryPickedCommitShaMap),
|
|
|
|
defaultColor.Sprint(c.Name),
|
|
|
|
}
|
2020-03-21 12:18:26 +11:00
|
|
|
}
|