diff options
author | Christian Rocha <christian@rocha.is> | 2020-07-16 15:37:48 -0400 |
---|---|---|
committer | Christian Muehlhaeuser <muesli@gmail.com> | 2020-10-05 13:50:04 +0200 |
commit | d156142f5741f4dad480878e46eb18ead6313499 (patch) | |
tree | b044a2ec3aa1c0fd93bc9eb17ec0198703eb5d1b /ui | |
parent | e8eea0b1a1529b82a86ac63f0f84d268288e7bad (diff) |
Press "r" to view errors in the stash
Diffstat (limited to 'ui')
-rw-r--r-- | ui/stash.go | 27 | ||||
-rw-r--r-- | 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...) @@ -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 |