mirror of
https://github.com/charmbracelet/gum
synced 2024-06-08 16:52:17 +02:00
refactor: use exit.StatusAborted, unexport heightOffset
This commit is contained in:
parent
ae1da5d329
commit
b6f739d7d1
|
@ -7,12 +7,10 @@ import (
|
||||||
"github.com/alecthomas/kong"
|
"github.com/alecthomas/kong"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
|
|
||||||
|
"github.com/charmbracelet/gum/internal/exit"
|
||||||
"github.com/charmbracelet/gum/style"
|
"github.com/charmbracelet/gum/style"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Aborted is the exit code when the user aborts the confirmation.
|
|
||||||
const Aborted = 130
|
|
||||||
|
|
||||||
// Run provides a shell script interface for prompting a user to confirm an
|
// Run provides a shell script interface for prompting a user to confirm an
|
||||||
// action with an affirmative or negative answer.
|
// action with an affirmative or negative answer.
|
||||||
func (o Options) Run() error {
|
func (o Options) Run() error {
|
||||||
|
@ -34,7 +32,7 @@ func (o Options) Run() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.(model).aborted {
|
if m.(model).aborted {
|
||||||
os.Exit(Aborted)
|
os.Exit(exit.StatusAborted)
|
||||||
} else if m.(model).confirmation {
|
} else if m.(model).confirmation {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -84,9 +84,10 @@ func (m *model) ProcessText(msg tea.WindowSizeMsg) {
|
||||||
m.viewport.SetContent(text.String())
|
m.viewport.SetContent(text.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const heightOffset = 2
|
||||||
|
|
||||||
func (m model) KeyHandler(key tea.KeyMsg) (model, func() tea.Msg) {
|
func (m model) KeyHandler(key tea.KeyMsg) (model, func() tea.Msg) {
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
const HeightOffset = 2
|
|
||||||
if m.search.active {
|
if m.search.active {
|
||||||
switch key.String() {
|
switch key.String() {
|
||||||
case "enter":
|
case "enter":
|
||||||
|
@ -96,7 +97,7 @@ func (m model) KeyHandler(key tea.KeyMsg) (model, func() tea.Msg) {
|
||||||
|
|
||||||
// Trigger a view update to highlight the found matches.
|
// Trigger a view update to highlight the found matches.
|
||||||
m.search.NextMatch(&m)
|
m.search.NextMatch(&m)
|
||||||
m.ProcessText(tea.WindowSizeMsg{Height: m.viewport.Height + HeightOffset, Width: m.viewport.Width})
|
m.ProcessText(tea.WindowSizeMsg{Height: m.viewport.Height + heightOffset, Width: m.viewport.Width})
|
||||||
} else {
|
} else {
|
||||||
m.search.Done()
|
m.search.Done()
|
||||||
}
|
}
|
||||||
|
@ -115,10 +116,10 @@ func (m model) KeyHandler(key tea.KeyMsg) (model, func() tea.Msg) {
|
||||||
m.search.Begin()
|
m.search.Begin()
|
||||||
case "p", "N":
|
case "p", "N":
|
||||||
m.search.PrevMatch(&m)
|
m.search.PrevMatch(&m)
|
||||||
m.ProcessText(tea.WindowSizeMsg{Height: m.viewport.Height + HeightOffset, Width: m.viewport.Width})
|
m.ProcessText(tea.WindowSizeMsg{Height: m.viewport.Height + heightOffset, Width: m.viewport.Width})
|
||||||
case "n":
|
case "n":
|
||||||
m.search.NextMatch(&m)
|
m.search.NextMatch(&m)
|
||||||
m.ProcessText(tea.WindowSizeMsg{Height: m.viewport.Height + HeightOffset, Width: m.viewport.Width})
|
m.ProcessText(tea.WindowSizeMsg{Height: m.viewport.Height + heightOffset, Width: m.viewport.Width})
|
||||||
case "q", "ctrl+c", "esc":
|
case "q", "ctrl+c", "esc":
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue