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"
"math"
"strings"
"time"
"github.com/aymanbagabas/go-osc52"
"github.com/charmbracelet/bubbles/spinner"
@ -123,7 +122,6 @@ type pagerModel struct {
spinner spinner.Model
statusMessage string
statusMessageTimer *time.Timer
// Current document being rendered, sans-glamour rendering. We cache
// 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
m.state = pagerStateStatusMessage
m.statusMessage = statusMessage
if m.statusMessageTimer != nil {
m.statusMessageTimer.Stop()
}
m.statusMessageTimer = time.NewTimer(statusMessageTimeout)
return waitForStatusMessageTimeout(pagerContext, m.statusMessageTimer)
return nil
}
func (m *pagerModel) unload() {
if m.showHelp {
m.toggleHelp()
}
if m.statusMessageTimer != nil {
m.statusMessageTimer.Stop()
}
m.state = pagerStateBrowse
m.viewport.SetContent("")
m.viewport.YOffset = 0
@ -226,6 +216,8 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch m.state {
case pagerStateStatusMessage:
m.state = pagerStateBrowse
case pagerStateSetNote:
switch msg.String() {
case "esc":
@ -272,12 +264,6 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
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
if m.textInput.Value() == "" {
m.textInput.SetValue(m.currentDocument.Note)