refactor fstree to separate package
This commit is contained in:
@@ -6,7 +6,7 @@ fileopen
|
|||||||
- ruinivist, 30Dec25
|
- ruinivist, 30Dec25
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package fstree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@@ -3,7 +3,7 @@ another test that is entirely ae ayee generated
|
|||||||
- ruinivist, 30Dec25
|
- ruinivist, 30Dec25
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package fstree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
@@ -5,10 +5,11 @@ It is initialised at startup and used for state changes in UI and later persiste
|
|||||||
- ruinivist, 30Dec25
|
- ruinivist, 30Dec25
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package fstree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"mend/utils"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -97,7 +98,7 @@ func (t *FsTreeImpl) DeleteNode(node *FsNode) error {
|
|||||||
return errors.New("node to delete must have a parent")
|
return errors.New("node to delete must have a parent")
|
||||||
}
|
}
|
||||||
|
|
||||||
parent.children = RemoveFromSlice(parent.children, node)
|
parent.children = utils.RemoveFromSlice(parent.children, node)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5,7 +5,7 @@ few good uses of ae ayee in my opinion
|
|||||||
- ruinivist, 30Dec25
|
- ruinivist, 30Dec25
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package fstree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -6,6 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
fs "mend/fstree"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/spinner"
|
"github.com/charmbracelet/bubbles/spinner"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
@@ -36,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 *FsTreeImpl
|
tree *fs.FsTreeImpl
|
||||||
// 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
|
||||||
@@ -61,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 *FsTreeImpl
|
tree *fs.FsTreeImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadTreeCmd() tea.Msg {
|
func loadTreeCmd() tea.Msg {
|
||||||
@@ -72,7 +74,7 @@ func loadTreeCmd() tea.Msg {
|
|||||||
fmt.Println("Error getting cwd:", err)
|
fmt.Println("Error getting cwd:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
return treeLoadedMsg{tree: NewFsTree(cwd)}
|
return treeLoadedMsg{tree: fs.NewFsTree(cwd)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m model) Init() tea.Cmd {
|
func (m model) Init() tea.Cmd {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package utils
|
||||||
|
|
||||||
// Removes the first occurence from the slice. Worst case O(n)
|
// Removes the first occurence from the slice. Worst case O(n)
|
||||||
func RemoveFromSlice[T comparable](slice []T, item T) []T {
|
func RemoveFromSlice[T comparable](slice []T, item T) []T {
|
||||||
Reference in New Issue
Block a user