mirror of
https://github.com/charmbracelet/glow
synced 2024-11-10 06:04:18 +00:00
feat: alert until keypress
This commit is contained in:
parent
2a95efc50d
commit
aa328d6636
1 changed files with 4 additions and 18 deletions
20
ui/pager.go
20
ui/pager.go
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue