summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Rocha <christian@rocha.is>2020-07-16 15:54:55 -0400
committerChristian Muehlhaeuser <muesli@gmail.com>2020-10-05 13:50:04 +0200
commit74aad5324ace6f51e74717556bea8d9d24420453 (patch)
treebfb20dc6319d08498fc466f8bfe23665143c66f4
parent4cfd1fc897f8f9264c66119246c1cd641d403114 (diff)
Don't quit if user uses esc/q to exit the non-fatal error view
-rw-r--r--ui/stash.go25
-rw-r--r--ui/ui.go4
2 files changed, 12 insertions, 17 deletions
diff --git a/ui/stash.go b/ui/stash.go
index 4e01ade..b5b7765 100644
--- a/ui/stash.go
+++ b/ui/stash.go
@@ -97,13 +97,13 @@ const (
stashStatePromptDelete
stashStateLoadingDocument
stashStateSettingNote
+ stashStateShowingError
)
type stashModel struct {
cc *charm.Client
state stashState
err error
- showError bool
markdowns []*markdown
spinner spinner.Model
noteInput textinput.Model
@@ -341,20 +341,13 @@ 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
+ if m.err != nil && m.state == stashStateReady {
+ m.state = stashStateShowingError
return m, nil
}
}
-
- // If the error view is visible any key hides it.
- if m.showError {
- m.showError = false
- }
-
}
// Update paginator
@@ -407,7 +400,6 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
}
case stashStateSettingNote:
-
if msg, ok := msg.(tea.KeyMsg); ok {
switch msg.String() {
case "esc":
@@ -431,6 +423,12 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
m.noteInput = newNoteInputModel
cmds = append(cmds, cmd)
+ case stashStateShowingError:
+ // Any key exists the error view
+ if _, ok := msg.(tea.KeyMsg); ok {
+ m.state = stashStateReady
+ }
+
}
// If an item is being confirmed for delete, any key (other than the key
@@ -442,12 +440,11 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
// VIEW
func stashView(m stashModel) string {
- if m.showError {
- return errorView(m.err, false)
- }
var s string
switch m.state {
+ case stashStateShowingError:
+ return errorView(m.err, false)
case stashStateLoadingDocument:
s += " " + spinner.View(m.spinner) + " Loading document..."
case stashStateReady, stashStateSettingNote, stashStatePromptDelete:
diff --git a/ui/ui.go b/ui/ui.go
index 114a68a..6ca8c1f 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -172,9 +172,7 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
case stateShowStash:
switch m.stash.state {
- case stashStateSettingNote:
- fallthrough
- case stashStatePromptDelete:
+ case stashStateSettingNote, stashStatePromptDelete, stashStateShowingError:
m.stash, cmd = stashUpdate(msg, m.stash)
return m, cmd
}