remove rendundant fsTree inferface

This commit is contained in:
2025-12-31 03:32:54 +00:00
parent 74113ccdc0
commit c59bdad8aa
2 changed files with 8 additions and 20 deletions
+6 -18
View File
@@ -38,21 +38,11 @@ func (n *FsNode) FileName() string {
} }
// ==================== FsNode definition ==================== // ==================== FsNode definition ====================
type FsTree struct {
// ==================== FsTree definition ====================
type FsTree interface {
CreateNode(parent *FsNode, name string, nodeType FsNodeType) error
DeleteNode(node *FsNode) error
ToggleExpand(node *FsNode) error
}
// reminder: a bit redundant but I this above shows what funcs are there at a glace
// so I still like to use this pattern ( 30Dec25)
type FsTreeImpl struct {
root *FsNode root *FsNode
} }
func NewFsTree(rootPath string) *FsTreeImpl { func NewFsTree(rootPath string) *FsTree {
root := &FsNode{ root := &FsNode{
nodeType: FolderNode, nodeType: FolderNode,
path: rootPath, path: rootPath,
@@ -61,12 +51,12 @@ func NewFsTree(rootPath string) *FsTreeImpl {
} }
walkFileSystemAndBuildTree(rootPath, root) walkFileSystemAndBuildTree(rootPath, root)
return &FsTreeImpl{ return &FsTree{
root: root, root: root,
} }
} }
func (t *FsTreeImpl) CreateNode(parent *FsNode, name string, nodeType FsNodeType) error { func (t *FsTree) CreateNode(parent *FsNode, name string, nodeType FsNodeType) error {
if parent == nil { if parent == nil {
return errors.New("parent node cannot be nil") return errors.New("parent node cannot be nil")
} }
@@ -89,7 +79,7 @@ func (t *FsTreeImpl) CreateNode(parent *FsNode, name string, nodeType FsNodeType
return nil return nil
} }
func (t *FsTreeImpl) DeleteNode(node *FsNode) error { func (t *FsTree) DeleteNode(node *FsNode) error {
if node == nil { if node == nil {
return errors.New("node to delete cannot be nil") return errors.New("node to delete cannot be nil")
} }
@@ -103,7 +93,7 @@ func (t *FsTreeImpl) DeleteNode(node *FsNode) error {
} }
// ToggleExpand toggles the expanded state of a node // ToggleExpand toggles the expanded state of a node
func (t *FsTreeImpl) ToggleExpand(node *FsNode) error { func (t *FsTree) ToggleExpand(node *FsNode) error {
if node == nil { if node == nil {
return errors.New("node cannot be nil") return errors.New("node cannot be nil")
} }
@@ -114,5 +104,3 @@ func (t *FsTreeImpl) ToggleExpand(node *FsNode) error {
node.expanded = !node.expanded node.expanded = !node.expanded
return nil return nil
} }
// ==================== FsTree definition ====================
+2 -2
View File
@@ -38,7 +38,7 @@ this data in msg when returned to the update func is used to update the model
type model struct { type model struct {
width int width int
tree *fs.FsTreeImpl tree *fs.FsTree
// spinner needs to be state as I need to update the spinner on // spinner needs to be state as I need to update the spinner on
// each tick in update func // each tick in update func
spinner spinner.Model spinner spinner.Model
@@ -63,7 +63,7 @@ func createModel() model {
// these need to be on the "model" ( duck typing "implements" interface ) // these need to be on the "model" ( duck typing "implements" interface )
type treeLoadedMsg struct { type treeLoadedMsg struct {
tree *fs.FsTreeImpl tree *fs.FsTree
} }
func loadTreeCmd() tea.Msg { func loadTreeCmd() tea.Msg {