~mariusor/motley

9275b26d47de239c0902b0ba2f28d028e20cc85a — Marius Orcsik 4 months ago 00f39b6
Improvements to statusbar ticker
4 files changed, 55 insertions(+), 57 deletions(-)

M fedbox.go
M item_model.go
M statusbar.go
M ui.go
M fedbox.go => fedbox.go +10 -10
@@ 333,7 333,7 @@ func getObjectElements(ob pub.Object, parent *n) []*n {

func getActorElements(act pub.Actor, parent *n) []*n {
	result := make([]*n, 0)
	pub.OnObject(&act, func(o *pub.Object) error {
	_ = pub.OnObject(&act, func(o *pub.Object) error {
		result = append(result, getObjectElements(*o, parent)...)
		return nil
	})


@@ 363,7 363,7 @@ func getItemElements(parent *n) []*n {
	it := parent.Item

	if pub.IsItemCollection(it) {
		pub.OnItemCollection(it, func(c *pub.ItemCollection) error {
		_ = pub.OnItemCollection(it, func(c *pub.ItemCollection) error {
			for _, ob := range c.Collection() {
				result = append(result, node(ob, withParent(parent)))
			}


@@ 371,13 371,13 @@ func getItemElements(parent *n) []*n {
		})
	}
	if pub.ActorTypes.Contains(it.GetType()) {
		pub.OnActor(it, func(act *pub.Actor) error {
		_ = pub.OnActor(it, func(act *pub.Actor) error {
			result = append(result, getActorElements(*act, parent)...)
			return nil
		})
	}
	if pub.ActivityTypes.Contains(it.GetType()) || pub.ObjectTypes.Contains(it.GetType()) {
		pub.OnObject(it, func(act *pub.Object) error {
		_ = pub.OnObject(it, func(act *pub.Object) error {
			result = append(result, getObjectElements(*act, parent)...)
			return nil
		})


@@ 408,10 408,10 @@ func (m *model) loadDepsForNode(ctx context.Context, node *n) tea.Cmd {
		return nil
	})
	go func() {
		g.Wait()
		_ = g.Wait()
		node.s ^= NodeSyncing
	}()
	return m.status.spinner.Tick
	return m.status.startedLoading
}

func (m *model) loadChildrenForNode(ctx context.Context, nn *n) error {


@@ 440,7 440,7 @@ func dereferenceIRIs(ctx context.Context, f *fedbox, iris pub.ItemCollection) pu
	items := make(pub.ItemCollection, 0, len(iris))
	for _, it := range iris {
		if deref := dereferenceIRI(ctx, f, it); pub.IsItemCollection(deref) {
			pub.OnItemCollection(deref, func(col *pub.ItemCollection) error {
			_ = pub.OnItemCollection(deref, func(col *pub.ItemCollection) error {
				items = append(items, pub.ItemCollectionDeduplication(col)...)
				return nil
			})


@@ 657,9 657,9 @@ func emptyAccum(_ context.Context, _ pub.CollectionInterface) error {
}

func (a accumFn) LoadFromSearch(ctx context.Context, f *fedbox, iris ...pub.IRI) error {
	var cancelFn func()
	var cancel func()

	ctx, cancelFn = context.WithCancel(ctx)
	ctx, cancel = context.WithCancel(ctx)
	g, gtx := errgroup.WithContext(ctx)

	for _, iri := range iris {


@@ 668,7 668,7 @@ func (a accumFn) LoadFromSearch(ctx context.Context, f *fedbox, iris ...pub.IRI)
	if err := g.Wait(); err != nil {
		if errors.Is(err, StopLoad{}) {
			f.logFn("stopped loading search")
			cancelFn()
			cancel()
		} else {
			f.logFn("%s", err)
			return err

M item_model.go => item_model.go +11 -9
@@ 275,20 275,22 @@ func (i itemModel) Init() tea.Cmd {

func (i itemModel) updateAsModel(msg tea.Msg) (itemModel, tea.Cmd) {
	cmds := make([]tea.Cmd, 0)
	switch msg := msg.(type) {
	switch mm := msg.(type) {
	case tea.WindowSizeMsg:
		i.logFn("item resize: %+v", msg)
	case nodeUpdateMsg:
		i.item = msg.Item
		ob := newObjectModel()
		err := vocab.OnObject(i.item, ob.updateObject)
		if err != nil {
			cmds = append(cmds, errCmd(err))
		} else {
			i.model = ob
		if mm.n != nil {
			i.item = mm.n.Item
			ob := newObjectModel()
			err := vocab.OnObject(i.item, ob.updateObject)
			if err != nil {
				cmds = append(cmds, errCmd(err))
			} else {
				i.model = ob
			}
		}
	case tea.KeyMsg:
		switch msg.String() {
		switch mm.String() {
		case "home", "g":
			i.viewport.GotoTop()
			if i.viewport.HighPerformanceRendering {

M statusbar.go => statusbar.go +11 -18
@@ 52,8 52,6 @@ type statusModel struct {
	timer *time.Timer
}

var glowLogoTextColor = Color("#ECFD65")

func initializeSpinner() spinner.Model {
	sp := spinner.New()
	sp.Style = lipgloss.NewStyle().Bold(true)


@@ 63,8 61,6 @@ func initializeSpinner() spinner.Model {
}

func newStatusModel(common *commonModel) statusModel {
	// Text input for search

	return statusModel{
		commonModel: common,
		spinner:     initializeSpinner(),


@@ 151,42 147,39 @@ func (a statusNode) View() string {
func (s *statusModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	var cmd tea.Cmd

	switch msg := msg.(type) {
	switch mm := msg.(type) {
	case error:
		cmd = s.showError(msg)
		cmd = s.showError(mm)
	case spinner.TickMsg:
		if s.state.Is(statusBusy) {
			cmd = s.spin(msg)
		}
	case nodeUpdateMsg:
		cmd = s.showStatusMessage(statusNode{msg.n}.View())
		if mm.n != nil {
			cmd = s.showStatusMessage(statusNode{mm.n}.View())
		}
	case statusState:
		//if !msg.Is(statusError) && s.state.Is(statusError) {
		//	s.state ^= statusError
		//}
		s.state |= msg
		if msg.Is(statusBusy) {
			s.logFn("starting spinner")
			cmd = s.spinner.Tick
		} else {
		s.state |= mm
		if !s.state.Is(statusBusy) {
			s.logFn("stopping spinner")
			initializeSpinner()
			s.spinner = initializeSpinner()
		}
	case percentageMsg:
		s.percent = float64(msg) * 100.0
		s.percent = float64(mm) * 100.0
	}

	return s, cmd
}

func (s *statusModel) startedLoading() tea.Msg {
	s.state = s.state | statusBusy
	return nil
	return s.state | statusBusy
}

func (s *statusModel) stoppedLoading() tea.Msg {
	s.state = s.state ^ statusBusy
	return nil
	return s.state ^ statusBusy
}

func (s *statusModel) View() string {

M ui.go => ui.go +23 -20
@@ 191,24 191,27 @@ func nodeUpdateCmd(n *n) tea.Cmd {
func (m *model) update(msg tea.Msg) tea.Cmd {
	cmds := make([]tea.Cmd, 0)

	switch msg := msg.(type) {
	switch mm := msg.(type) {
	case *n:
		m.currentNodePosition = m.tree.list.Cursor()
		m.currentNode = msg
		ctx, _ := context.WithTimeout(context.Background(), time.Millisecond*300)
		cmd := m.loadDepsForNode(ctx, m.currentNode)
		for _, st := range m.f.stores {
			if msg.GetLink().Contains(st.root.GetLink(), true) {
				m.root = st.root
				break
		if mm != nil {
			m.currentNodePosition = m.tree.list.Cursor()
			m.currentNode = mm
			ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*300)
			defer cancel()
			cmd := m.loadDepsForNode(ctx, m.currentNode)
			for _, st := range m.f.stores {
				if mm.GetLink().Contains(st.root.GetLink(), true) {
					m.root = st.root
					break
				}
			}
			cmds = append(cmds, nodeUpdateCmd(m.currentNode), cmd)
		}
		cmds = append(cmds, nodeUpdateCmd(m.currentNode), cmd)
	case advanceMsg:
		cmds = append(cmds, m.Advance(msg))
		cmds = append(cmds, m.Advance(mm))
	case tea.KeyMsg:
		switch {
		case key.Matches(msg, movePane):
		case key.Matches(mm, movePane):
			if m.tree.list.Focused() {
				m.tree.list.Blur()
			} else {


@@ 216,18 219,18 @@ func (m *model) update(msg tea.Msg) tea.Cmd {
				// the model.Tree sets cursor to -1 when bluring, so we need to add an extra +1
				cmds = append(cmds, m.tree.list.SetCursor(m.currentNodePosition))
			}
		case key.Matches(msg, quitKey):
		case key.Matches(mm, quitKey):
			return quitCmd
		case key.Matches(msg, helpKey):
		case key.Matches(mm, helpKey):
			return tea.Batch(showHelpCmd(), resizeCmd(m.width, m.height))
		case key.Matches(msg, advanceKey):
		case key.Matches(mm, advanceKey):
			return advanceCmd(m.currentNode)
		case key.Matches(msg, backKey):
			return m.Back(msg)
		case key.Matches(mm, backKey):
			return m.Back(mm)
		}

	case tea.WindowSizeMsg:
		m.setSize(msg.Width, msg.Height)
		m.setSize(mm.Width, mm.Height)
		return m.tree.list.SetCursor(m.currentNodePosition)
	case quitMsg:
		return tea.Quit


@@ 239,8 242,8 @@ func (m *model) update(msg tea.Msg) tea.Cmd {
			cmds = append(cmds, m.status.startedLoading)
		}
	}
	if m.status.state.Is(statusBusy) && !m.tree.IsSyncing() {
		cmds = append(cmds, m.status.stoppedLoading, nodeUpdateCmd(m.currentNode))
	if !m.tree.IsSyncing() {
		cmds = append(cmds, nodeUpdateCmd(m.currentNode))
	}
	cmds = append(cmds, m.updatePager(msg))
	cmds = append(cmds, m.updateStatusBar(msg))