TUI: add quit confirmation
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/LazyBachelor/LazyPM/pkg/tui/components"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/tui/issues"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
@@ -323,6 +324,29 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
})
|
||||
|
||||
case tea.KeyMsg:
|
||||
// Always allow quit with q/ctrl+c, even when in inputs or other modals
|
||||
if !m.confirmingQuit && (key.Matches(msg, m.keyMap.Quit) || msg.String() == "q" || msg.String() == "ctrl+c") {
|
||||
m.cancelAllModals()
|
||||
m.startConfirmQuit()
|
||||
m.logAction("tui quit requested")
|
||||
return m, nil
|
||||
}
|
||||
|
||||
if m.confirmingQuit {
|
||||
switch msg.String() {
|
||||
case "y", "Y", "ctrl+c":
|
||||
m.logAction("tui confirmed quit")
|
||||
m.confirmingQuit = false
|
||||
return m, tea.Quit
|
||||
case "n", "N", "esc":
|
||||
m.logAction("tui canceled quit")
|
||||
m.confirmingQuit = false
|
||||
return m, nil
|
||||
default:
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
|
||||
if m.confirmingDelete {
|
||||
switch msg.String() {
|
||||
case "y", "Y":
|
||||
|
||||
Reference in New Issue
Block a user