Press "r" to view errors in the stash

This commit is contained in:
Christian Rocha 2020-07-16 15:37:48 -04:00 committed by Christian Muehlhaeuser
commit d156142f57
2 changed files with 26 additions and 7 deletions

View file

@ -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...)

View file

@ -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