mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-29 22:48:24 +02:00
Let users to define custom icons and color for files on the config file
Co-authored-by: Stefan Haller <stefan@haller-berlin.de>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/gookit/color"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||
@@ -23,12 +24,13 @@ func RenderFileTree(
|
||||
submoduleConfigs []*models.SubmoduleConfig,
|
||||
showFileIcons bool,
|
||||
showNumstat bool,
|
||||
customIconsConfig *config.CustomIconsConfig,
|
||||
) []string {
|
||||
collapsedPaths := tree.CollapsedPaths()
|
||||
return renderAux(tree.GetRoot().Raw(), collapsedPaths, -1, -1, func(node *filetree.Node[models.File], treeDepth int, visualDepth int, isCollapsed bool) string {
|
||||
fileNode := filetree.NewFileNode(node)
|
||||
|
||||
return getFileLine(isCollapsed, fileNode.GetHasUnstagedChanges(), fileNode.GetHasStagedChanges(), treeDepth, visualDepth, showNumstat, showFileIcons, submoduleConfigs, node)
|
||||
return getFileLine(isCollapsed, fileNode.GetHasUnstagedChanges(), fileNode.GetHasStagedChanges(), treeDepth, visualDepth, showNumstat, showFileIcons, submoduleConfigs, node, customIconsConfig)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -36,12 +38,13 @@ func RenderCommitFileTree(
|
||||
tree *filetree.CommitFileTreeViewModel,
|
||||
patchBuilder *patch.PatchBuilder,
|
||||
showFileIcons bool,
|
||||
customIconsConfig *config.CustomIconsConfig,
|
||||
) []string {
|
||||
collapsedPaths := tree.CollapsedPaths()
|
||||
return renderAux(tree.GetRoot().Raw(), collapsedPaths, -1, -1, func(node *filetree.Node[models.CommitFile], treeDepth int, visualDepth int, isCollapsed bool) string {
|
||||
status := commitFilePatchStatus(node, tree, patchBuilder)
|
||||
|
||||
return getCommitFileLine(isCollapsed, treeDepth, visualDepth, node, status, showFileIcons)
|
||||
return getCommitFileLine(isCollapsed, treeDepth, visualDepth, node, status, showFileIcons, customIconsConfig)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -116,6 +119,7 @@ func getFileLine(
|
||||
showFileIcons bool,
|
||||
submoduleConfigs []*models.SubmoduleConfig,
|
||||
node *filetree.Node[models.File],
|
||||
customIconsConfig *config.CustomIconsConfig,
|
||||
) string {
|
||||
name := fileNameAtDepth(node, treeDepth)
|
||||
output := ""
|
||||
@@ -156,7 +160,7 @@ func getFileLine(
|
||||
isDirectory := file == nil
|
||||
|
||||
if showFileIcons {
|
||||
icon := icons.IconForFile(name, isSubmodule, isLinkedWorktree, isDirectory)
|
||||
icon := icons.IconForFile(name, isSubmodule, isLinkedWorktree, isDirectory, customIconsConfig)
|
||||
paint := color.HEX(icon.Color, false)
|
||||
output += paint.Sprint(icon.Icon) + nameColor.Sprint(" ")
|
||||
}
|
||||
@@ -218,6 +222,7 @@ func getCommitFileLine(
|
||||
node *filetree.Node[models.CommitFile],
|
||||
status patch.PatchStatus,
|
||||
showFileIcons bool,
|
||||
customIconsConfig *config.CustomIconsConfig,
|
||||
) string {
|
||||
indentation := strings.Repeat(" ", visualDepth)
|
||||
name := commitFileNameAtDepth(node, treeDepth)
|
||||
@@ -266,7 +271,7 @@ func getCommitFileLine(
|
||||
isLinkedWorktree := false
|
||||
|
||||
if showFileIcons {
|
||||
icon := icons.IconForFile(name, isSubmodule, isLinkedWorktree, isDirectory)
|
||||
icon := icons.IconForFile(name, isSubmodule, isLinkedWorktree, isDirectory, customIconsConfig)
|
||||
paint := color.HEX(icon.Color, false)
|
||||
output += paint.Sprint(icon.Icon) + " "
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/gookit/color"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -91,7 +92,7 @@ func TestRenderFileTree(t *testing.T) {
|
||||
for _, path := range s.collapsedPaths {
|
||||
viewModel.ToggleCollapsed(path)
|
||||
}
|
||||
result := RenderFileTree(viewModel, nil, false, s.showLineChanges)
|
||||
result := RenderFileTree(viewModel, nil, false, s.showLineChanges, &config.CustomIconsConfig{})
|
||||
assert.EqualValues(t, s.expected, result)
|
||||
})
|
||||
}
|
||||
@@ -161,7 +162,7 @@ func TestRenderCommitFileTree(t *testing.T) {
|
||||
},
|
||||
)
|
||||
patchBuilder.Start("from", "to", false, false)
|
||||
result := RenderCommitFileTree(viewModel, patchBuilder, false)
|
||||
result := RenderCommitFileTree(viewModel, patchBuilder, false, &config.CustomIconsConfig{})
|
||||
assert.EqualValues(t, s.expected, result)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package icons
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
)
|
||||
|
||||
// NOTE: Visit next links for inspiration:
|
||||
@@ -763,13 +765,19 @@ func patchFileIconsForNerdFontsV2() {
|
||||
extIconMap[".vue"] = IconProperties{Icon: "\ufd42", Color: "#89e051"} // ﵂
|
||||
}
|
||||
|
||||
func IconForFile(name string, isSubmodule bool, isLinkedWorktree bool, isDirectory bool) IconProperties {
|
||||
func IconForFile(name string, isSubmodule bool, isLinkedWorktree bool, isDirectory bool, customIconsConfig *config.CustomIconsConfig) IconProperties {
|
||||
base := filepath.Base(name)
|
||||
if icon, ok := customIconsConfig.Filenames[base]; ok {
|
||||
return IconProperties{Color: icon.Color, Icon: icon.Icon}
|
||||
}
|
||||
if icon, ok := nameIconMap[base]; ok {
|
||||
return icon
|
||||
}
|
||||
|
||||
ext := strings.ToLower(filepath.Ext(name))
|
||||
if icon, ok := customIconsConfig.Extensions[ext]; ok {
|
||||
return IconProperties{Color: icon.Color, Icon: icon.Icon}
|
||||
}
|
||||
if icon, ok := extIconMap[ext]; ok {
|
||||
return icon
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user