2020-02-25 11:11:07 +02:00
|
|
|
package presentation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/fatih/color"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
|
|
|
)
|
|
|
|
|
2020-03-29 05:34:17 +02:00
|
|
|
func GetCommitListDisplayStrings(commits []*commands.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool, diffName string) [][]string {
|
2020-02-25 11:11:07 +02:00
|
|
|
lines := make([][]string, len(commits))
|
|
|
|
|
2020-03-29 05:34:17 +02:00
|
|
|
var displayFunc func(*commands.Commit, map[string]bool, bool) []string
|
2020-02-25 11:11:07 +02:00
|
|
|
if fullDescription {
|
|
|
|
displayFunc = getFullDescriptionDisplayStringsForCommit
|
|
|
|
} else {
|
|
|
|
displayFunc = getDisplayStringsForCommit
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range commits {
|
2020-03-29 05:34:17 +02:00
|
|
|
diffed := commits[i].Sha == diffName
|
|
|
|
lines[i] = displayFunc(commits[i], cherryPickedCommitShaMap, diffed)
|
2020-02-25 11:11:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return lines
|
|
|
|
}
|
|
|
|
|
2020-03-29 05:34:17 +02:00
|
|
|
func getFullDescriptionDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string {
|
2020-02-25 11:11:07 +02:00
|
|
|
red := color.New(color.FgRed)
|
|
|
|
yellow := color.New(color.FgYellow)
|
|
|
|
green := color.New(color.FgGreen)
|
|
|
|
blue := color.New(color.FgBlue)
|
|
|
|
defaultColor := color.New(theme.DefaultTextColor)
|
2020-03-29 05:34:17 +02:00
|
|
|
diffedColor := color.New(theme.DiffTerminalColor)
|
2020-02-25 11:11:07 +02:00
|
|
|
|
|
|
|
// for some reason, setting the background to blue pads out the other commits
|
|
|
|
// horizontally. For the sake of accessibility I'm considering this a feature,
|
|
|
|
// not a bug
|
|
|
|
copied := color.New(color.FgCyan, color.BgBlue)
|
|
|
|
|
|
|
|
var shaColor *color.Color
|
|
|
|
switch c.Status {
|
|
|
|
case "unpushed":
|
|
|
|
shaColor = red
|
|
|
|
case "pushed":
|
|
|
|
shaColor = yellow
|
|
|
|
case "merged":
|
|
|
|
shaColor = green
|
|
|
|
case "rebasing":
|
|
|
|
shaColor = blue
|
|
|
|
case "reflog":
|
|
|
|
shaColor = blue
|
|
|
|
default:
|
|
|
|
shaColor = defaultColor
|
|
|
|
}
|
|
|
|
|
2020-03-29 05:34:17 +02:00
|
|
|
if diffed {
|
|
|
|
shaColor = diffedColor
|
|
|
|
} else if cherryPickedCommitShaMap[c.Sha] {
|
2020-02-25 11:11:07 +02:00
|
|
|
shaColor = copied
|
|
|
|
}
|
|
|
|
|
|
|
|
tagString := ""
|
2020-03-27 10:12:15 +02:00
|
|
|
secondColumnString := blue.Sprint(utils.UnixToDate(c.UnixTimestamp))
|
2020-02-25 11:11:07 +02:00
|
|
|
if c.Action != "" {
|
2020-08-27 09:00:43 +02:00
|
|
|
secondColumnString = color.New(actionColorMap(c.Action)).Sprint(c.Action)
|
2020-02-25 11:55:36 +02:00
|
|
|
} else if c.ExtraInfo != "" {
|
2020-02-25 11:11:07 +02:00
|
|
|
tagColor := color.New(color.FgMagenta, color.Bold)
|
|
|
|
tagString = utils.ColoredStringDirect(c.ExtraInfo, tagColor) + " "
|
|
|
|
}
|
|
|
|
|
|
|
|
truncatedAuthor := utils.TruncateWithEllipsis(c.Author, 17)
|
|
|
|
|
2020-03-26 00:18:52 +02:00
|
|
|
return []string{shaColor.Sprint(c.ShortSha()), secondColumnString, yellow.Sprint(truncatedAuthor), tagString + defaultColor.Sprint(c.Name)}
|
2020-02-25 11:11:07 +02:00
|
|
|
}
|
|
|
|
|
2020-03-29 05:34:17 +02:00
|
|
|
func getDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string {
|
2020-02-25 11:11:07 +02:00
|
|
|
red := color.New(color.FgRed)
|
|
|
|
yellow := color.New(color.FgYellow)
|
|
|
|
green := color.New(color.FgGreen)
|
|
|
|
blue := color.New(color.FgBlue)
|
|
|
|
defaultColor := color.New(theme.DefaultTextColor)
|
2020-03-29 05:34:17 +02:00
|
|
|
diffedColor := color.New(theme.DiffTerminalColor)
|
2020-02-25 11:11:07 +02:00
|
|
|
|
|
|
|
// for some reason, setting the background to blue pads out the other commits
|
|
|
|
// horizontally. For the sake of accessibility I'm considering this a feature,
|
|
|
|
// not a bug
|
|
|
|
copied := color.New(color.FgCyan, color.BgBlue)
|
|
|
|
|
|
|
|
var shaColor *color.Color
|
|
|
|
switch c.Status {
|
|
|
|
case "unpushed":
|
|
|
|
shaColor = red
|
|
|
|
case "pushed":
|
|
|
|
shaColor = yellow
|
|
|
|
case "merged":
|
|
|
|
shaColor = green
|
|
|
|
case "rebasing":
|
|
|
|
shaColor = blue
|
|
|
|
case "reflog":
|
|
|
|
shaColor = blue
|
|
|
|
default:
|
|
|
|
shaColor = defaultColor
|
|
|
|
}
|
|
|
|
|
2020-03-29 05:34:17 +02:00
|
|
|
if diffed {
|
|
|
|
shaColor = diffedColor
|
|
|
|
} else if cherryPickedCommitShaMap[c.Sha] {
|
2020-02-25 11:11:07 +02:00
|
|
|
shaColor = copied
|
|
|
|
}
|
|
|
|
|
|
|
|
actionString := ""
|
|
|
|
tagString := ""
|
|
|
|
if c.Action != "" {
|
2020-08-27 09:00:43 +02:00
|
|
|
actionString = color.New(actionColorMap(c.Action)).Sprint(utils.WithPadding(c.Action, 7)) + " "
|
2020-02-25 11:11:07 +02:00
|
|
|
} else if len(c.Tags) > 0 {
|
|
|
|
tagColor := color.New(color.FgMagenta, color.Bold)
|
|
|
|
tagString = utils.ColoredStringDirect(strings.Join(c.Tags, " "), tagColor) + " "
|
|
|
|
}
|
|
|
|
|
2020-03-26 00:18:52 +02:00
|
|
|
return []string{shaColor.Sprint(c.ShortSha()), actionString + tagString + defaultColor.Sprint(c.Name)}
|
2020-02-25 11:11:07 +02:00
|
|
|
}
|
2020-08-27 09:00:43 +02:00
|
|
|
|
|
|
|
func actionColorMap(str string) color.Attribute {
|
|
|
|
switch str {
|
|
|
|
case "pick":
|
|
|
|
return color.FgCyan
|
|
|
|
case "drop":
|
|
|
|
return color.FgRed
|
|
|
|
case "edit":
|
|
|
|
return color.FgGreen
|
|
|
|
case "fixup":
|
|
|
|
return color.FgMagenta
|
|
|
|
default:
|
|
|
|
return color.FgYellow
|
|
|
|
}
|
|
|
|
}
|