1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-04 03:48:07 +02:00

better colouring for directories for when adding a patch

This commit is contained in:
Jesse Duffield 2021-03-31 23:00:24 +11:00
parent 7364525bf5
commit 50c169e0a3
3 changed files with 26 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package models
// CommitFile : A git commit file
type CommitFile struct {
// TODO: rename this to Path
Name string
ChangeStatus string // e.g. 'A' for added or 'M' for modified. This is based on the result from git diff --name-status

View File

@ -91,6 +91,24 @@ func (m *CommitFileChangeManager) ToggleCollapsed(path string) {
func (m *CommitFileChangeManager) Render(diffName string, patchManager *patch.PatchManager) []string {
return renderAux(m.tree, m.collapsedPaths, "", -1, func(n INode, depth int) string {
castN := n.(*CommitFileChangeNode)
return presentation.GetCommitFileLine(castN.NameAtDepth(depth), diffName, castN.File, patchManager, m.parent)
// This is a little convoluted because we're dealing with either a leaf or a non-leaf.
// But this code actually applies to both. If it's a leaf, the status will just
// be whatever status it is, but if it's a non-leaf it will determine its status
// based on the leaves of that subtree
var status patch.PatchStatus
if castN.EveryFile(func(file *models.CommitFile) bool {
return patchManager.GetFileStatus(file.Name, m.parent) == patch.WHOLE
}) {
status = patch.WHOLE
} else if castN.EveryFile(func(file *models.CommitFile) bool {
return patchManager.GetFileStatus(file.Name, m.parent) == patch.UNSELECTED
}) {
status = patch.UNSELECTED
} else {
status = patch.PART
}
return presentation.GetCommitFileLine(castN.NameAtDepth(depth), diffName, castN.File, status)
})
}

View File

@ -8,21 +8,16 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils"
)
func GetCommitFileLine(name string, diffName string, commitFile *models.CommitFile, patchManager *patch.PatchManager, parent string) string {
func GetCommitFileLine(name string, diffName string, commitFile *models.CommitFile, status patch.PatchStatus) string {
yellow := color.New(color.FgYellow)
green := color.New(color.FgGreen)
defaultColor := color.New(theme.DefaultTextColor)
diffTerminalColor := color.New(theme.DiffTerminalColor)
if commitFile == nil {
return name
}
colour := defaultColor
if diffName == name {
colour = diffTerminalColor
} else if commitFile != nil {
status := patchManager.GetFileStatus(commitFile.Name, parent)
} else {
switch status {
case patch.UNSELECTED:
colour = defaultColor
@ -33,6 +28,10 @@ func GetCommitFileLine(name string, diffName string, commitFile *models.CommitFi
}
}
if commitFile == nil {
return colour.Sprint(name)
}
return utils.ColoredString(commitFile.ChangeStatus, getColorForChangeStatus(commitFile.ChangeStatus)) + " " + colour.Sprint(name)
}