vcom/internal/tui/quit.go
vrubelroman 40b8722d58 feat(tui): App skeleton with mode machine, async navigation and effects (6.1.5)
The new UI's root model: Screen x viewer focus x native selection x
filter edit x modal stack, one inputOwner, keys resolved through the
registry, an action table that features extend from register_*.go.
Directory reads and previews run in Cmds with tickets: Update never
blocks (N-P1-1), stale results are dropped (U-P1-13), failed navigation
keeps the panel and a vanished directory climbs up (U-P1-8). q closes
layers before asking to quit (U-P1-16), PgDn pages (U-P1-6), the theme
list previews live and saves with config.SetKey. Mouse mode is
reconciled after every Update; View only reads state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 09:11:39 +03:00

45 lines
1.1 KiB
Go

package tui
import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"vcom/internal/tui/modal"
)
// askQuit is q/F10 in Browse (and Ctrl+C with nothing to clear). With
// confirm_quit or running jobs it asks; "q q" quits fast because the Quit
// button's hotkey is q (U-P1-16). Running jobs are cancelled and cleaned
// up by main's teardown (jobs.Shutdown).
func (a *App) askQuit() tea.Cmd {
n := a.activeJobCount()
if !a.deps.Config.Behavior.ConfirmQuit && n == 0 {
return a.quit()
}
d := &modal.Dialog{
Title: "Quit vcom?",
Buttons: []modal.Button{
{Label: "Quit", Key: "q", Value: true, Default: true},
{Label: "Back", Key: "n", Cancel: true},
},
}
if n > 0 {
d.Title = "Quit and cancel operations?"
d.Warnings = []string{fmt.Sprintf("%d operation(s) running: they will be cancelled and their temp files removed", n)}
d.Buttons[0].Label = "Cancel them and quit"
d.Buttons[0].Danger = true
}
a.openModal(d, func(o modal.Outcome) tea.Cmd {
if o.Cancelled {
return nil
}
return a.quit()
})
return nil
}
func (a *App) quit() tea.Cmd {
a.quitting = true
return tea.Quit
}