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 -16
View File
@@ -10,15 +10,33 @@ import (
const (
header = "App do Dono - Instalador Cliente"
defaultMsg = "ctrl+c: sair"
anyKeyOutMsg = "qualquer tecla: sair"
formMsg = "tab: próximo campo • enter: confirmar • ctrl+c: sair"
retryMsg = "r: tentar novamente • q: sair"
fixMsg = "qualquer tecla: voltar e corrigir"
formBase = "tab: próximo campo • enter: confirmar"
ipBase = "↑/↓: navegar • enter: selecionar"
reviewBase = "enter: confirmar e instalar"
)
// helpFor builds the footer for an input step, appending "esc: voltar" when back
// navigation is available and always ending with "ctrl+c: sair".
func (m Model) helpFor(base string) string {
parts := []string{}
if base != "" {
parts = append(parts, base)
}
if m.canGoBack() {
parts = append(parts, "esc: voltar")
}
parts = append(parts, "ctrl+c: sair")
return strings.Join(parts, " • ")
}
func (m Model) View() tea.View {
pad := strings.Repeat(" ", padding)
var body string
helpMsg := defaultMsg
helpMsg := m.helpFor("")
switch m.currentStep {
// Docker stuff
@@ -29,53 +47,65 @@ func (m Model) View() tea.View {
helpMsg = anyKeyOutMsg
case StepDockerLogin:
body = m.loginForm.View()
helpMsg = formMsg
helpMsg = m.helpFor(formBase)
case StepDownloadImage:
body = m.viewDownloadImage()
if m.downloadDone && m.downloadError != nil {
helpMsg = retryMsg
}
// IP Stuff
case StepIPQuestion:
body = m.viewIPQuestion()
helpMsg = m.helpFor(ipBase)
case StepWireguardConfig:
body = m.wireguardForm.View()
helpMsg = formMsg
helpMsg = m.helpFor(formBase)
case StepGenerateWireguardFile:
body = m.viewGenerateFile()
if m.finishedFile && m.configFileError != nil {
helpMsg = anyKeyOutMsg
helpMsg = fixMsg
}
case StepDownloadWireguard:
body = m.viewDownloadImage()
if m.downloadDone && m.downloadError != nil {
helpMsg = retryMsg
}
case StepRunWireguard:
body = m.viewDockerRun()
if m.finishedDockerRun && m.dockerRunError != nil {
helpMsg = anyKeyOutMsg
helpMsg = retryMsg
}
// App Config Stuff
case StepAppConfig:
body = m.appForm.View()
helpMsg = formMsg
helpMsg = m.helpFor(formBase)
case StepServerConfig:
body = m.serverForm.View()
helpMsg = formMsg
helpMsg = m.helpFor(formBase)
case StepDatabaseConfig:
body = m.dbForm.View()
helpMsg = formMsg
helpMsg = m.helpFor(formBase)
case StepCertConfig:
body = m.certForm.View()
helpMsg = formMsg
helpMsg = m.helpFor(formBase)
// Review
case StepReview:
body = m.viewReview()
helpMsg = m.helpFor(reviewBase)
// Finalize
case StepGenerateFile:
body = m.viewGenerateFile()
if m.finishedFile && m.configFileError != nil {
helpMsg = anyKeyOutMsg
helpMsg = fixMsg
}
case StepRunDocker:
body = m.viewDockerRun()
if m.finishedDockerRun && m.dockerRunError != nil {
helpMsg = anyKeyOutMsg
helpMsg = retryMsg
}
case StepDone:
body = m.viewDoneMessage()
@@ -155,7 +185,7 @@ func (m Model) viewDownloadImage() string {
errText := dualPad + m.downloadMessage + "\n" + dualPad + m.downloadError.Error()
sb.WriteString(ErrorStyle.Width(m.width - (padding * 2)).Align(lipgloss.Left).Render(errText))
sb.WriteString("\n\n" + pad + "Pressione qualquer tecla para sair.")
sb.WriteString("\n\n" + pad + "Pressione 'r' para tentar novamente ou 'q' para sair.")
}
return sb.String()
@@ -187,6 +217,51 @@ func (m Model) viewIPQuestion() string {
return sb.String()
}
func (m Model) viewReview() string {
pad := strings.Repeat(" ", padding)
cv := m.configValues
var sb strings.Builder
sb.WriteString(pad + "Revise as configurações antes de instalar:\n")
section := func(title string, rows [][2]string) {
sb.WriteString("\n" + pad + TitleStyle.Render(title) + "\n")
for _, r := range rows {
sb.WriteString(pad + HelpStyle.Render(r[0]+": ") + r[1] + "\n")
}
}
if len(cv.Wireguard) > 0 {
section("vproxy", [][2]string{
{"IP Virtual", cv.Wireguard["vip"]},
{"Proxy EDPS", cv.Wireguard["proxy_edps"]},
{"MTU", cv.Wireguard["mtu"]},
{"Protocolo", cv.Wireguard["proto"]},
})
}
section("Aplicação", [][2]string{
{"Servidor Central", cv.Application["central_server_url"]},
{"Token de Inscrição", cv.Application["enrollment_token"]},
})
section("Servidor", [][2]string{
{"Porta (host)", cv.Server["port"]},
{"Timeout", cv.Server["timeout"]},
{"Ambiente", cv.Server["environment"]},
{"Modo Compatibilidade", cv.Server["seccomp_unconfined"]},
})
section("Banco de Dados", [][2]string{
{"Tipo", cv.Database["database_type"]},
{"URL", cv.Database["database_url"]},
{"Conexões (máx/mín)", cv.Database["max_conns"] + "/" + cv.Database["min_conns"]},
})
section("Certificado", [][2]string{
{"Diretório", cv.Cert["cert_dir_path"]},
})
return sb.String()
}
func (m Model) viewGenerateFile() string {
pad := strings.Repeat(" ", padding)
var sb strings.Builder
@@ -205,7 +280,7 @@ func (m Model) viewGenerateFile() string {
errText := dualPad + m.configFileError.Error()
sb.WriteString(ErrorStyle.Width(m.width - (padding * 2)).Align(lipgloss.Left).Render(errText))
sb.WriteString("\n\n" + pad + "Tente novamente.")
sb.WriteString("\n\n" + pad + "Pressione qualquer tecla para voltar e corrigir os dados.")
}
}
@@ -230,7 +305,7 @@ func (m Model) viewDockerRun() string {
errText := dualPad + m.dockerRunError.Error()
sb.WriteString(ErrorStyle.Width(m.width - (padding * 2)).Align(lipgloss.Left).Render(errText))
sb.WriteString("\n\n" + pad + "Tente novamente.")
sb.WriteString("\n\n" + pad + "Pressione 'r' para tentar novamente ou 'q' para sair.")
}
}