summaryrefslogtreecommitdiffstats
path: root/pkg/gui/presentation/reflog_commits.go
blob: d435c13876923e2bc1783e56b6ae2ab15e512096 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package presentation

import (
	"github.com/fatih/color"
	"github.com/jesseduffield/lazygit/pkg/commands/models"
	"github.com/jesseduffield/lazygit/pkg/theme"
	"github.com/jesseduffield/lazygit/pkg/utils"
)

func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool, diffName string) [][]string {
	lines := make([][]string, len(commits))

	var displayFunc func(*models.Commit, map[string]bool, bool) []string
	if fullDescription {
		displayFunc = getFullDescriptionDisplayStringsForReflogCommit
	} else {
		displayFunc = getDisplayStringsForReflogCommit
	}

	for i := range commits {
		diffed := commits[i].Sha == diffName
		lines[i] = displayFunc(commits[i], cherryPickedCommitShaMap, diffed)
	}

	return lines
}

func coloredReflogSha(c *models.Commit, cherryPickedCommitShaMap map[string]bool) string {
	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())
}

func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string {
	colorAttr := theme.DefaultTextColor
	if diffed {
		colorAttr = theme.DiffTerminalColor
	}

	return []string{
		coloredReflogSha(c, cherryPickedCommitShaMap),
		utils.ColoredString(utils.UnixToDate(c.UnixTimestamp), color.FgMagenta),
		utils.ColoredString(c.Name, colorAttr),
	}
}

func getDisplayStringsForReflogCommit(c *models.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string {
	defaultColor := color.New(theme.DefaultTextColor)

	return []string{
		coloredReflogSha(c, cherryPickedCommitShaMap),
		defaultColor.Sprint(c.Name),
	}
}