add file content render

This commit is contained in:
2026-01-01 01:54:05 +00:00
parent 5acfa16368
commit ee40c47864
3 changed files with 41 additions and 6 deletions
+3 -2
View File
@@ -57,9 +57,10 @@ func TestWalkFileSystemAndBuildTree(t *testing.T) {
t.Errorf("child %q parent pointer incorrect", child.FileName())
}
if child.nodeType == FileNode {
switch child.nodeType {
case FileNode:
fileCount++
} else if child.nodeType == FolderNode {
case FolderNode:
folderCount++
if child.FileName() == "folder1" {
folder1 = child
+17
View File
@@ -11,6 +11,7 @@ import (
"errors"
"mend/styles"
"mend/utils"
"os"
"path/filepath"
"strings"
@@ -195,6 +196,22 @@ func (t *FsTree) ToggleSelectedExpand() error {
return nil
}
func (t *FsTree) GetSelectedContent() (string, error) {
if t.selected == nil {
return "", errors.New("no node is currently selected")
}
if t.selected.nodeType != FileNode {
return "", nil
}
contentBytes, err := os.ReadFile(t.selected.path)
if err != nil {
return "", err
}
return string(contentBytes), nil
}
func (t *FsTree) Render() string {
builder := &strings.Builder{}
t.renderNode(t.root, 0, builder)