1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/commands/commit.go

67 lines
1.7 KiB
Go
Raw Normal View History

package commands
import (
2019-11-18 00:38:36 +02:00
"strings"
"github.com/fatih/color"
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils"
)
// Commit : A git commit
type Commit struct {
Sha string
Name string
2019-03-28 11:58:34 +02:00
Status string // one of "unpushed", "pushed", "merged", "rebasing" or "selected"
DisplayString string
Action string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup"
2019-02-24 04:51:52 +02:00
Copied bool // to know if this commit is ready to be cherry-picked somewhere
2019-11-18 00:38:36 +02:00
Tags []string
}
2018-11-30 02:47:14 +02:00
// GetDisplayStrings is a function.
func (c *Commit) GetDisplayStrings(isFocused bool) []string {
red := color.New(color.FgRed)
yellow := color.New(color.FgYellow)
green := color.New(color.FgGreen)
blue := color.New(color.FgBlue)
cyan := color.New(color.FgCyan)
defaultColor := color.New(theme.DefaultTextColor)
2019-03-28 11:58:34 +02:00
magenta := color.New(color.FgMagenta)
2019-02-24 04:51:52 +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
2019-03-28 11:58:34 +02:00
case "selected":
shaColor = magenta
default:
shaColor = defaultColor
}
2019-02-24 04:51:52 +02:00
if c.Copied {
shaColor = copied
}
actionString := ""
2019-11-18 00:38:36 +02:00
tagString := ""
if c.Action != "" {
actionString = cyan.Sprint(utils.WithPadding(c.Action, 7)) + " "
2019-11-18 00:38:36 +02:00
} else if len(c.Tags) > 0 {
tagString = utils.ColoredString(strings.Join(c.Tags, " "), color.FgMagenta) + " "
}
2019-11-18 00:38:36 +02:00
return []string{shaColor.Sprint(c.Sha), actionString + tagString + defaultColor.Sprint(c.Name)}
}