improve the tree view render

This commit is contained in:
2026-01-01 00:16:17 +00:00
parent bf167e1d8a
commit b6c461df7c
2 changed files with 25 additions and 5 deletions
+18 -5
View File
@@ -9,9 +9,12 @@ package fstree
import (
"errors"
"mend/styles"
"mend/utils"
"path/filepath"
"strings"
"github.com/charmbracelet/lipgloss"
)
// enums for node types
@@ -116,13 +119,23 @@ func (t *FsTree) renderNode(node *FsNode, depth int, builder *strings.Builder) {
return
}
indent := strings.Repeat(" ", depth)
icon := "-"
if node.nodeType == FolderNode {
icon = "> "
indent := strings.Repeat(" ", depth)
prevIndent := strings.Repeat(" ", max(depth-1, 0))
var icon string
switch node.nodeType {
case FolderNode:
if node.expanded {
icon = indent + styles.ArrowDownIcon
} else {
icon = indent + styles.ArrowRightIcon
}
case FileNode:
icon = styles.VerticalLine
icon = lipgloss.NewStyle().Faint(true).Render(prevIndent + icon + indent)
}
line := indent + icon + " " + node.FileName() + "\n"
line := icon + " " + node.FileName() + "\n"
builder.WriteString(line)
if node.expanded {
+7
View File
@@ -24,3 +24,10 @@ var (
Width(1).
Background(Primary)
)
// ==================== icons ====================
var (
VerticalLine = "│"
ArrowDownIcon = "⌄"
ArrowRightIcon = ""
)