2020-02-25 11:55:36 +02:00
|
|
|
package presentation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/fatih/color"
|
2020-09-29 12:28:39 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
2020-08-15 03:18:40 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
2020-02-25 11:55:36 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
2020-08-23 06:20:28 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
2020-02-25 11:55:36 +02:00
|
|
|
)
|
|
|
|
|
2021-03-31 14:00:24 +02:00
|
|
|
func GetCommitFileLine(name string, diffName string, commitFile *models.CommitFile, status patch.PatchStatus) string {
|
2020-02-25 11:55:36 +02:00
|
|
|
yellow := color.New(color.FgYellow)
|
|
|
|
green := color.New(color.FgGreen)
|
|
|
|
defaultColor := color.New(theme.DefaultTextColor)
|
2020-03-29 05:34:17 +02:00
|
|
|
diffTerminalColor := color.New(theme.DiffTerminalColor)
|
2020-02-25 11:55:36 +02:00
|
|
|
|
2021-03-31 13:08:55 +02:00
|
|
|
colour := defaultColor
|
|
|
|
if diffName == name {
|
2020-03-29 05:34:17 +02:00
|
|
|
colour = diffTerminalColor
|
2021-03-31 14:00:24 +02:00
|
|
|
} else {
|
2021-03-31 13:39:55 +02:00
|
|
|
switch status {
|
2021-03-31 13:08:55 +02:00
|
|
|
case patch.UNSELECTED:
|
|
|
|
colour = defaultColor
|
|
|
|
case patch.WHOLE:
|
|
|
|
colour = green
|
|
|
|
case patch.PART:
|
|
|
|
colour = yellow
|
|
|
|
}
|
2020-03-29 05:34:17 +02:00
|
|
|
}
|
2021-03-31 13:08:55 +02:00
|
|
|
|
2021-07-23 12:04:23 +02:00
|
|
|
name = utils.EscapeSpecialChars(name)
|
2021-03-31 14:00:24 +02:00
|
|
|
if commitFile == nil {
|
|
|
|
return colour.Sprint(name)
|
|
|
|
}
|
|
|
|
|
2021-03-31 13:08:55 +02:00
|
|
|
return utils.ColoredString(commitFile.ChangeStatus, getColorForChangeStatus(commitFile.ChangeStatus)) + " " + colour.Sprint(name)
|
2020-08-23 06:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func getColorForChangeStatus(changeStatus string) color.Attribute {
|
|
|
|
switch changeStatus {
|
|
|
|
case "A":
|
|
|
|
return color.FgGreen
|
|
|
|
case "M", "R":
|
|
|
|
return color.FgYellow
|
|
|
|
case "D":
|
|
|
|
return color.FgRed
|
|
|
|
case "C":
|
|
|
|
return color.FgCyan
|
|
|
|
case "T":
|
|
|
|
return color.FgMagenta
|
|
|
|
default:
|
2020-08-23 06:43:48 +02:00
|
|
|
return theme.DefaultTextColor
|
2020-08-23 06:20:28 +02:00
|
|
|
}
|
2020-02-25 11:55:36 +02:00
|
|
|
}
|