github.com/dawidd6/lazygit@v0.8.1/pkg/commands/commit.go (about)

     1  package commands
     2  
     3  import (
     4  	"github.com/fatih/color"
     5  	"github.com/jesseduffield/lazygit/pkg/utils"
     6  )
     7  
     8  // Commit : A git commit
     9  type Commit struct {
    10  	Sha           string
    11  	Name          string
    12  	Status        string // one of "unpushed", "pushed", "merged", "rebasing" or "selected"
    13  	DisplayString string
    14  	Action        string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup"
    15  	Copied        bool   // to know if this commit is ready to be cherry-picked somewhere
    16  }
    17  
    18  // GetDisplayStrings is a function.
    19  func (c *Commit) GetDisplayStrings(isFocused bool) []string {
    20  	red := color.New(color.FgRed)
    21  	yellow := color.New(color.FgYellow)
    22  	green := color.New(color.FgGreen)
    23  	blue := color.New(color.FgBlue)
    24  	cyan := color.New(color.FgCyan)
    25  	white := color.New(color.FgWhite)
    26  	magenta := color.New(color.FgMagenta)
    27  
    28  	// for some reason, setting the background to blue pads out the other commits
    29  	// horizontally. For the sake of accessibility I'm considering this a feature,
    30  	// not a bug
    31  	copied := color.New(color.FgCyan, color.BgBlue)
    32  
    33  	var shaColor *color.Color
    34  	switch c.Status {
    35  	case "unpushed":
    36  		shaColor = red
    37  	case "pushed":
    38  		shaColor = yellow
    39  	case "merged":
    40  		shaColor = green
    41  	case "rebasing":
    42  		shaColor = blue
    43  	case "selected":
    44  		shaColor = magenta
    45  	default:
    46  		shaColor = white
    47  	}
    48  
    49  	if c.Copied {
    50  		shaColor = copied
    51  	}
    52  
    53  	actionString := ""
    54  	if c.Action != "" {
    55  		actionString = cyan.Sprint(utils.WithPadding(c.Action, 7)) + " "
    56  	}
    57  
    58  	return []string{shaColor.Sprint(c.Sha), actionString + white.Sprint(c.Name)}
    59  }