feat: alert until keypress

This commit is contained in:
bashbunni 2022-09-23 15:25:47 -07:00
parent 2a95efc50d
commit aa328d6636
No known key found for this signature in database
GPG key ID: 89226497B6075499

View file

@ -5,7 +5,6 @@ import (
"log" "log"
"math" "math"
"strings" "strings"
"time"
"github.com/aymanbagabas/go-osc52" "github.com/aymanbagabas/go-osc52"
"github.com/charmbracelet/bubbles/spinner" "github.com/charmbracelet/bubbles/spinner"
@ -122,8 +121,7 @@ type pagerModel struct {
textInput textinput.Model textInput textinput.Model
spinner spinner.Model spinner spinner.Model
statusMessage string statusMessage string
statusMessageTimer *time.Timer
// Current document being rendered, sans-glamour rendering. We cache // Current document being rendered, sans-glamour rendering. We cache
// it here so we can re-render it on resize. // it here so we can re-render it on resize.
@ -196,21 +194,13 @@ func (m *pagerModel) showStatusMessage(statusMessage string) tea.Cmd {
// Show a success message to the user // Show a success message to the user
m.state = pagerStateStatusMessage m.state = pagerStateStatusMessage
m.statusMessage = statusMessage m.statusMessage = statusMessage
if m.statusMessageTimer != nil { return nil
m.statusMessageTimer.Stop()
}
m.statusMessageTimer = time.NewTimer(statusMessageTimeout)
return waitForStatusMessageTimeout(pagerContext, m.statusMessageTimer)
} }
func (m *pagerModel) unload() { func (m *pagerModel) unload() {
if m.showHelp { if m.showHelp {
m.toggleHelp() m.toggleHelp()
} }
if m.statusMessageTimer != nil {
m.statusMessageTimer.Stop()
}
m.state = pagerStateBrowse m.state = pagerStateBrowse
m.viewport.SetContent("") m.viewport.SetContent("")
m.viewport.YOffset = 0 m.viewport.YOffset = 0
@ -226,6 +216,8 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
switch msg := msg.(type) { switch msg := msg.(type) {
case tea.KeyMsg: case tea.KeyMsg:
switch m.state { switch m.state {
case pagerStateStatusMessage:
m.state = pagerStateBrowse
case pagerStateSetNote: case pagerStateSetNote:
switch msg.String() { switch msg.String() {
case "esc": case "esc":
@ -272,12 +264,6 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
m.state = pagerStateSetNote m.state = pagerStateSetNote
// Stop the timer for hiding a status message since changing
// the state above will have cleared it.
if m.statusMessageTimer != nil {
m.statusMessageTimer.Stop()
}
// Pre-populate note with existing value // Pre-populate note with existing value
if m.textInput.Value() == "" { if m.textInput.Value() == "" {
m.textInput.SetValue(m.currentDocument.Note) m.textInput.SetValue(m.currentDocument.Note)