mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-09 09:22:48 +03:00
better colouring for directories for when adding a patch
This commit is contained in:
@@ -2,6 +2,7 @@ package models
|
|||||||
|
|
||||||
// CommitFile : A git commit file
|
// CommitFile : A git commit file
|
||||||
type CommitFile struct {
|
type CommitFile struct {
|
||||||
|
// TODO: rename this to Path
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
ChangeStatus string // e.g. 'A' for added or 'M' for modified. This is based on the result from git diff --name-status
|
ChangeStatus string // e.g. 'A' for added or 'M' for modified. This is based on the result from git diff --name-status
|
||||||
|
@@ -91,6 +91,24 @@ func (m *CommitFileChangeManager) ToggleCollapsed(path string) {
|
|||||||
func (m *CommitFileChangeManager) Render(diffName string, patchManager *patch.PatchManager) []string {
|
func (m *CommitFileChangeManager) Render(diffName string, patchManager *patch.PatchManager) []string {
|
||||||
return renderAux(m.tree, m.collapsedPaths, "", -1, func(n INode, depth int) string {
|
return renderAux(m.tree, m.collapsedPaths, "", -1, func(n INode, depth int) string {
|
||||||
castN := n.(*CommitFileChangeNode)
|
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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -8,21 +8,16 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"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)
|
yellow := color.New(color.FgYellow)
|
||||||
green := color.New(color.FgGreen)
|
green := color.New(color.FgGreen)
|
||||||
defaultColor := color.New(theme.DefaultTextColor)
|
defaultColor := color.New(theme.DefaultTextColor)
|
||||||
diffTerminalColor := color.New(theme.DiffTerminalColor)
|
diffTerminalColor := color.New(theme.DiffTerminalColor)
|
||||||
|
|
||||||
if commitFile == nil {
|
|
||||||
return name
|
|
||||||
}
|
|
||||||
|
|
||||||
colour := defaultColor
|
colour := defaultColor
|
||||||
if diffName == name {
|
if diffName == name {
|
||||||
colour = diffTerminalColor
|
colour = diffTerminalColor
|
||||||
} else if commitFile != nil {
|
} else {
|
||||||
status := patchManager.GetFileStatus(commitFile.Name, parent)
|
|
||||||
switch status {
|
switch status {
|
||||||
case patch.UNSELECTED:
|
case patch.UNSELECTED:
|
||||||
colour = defaultColor
|
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)
|
return utils.ColoredString(commitFile.ChangeStatus, getColorForChangeStatus(commitFile.ChangeStatus)) + " " + colour.Sprint(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user