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
|
|
|
)
|
|
|
|
|
2020-09-29 10:48:38 +02:00
|
|
|
func GetCommitFileListDisplayStrings(commitFiles []*models.CommitFile, diffName string) [][]string {
|
2020-08-23 06:43:48 +02:00
|
|
|
if len(commitFiles) == 0 {
|
|
|
|
return [][]string{{utils.ColoredString("(none)", color.FgRed)}}
|
|
|
|
}
|
|
|
|
|
2020-03-29 05:34:17 +02:00
|
|
|
lines := make([][]string, len(commitFiles))
|
2020-02-25 11:55:36 +02:00
|
|
|
|
2020-03-29 05:34:17 +02:00
|
|
|
for i := range commitFiles {
|
|
|
|
diffed := commitFiles[i].Name == diffName
|
|
|
|
lines[i] = getCommitFileDisplayStrings(commitFiles[i], diffed)
|
2020-02-25 11:55:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return lines
|
|
|
|
}
|
|
|
|
|
|
|
|
// getCommitFileDisplayStrings returns the display string of branch
|
2020-09-29 10:48:38 +02:00
|
|
|
func getCommitFileDisplayStrings(f *models.CommitFile, diffed bool) []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
|
|
|
|
|
|
|
var colour *color.Color
|
2020-08-23 07:04:12 +02:00
|
|
|
switch f.PatchStatus {
|
2020-08-15 03:18:40 +02:00
|
|
|
case patch.UNSELECTED:
|
2020-02-25 11:55:36 +02:00
|
|
|
colour = defaultColor
|
2020-08-15 03:18:40 +02:00
|
|
|
case patch.WHOLE:
|
2020-02-25 11:55:36 +02:00
|
|
|
colour = green
|
2020-08-15 03:18:40 +02:00
|
|
|
case patch.PART:
|
2020-02-25 11:55:36 +02:00
|
|
|
colour = yellow
|
|
|
|
}
|
2020-03-29 05:34:17 +02:00
|
|
|
if diffed {
|
|
|
|
colour = diffTerminalColor
|
|
|
|
}
|
2020-08-23 06:20:28 +02:00
|
|
|
return []string{utils.ColoredString(f.ChangeStatus, getColorForChangeStatus(f.ChangeStatus)), colour.Sprint(f.Name)}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|