mirror of
https://github.com/charmbracelet/gum
synced 2024-06-09 01:02:17 +02:00
feat: Adding timeout option in preparation for coming timeout features in all commands
This commit is contained in:
parent
eb888a57bb
commit
938a3cf97c
|
@ -10,6 +10,8 @@ import (
|
|||
"github.com/charmbracelet/gum/style"
|
||||
)
|
||||
|
||||
const ABORTED = 130
|
||||
|
||||
// Run provides a shell script interface for prompting a user to confirm an
|
||||
// action with an affirmative or negative answer.
|
||||
func (o Options) Run() error {
|
||||
|
@ -31,7 +33,7 @@ func (o Options) Run() error {
|
|||
}
|
||||
|
||||
if m.(model).aborted {
|
||||
os.Exit(130)
|
||||
os.Exit(ABORTED)
|
||||
} else if m.(model).confirmation {
|
||||
os.Exit(0)
|
||||
} else {
|
||||
|
|
|
@ -86,6 +86,7 @@ func (m *model) ProcessText(msg tea.WindowSizeMsg) {
|
|||
|
||||
func (m model) KeyHandler(key tea.KeyMsg) (model, func() tea.Msg) {
|
||||
var cmd tea.Cmd
|
||||
const HEIGHT_OFFSET = 2
|
||||
if m.search.active {
|
||||
switch key.String() {
|
||||
case "enter":
|
||||
|
@ -95,7 +96,7 @@ func (m model) KeyHandler(key tea.KeyMsg) (model, func() tea.Msg) {
|
|||
|
||||
// Trigger a view update to highlight the found matches.
|
||||
m.search.NextMatch(&m)
|
||||
m.ProcessText(tea.WindowSizeMsg{Height: m.viewport.Height + 2, Width: m.viewport.Width})
|
||||
m.ProcessText(tea.WindowSizeMsg{Height: m.viewport.Height + HEIGHT_OFFSET, Width: m.viewport.Width})
|
||||
} else {
|
||||
m.search.Done()
|
||||
}
|
||||
|
@ -114,10 +115,10 @@ func (m model) KeyHandler(key tea.KeyMsg) (model, func() tea.Msg) {
|
|||
m.search.Begin()
|
||||
case "p", "N":
|
||||
m.search.PrevMatch(&m)
|
||||
m.ProcessText(tea.WindowSizeMsg{Height: m.viewport.Height + 2, Width: m.viewport.Width})
|
||||
m.ProcessText(tea.WindowSizeMsg{Height: m.viewport.Height + HEIGHT_OFFSET, Width: m.viewport.Width})
|
||||
case "n":
|
||||
m.search.NextMatch(&m)
|
||||
m.ProcessText(tea.WindowSizeMsg{Height: m.viewport.Height + 2, Width: m.viewport.Width})
|
||||
m.ProcessText(tea.WindowSizeMsg{Height: m.viewport.Height + HEIGHT_OFFSET, Width: m.viewport.Width})
|
||||
case "q", "ctrl+c", "esc":
|
||||
return m, tea.Quit
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue