improve the tree view render
This commit is contained in:
+18
-5
@@ -9,9 +9,12 @@ package fstree
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"mend/styles"
|
||||||
"mend/utils"
|
"mend/utils"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/charmbracelet/lipgloss"
|
||||||
)
|
)
|
||||||
|
|
||||||
// enums for node types
|
// enums for node types
|
||||||
@@ -116,13 +119,23 @@ func (t *FsTree) renderNode(node *FsNode, depth int, builder *strings.Builder) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
indent := strings.Repeat(" ", depth)
|
indent := strings.Repeat(" ", depth)
|
||||||
icon := "-"
|
prevIndent := strings.Repeat(" ", max(depth-1, 0))
|
||||||
if node.nodeType == FolderNode {
|
|
||||||
icon = "> "
|
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)
|
builder.WriteString(line)
|
||||||
|
|
||||||
if node.expanded {
|
if node.expanded {
|
||||||
|
|||||||
@@ -24,3 +24,10 @@ var (
|
|||||||
Width(1).
|
Width(1).
|
||||||
Background(Primary)
|
Background(Primary)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ==================== icons ====================
|
||||||
|
var (
|
||||||
|
VerticalLine = "│"
|
||||||
|
ArrowDownIcon = "⌄"
|
||||||
|
ArrowRightIcon = "›"
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user