refactor: use exit.StatusAborted, unexport heightOffset

This commit is contained in:
Maas Lalani 2023-06-29 16:36:47 -04:00
parent ae1da5d329
commit b6f739d7d1
No known key found for this signature in database
GPG key ID: 5A6ED5CBF1A0A000
2 changed files with 7 additions and 8 deletions

View file

@ -7,12 +7,10 @@ import (
"github.com/alecthomas/kong"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/gum/internal/exit"
"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
// action with an affirmative or negative answer.
func (o Options) Run() error {
@ -34,7 +32,7 @@ func (o Options) Run() error {
}
if m.(model).aborted {
os.Exit(Aborted)
os.Exit(exit.StatusAborted)
} else if m.(model).confirmation {
os.Exit(0)
} else {

View file

@ -84,9 +84,10 @@ func (m *model) ProcessText(msg tea.WindowSizeMsg) {
m.viewport.SetContent(text.String())
}
const heightOffset = 2
func (m model) KeyHandler(key tea.KeyMsg) (model, func() tea.Msg) {
var cmd tea.Cmd
const HeightOffset = 2
if m.search.active {
switch key.String() {
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.
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 {
m.search.Done()
}
@ -115,10 +116,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 + HeightOffset, Width: m.viewport.Width})
m.ProcessText(tea.WindowSizeMsg{Height: m.viewport.Height + heightOffset, Width: m.viewport.Width})
case "n":
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":
return m, tea.Quit
}