~mariusor/motley

a261692024710f4b5bce1528f5f2e31c93cad0a7 — Marius Orcsik 4 months ago a79499f
Improve errors displayed in the status bar
2 files changed, 11 insertions(+), 2 deletions(-)

M statusbar.go
M ui.go
M statusbar.go => statusbar.go +10 -1
@@ 15,6 15,8 @@ import (
	"github.com/muesli/reflow/margin"
	"github.com/muesli/reflow/truncate"
	te "github.com/muesli/termenv"
	"golang.org/x/text/language"
	"golang.org/x/text/cases"
)

type statusState uint8


@@ 89,6 91,13 @@ func (s *statusModel) showStatusMessage(statusMessage string) tea.Cmd {
	return nil
}

func ucfirst(s string) string {
	pieces := strings.SplitN(s, " ", 2)
	if len(pieces) > 0 {
		pieces[0] = cases.Title(language.English).String(pieces[0])
	}
	return strings.Join(pieces, " ")
}
func (s *statusModel) statusBarView(b *strings.Builder) {
	percent := clamp(int(math.Round(s.percent)), 0, 100)
	scrollPercent := fmt.Sprintf(" %d%% ", percent)


@@ 101,7 110,7 @@ func (s *statusModel) statusBarView(b *strings.Builder) {
	message := truncate.StringWithTail(s.message, uint(w), ellipsis)
	if s.error != nil {
		render = statusBarFailStyle
		message = s.error.Error()
		message = ucfirst(s.error.Error())
	}

	b.WriteString(s.logo)

M ui.go => ui.go +1 -1
@@ 328,7 328,7 @@ func (m *model) Advance(msg advanceMsg) tea.Cmd {
	name := getRootNodeName(msg.n)
	newNode := node(msg.Item, withParent(msg.n), withName(name))
	if err := m.loadChildrenForNode(context.Background(), newNode); err != nil {
		return errCmd(fmt.Errorf("%s", msg.n.n))
		return errCmd(fmt.Errorf("unable to advance to %q: %w", msg.n.n, err))
	}
	if newNode.s.Is(tree.NodeCollapsible) && len(newNode.c) == 0 {
		return errCmd(fmt.Errorf("no items in collection %s", name))