From b6c461df7c3fe2438a85cd61fdb451d27dfbcd1d Mon Sep 17 00:00:00 2001 From: ruinivist Date: Thu, 1 Jan 2026 00:16:17 +0000 Subject: [PATCH] improve the tree view render --- fstree/fstree.go | 23 ++++++++++++++++++----- styles/styles.go | 7 +++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/fstree/fstree.go b/fstree/fstree.go index 54d75ec..a986da8 100644 --- a/fstree/fstree.go +++ b/fstree/fstree.go @@ -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 { diff --git a/styles/styles.go b/styles/styles.go index 0a3c1f7..69e3e5f 100644 --- a/styles/styles.go +++ b/styles/styles.go @@ -24,3 +24,10 @@ var ( Width(1). Background(Primary) ) + +// ==================== icons ==================== +var ( + VerticalLine = "│" + ArrowDownIcon = "⌄" + ArrowRightIcon = "›" +)