From d156142f5741f4dad480878e46eb18ead6313499 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 16 Jul 2020 15:37:48 -0400 Subject: [PATCH] Press "r" to view errors in the stash --- ui/stash.go | 27 +++++++++++++++++++++++---- ui/ui.go | 6 +++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ui/stash.go b/ui/stash.go index 60fe4d1..cbba85c 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -103,6 +103,7 @@ type stashModel struct { cc *charm.Client state stashState err error + showError bool markdowns []*markdown spinner spinner.Model noteInput textinput.Model @@ -266,6 +267,8 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { switch m.state { case stashStateReady: + + // Handle keys if msg, ok := msg.(tea.KeyMsg); ok { switch msg.String() { @@ -338,7 +341,20 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { m.state = stashStatePromptDelete } + // Show errors + case "r": + if m.err != nil && !m.showError { + m.showError = true + return m, nil + } + } + + // If the error view is visible any key hides it. + if m.showError { + m.showError = false + } + } // Update paginator @@ -426,6 +442,10 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { // VIEW func stashView(m stashModel) string { + if m.showError { + return errorView(m.err) + } + var s string switch m.state { case stashStateLoadingDocument: @@ -461,10 +481,6 @@ func stashView(m stashModel) string { header = stashHeaderView(m) } - if m.err != nil { - header = m.err.Error() - } - var pagination string if m.paginator.TotalPages > 1 { pagination = paginator.View(m.paginator) @@ -599,6 +615,9 @@ func stashHelpView(m stashModel) string { if isStashed && len(m.markdowns) > 0 { h = append(h, []string{"x: delete", "m: set memo"}...) } + if m.err != nil { + h = append(h, []string{"r: errors"}...) + } h = append(h, []string{"esc: exit"}...) } return common.HelpView(h...) diff --git a/ui/ui.go b/ui/ui.go index 60b7cd3..02dbc96 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -323,7 +323,7 @@ func view(mdl tea.Model) string { } if m.fatalErr != nil { - return fatalErrorView(m.fatalErr) + return errorView(m.fatalErr) } var s string @@ -338,7 +338,7 @@ func view(mdl tea.Model) string { return "\n" + indent(s, 2) } -func fatalErrorView(err error) string { +func errorView(err error) string { s := fmt.Sprintf("%s\n\n%v\n\n%s", te.String(" ERROR "). Foreground(common.Cream.Color()). @@ -347,7 +347,7 @@ func fatalErrorView(err error) string { err, common.Subtle("Press any key to exit"), ) - return "\n" + indent(s, 2) + return "\n" + indent(s, 3) } // COMMANDS