feat: add back navigation, review step, and error retry to TUI

Implements three UX improvements (TODO #1–#3):

- Back navigation: Esc returns to the previous input step. The Model keeps
  a history stack of input steps (advance/goBack helpers); action/wait
  steps are excluded via isInputStep so back never re-enters a
  side-effecting step. Form values are preserved.
- Review step (StepReview): shows all collected config for confirmation
  before any file is written; Enter installs, Esc edits.
- Retry vs. fix: transient failures (image pull, container run) offer
  "r: tentar novamente" instead of quitting; validation failures route
  back to the relevant form to correct the value.

Adds nav_test.go for the history/navigation logic and updates
README/CLAUDE/docs (incl. docs/TODO.md tracking the remaining ideas).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
jb
2026-06-19 12:19:49 -03:00
co-authored by Claude Opus 4.8
parent 3edfaa4ab2
commit 255b4cc299
9 changed files with 433 additions and 56 deletions
+91 -23
View File
@@ -20,6 +20,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch key.String() {
case "ctrl+c":
return m, tea.Quit
case "esc":
// Global "back" on input steps. Action/wait steps handle esc themselves.
if m.canGoBack() {
m.goBack()
return m, nil
}
}
}
@@ -43,7 +49,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if done {
m.configValues.Login = m.loginForm.Values()
m.currentStep = StepDownloadImage
m.advance(StepDownloadImage)
return m, DownloadImageCmd(imageName, m.configValues.Login["user"], m.configValues.Login["password"])
}
@@ -64,7 +70,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.downloadDone = false
m.downloadMessage = ""
m.downloadError = nil
m.currentStep = StepGenerateWireguardFile
m.advance(StepGenerateWireguardFile)
return m, GenerateWireguardConfigFile(m.configValues, wireguardConfigPath)
}
@@ -82,7 +88,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if done {
m.configValues.Application = m.appForm.Values()
m.currentStep = StepServerConfig
m.advance(StepServerConfig)
}
return m, cmd
@@ -91,7 +97,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if done {
m.configValues.Server = m.serverForm.Values()
m.currentStep = StepDatabaseConfig
m.advance(StepDatabaseConfig)
}
return m, cmd
@@ -100,7 +106,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if done {
m.configValues.Database = m.dbForm.Values()
m.currentStep = StepCertConfig
m.advance(StepCertConfig)
}
return m, cmd
@@ -109,15 +115,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if done {
m.configValues.Cert = m.certForm.Values()
m.currentStep = StepGenerateFile
m.finishedFile = false
m.configFileError = nil
return m, GenerateConfigFile(m.configValues, configPath)
m.advance(StepReview)
}
return m, cmd
case StepReview:
return m.updateReview(msg)
case StepGenerateFile:
return m.updateGenerateFile(msg)
case StepRunDocker:
@@ -146,9 +149,9 @@ func (m Model) updateCheckDocker(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.checkDockerDone && m.checkProgress == 1 {
if m.dockerInstalled {
m.loading = true
m.currentStep = StepDockerLogin
m.advance(StepDockerLogin)
} else {
m.currentStep = StepDockerInstall
m.advance(StepDockerInstall)
}
}
}
@@ -175,9 +178,17 @@ func (m Model) updateDownloadImage(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyPressMsg:
if m.downloadDone && m.downloadError == nil {
m.currentStep = StepIPQuestion
m.advance(StepIPQuestion)
} else if m.downloadDone {
return m, tea.Quit
switch msg.String() {
case "r":
m.downloadDone = false
m.downloadMessage = ""
m.downloadError = nil
return m, DownloadImageCmd(imageName, m.configValues.Login["user"], m.configValues.Login["password"])
default:
return m, tea.Quit
}
}
}
@@ -201,11 +212,11 @@ func (m Model) updateIPQuestion(msg tea.Msg) (tea.Model, tea.Cmd) {
case "enter":
// Yes
if m.cursor == 0 {
m.currentStep = StepAppConfig
m.advance(StepAppConfig)
return m, nil
}
m.currentStep = StepWireguardConfig
m.advance(StepWireguardConfig)
}
}
@@ -229,7 +240,15 @@ func (m Model) updateDownloadWireguard(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.downloadDone && m.downloadError == nil {
m.currentStep = StepRunWireguard
} else if m.downloadDone {
return m, tea.Quit
switch msg.String() {
case "r":
m.downloadDone = false
m.downloadMessage = ""
m.downloadError = nil
return m, DownloadImageCmd(wireguardImageName, m.configValues.Login["user"], m.configValues.Login["password"])
default:
return m, tea.Quit
}
}
}
@@ -250,7 +269,12 @@ func (m Model) updateGenerateWireguardFile(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyPressMsg:
if m.finishedFile && m.configFileError != nil {
return m, tea.Quit
// Validation error (e.g. MTU): go back to the form to correct it. The form
// is the top of the history stack, so goBack lands on it without leaving a
// duplicate entry; fall back to a direct set if history is unexpectedly empty.
if !m.goBack() {
m.currentStep = StepWireguardConfig
}
} else if m.finishedFile && m.configFileError == nil {
m.currentStep = StepDownloadWireguard
@@ -269,9 +293,36 @@ func (m Model) updateRunWireguardDocker(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyPressMsg:
if m.finishedDockerRun && m.dockerRunError != nil {
return m, tea.Quit
switch msg.String() {
case "r":
m.finishedDockerRun = false
m.dockerRunError = nil
return m, RunWireguardContainer(wireguardConfigPath, m.configValues)
default:
return m, tea.Quit
}
} else if m.finishedDockerRun && m.dockerRunError == nil {
m.currentStep = StepAppConfig
m.advance(StepAppConfig)
}
}
return m, nil
}
// updateReview shows the collected configuration for confirmation before any files are
// written. Enter confirms and generates config.toml; Esc (handled globally) goes back
// to the previous form to edit.
func (m Model) updateReview(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyPressMsg:
switch msg.String() {
case "enter":
m.advance(StepGenerateFile)
m.finishedFile = false
m.configFileError = nil
return m, GenerateConfigFile(m.configValues, configPath)
}
}
@@ -286,7 +337,11 @@ func (m Model) updateGenerateFile(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyPressMsg:
if m.finishedFile && m.configFileError != nil {
return m, tea.Quit
// Validation error: return to the review (top of the stack) so the user can
// navigate back to the forms; direct set as a fallback.
if !m.goBack() {
m.currentStep = StepReview
}
} else if m.finishedFile && m.configFileError == nil {
m.currentStep = StepRunDocker
@@ -314,7 +369,20 @@ func (m Model) updateRunDocker(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyPressMsg:
if m.finishedDockerRun && m.dockerRunError != nil {
return m, tea.Quit
switch msg.String() {
case "r":
m.finishedDockerRun = false
m.dockerRunError = nil
return m, RunAppContainer(
imageName,
"app-dono-cliente",
configPath,
fmt.Sprintf("/app/%s", configPath),
m.configValues,
)
default:
return m, tea.Quit
}
} else if m.finishedDockerRun && m.dockerRunError == nil {
m.currentStep = StepDone
}