add file content render
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user