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
+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)