~mariusor/motley

e38d19f08e6a8dc1dc16b4d35ec30fc430669d57 — Marius Orcsik 4 months ago 21161e8
Don't assume states on root nodes
8 files changed, 34 insertions(+), 22 deletions(-)

M fedbox.go
M go.mod
M item_model.go
M natural_language_values_model.go
M object_model.go
M statusbar.go
M tree.go
M ui.go
M fedbox.go => fedbox.go +8 -3
@@ 113,10 113,14 @@ func (f *fedbox) getRootNodes() pub.ItemCollection {

func initNodes(f *fedbox) tree.Nodes {
	nodes := make(tree.Nodes, 0)
	var state tree.NodeState
	if len(f.getRootNodes()) == 1 {
		state = tree.NodeLastChild
	}
	for _, root := range f.getRootNodes() {
		nodes = append(nodes, node(
			root,
			withState(tree.NodeLastChild|tree.NodeSelected),
			withState(state),
		))
	}
	return nodes


@@ 136,8 140,9 @@ func (n *n) Parent() tree.Node {
	}
	return n.p
}

func (n *n) Init() tea.Cmd {
	return nil
	return noop
}

func nodeIsError(n *n) bool {


@@ 211,7 216,7 @@ func (n *n) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	case tree.NodeState:
		n.s = m
	}
	return n, nil
	return n, noop
}

func (n *n) setChildren(c ...*n) {

M go.mod => go.mod +3 -3
@@ 17,7 17,7 @@ require (
	github.com/go-ap/storage-fs v0.0.0-20231114164216-ebc6b6d920df
	github.com/go-ap/storage-sqlite v0.0.0-20231112181059-f32529430fb8
	github.com/joho/godotenv v1.5.1
	github.com/mariusor/bubbles-tree v0.0.0-20231125100711-470a628f4cfa
	github.com/mariusor/bubbles-tree v0.0.0-20231130175756-6f4f8acb1d0e
	github.com/mariusor/qstring v0.0.0-20200204164351-5a99d46de39d
	github.com/mattn/go-runewidth v0.0.15
	github.com/muesli/reflow v0.3.0


@@ 76,8 76,8 @@ require (
	golang.org/x/mod v0.14.0 // indirect
	golang.org/x/net v0.18.0 // indirect
	golang.org/x/oauth2 v0.14.0 // indirect
	golang.org/x/sys v0.14.0 // indirect
	golang.org/x/term v0.14.0 // indirect
	golang.org/x/sys v0.15.0 // indirect
	golang.org/x/term v0.15.0 // indirect
	golang.org/x/tools v0.15.0 // indirect
	google.golang.org/appengine v1.6.8 // indirect
	google.golang.org/protobuf v1.31.0 // indirect

M item_model.go => item_model.go +1 -3
@@ 270,7 270,7 @@ func newItemModel(common *commonModel) itemModel {
}
func (i itemModel) Init() tea.Cmd {
	i.logFn("Item View init")
	return nil
	return noop
}

func (i itemModel) updateAsModel(msg tea.Msg) (itemModel, tea.Cmd) {


@@ 309,8 309,6 @@ func (i itemModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	return i.updateAsModel(msg)
}

type collectionModel struct{}

func ItemType(o vocab.Item) string {
	if typ := string(o.GetType()); typ != "" {
		return typ

M natural_language_values_model.go => natural_language_values_model.go +2 -2
@@ 44,11 44,11 @@ func NewNaturalLanguageValues(label string, val vocab.NaturalLanguageValues) Nat
}

func (n NaturalLanguageValues) Init() tea.Cmd {
	return nil
	return noop
}

func (n NaturalLanguageValues) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	return n, nil
	return n, noop
}

func (n NaturalLanguageValues) renderLabel() string {

M object_model.go => object_model.go +2 -2
@@ 29,11 29,11 @@ func newObjectModel() ObjectModel {
}

func (o ObjectModel) Init() tea.Cmd {
	return nil
	return noop
}

func (o ObjectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	return o, nil
	return o, noop
}

func mimeIsBinary(mimeType vocab.MimeType) bool {

M statusbar.go => statusbar.go +3 -3
@@ 73,12 73,12 @@ func newStatusModel(common *commonModel) statusModel {

func (s *statusModel) Init() tea.Cmd {
	s.logFn("Status Bar init")
	return nil
	return noop
}

func (s *statusModel) showError(err error) tea.Cmd {
	s.error = err
	return nil
	return noop
}

func (s *statusModel) showStatusMessage(statusMessage string) tea.Cmd {


@@ 87,7 87,7 @@ func (s *statusModel) showStatusMessage(statusMessage string) tea.Cmd {
	}
	s.message = statusMessage
	s.error = nil
	return nil
	return noop
}

func ucfirst(s string) string {

M tree.go => tree.go +2 -2
@@ 41,7 41,7 @@ func (t *treeModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
		return t, tea.Batch(cmd, percentageChanged(t.list.ScrollPercent()))
	}

	return t, nil
	return t, noop
}

const treeWidth = 32


@@ 69,7 69,7 @@ func (t *treeModel) width() int {
func (t *treeModel) Back(previous *tree.Model) (tea.Model, tea.Cmd) {
	previous.Focus()
	t.list = previous
	return t, nil
	return t, noop
}

func (t *treeModel) Advance(current *n) *tree.Model {

M ui.go => ui.go +13 -4
@@ 297,13 297,17 @@ var (
func (m *model) Back(msg tea.Msg) tea.Cmd {
	if len(m.breadCrumbs) == 0 {
		m.logFn("No previous tree to go back to.")
		return nil
		return noop
	}
	if oldTree := m.breadCrumbs[len(m.breadCrumbs)-1]; oldTree != nil {
		m.tree.Back(oldTree)
		m.breadCrumbs = m.breadCrumbs[:len(m.breadCrumbs)-1]
	}
	return nil
	return noop
}

func noop() tea.Msg {
	return "noop"
}

func advanceCmd(n *n) tea.Cmd {


@@ 320,10 324,15 @@ func getRootNodeName(n *n) string {
	return name
}

func (m *model) shouldAdvance() bool {
	children := m.tree.list.Children()
	return len(children) == 1 && children[0] == m.currentNode
}

func (m *model) Advance(msg advanceMsg) tea.Cmd {
	if top := m.tree.list.Children()[0]; top == m.currentNode {
	if !m.shouldAdvance() {
		m.logFn("will not advance to top of the tree")
		return nil
		return noop
	}

	if msg.n == nil {