Navigation Flow
Relevant source files
The following files were used as context for generating this wiki page:
The Navigation Flow system manages the sequential progression of a terminal-based wizard application. It facilitates the transition between multiple questions, captures user input, and handles the terminal state using the Bubble Tea framework. The system is designed to guide a user through a series of predefined questions—ranging from short text inputs to long-form text areas—before displaying a final summary of all provided answers.
The core of this flow is centered around the Main model, which tracks the current state of the wizard including the current question index, the collection of questions, and the completion status. This model acts as the orchestrator for input updates and view rendering, ensuring that only one question is presented at a time while maintaining the context of previous interactions.
Sources: main.go:27-34, main.go:121-125
State Management and Component Architecture
The navigation flow is governed by a central state machine implemented within the Main struct. This struct maintains the lifecycle of the wizard by tracking the user's progress through an array of Question objects.
Data Structures
The following structures define the state and content of the navigation:
| Structure | Description | Key Fields |
|---|---|---|
Main | The primary application state and model for the Bubble Tea program. | index (current question), questions (slice of all steps), done (completion flag) |
Question | Represents an individual step in the wizard. | question (label), answer (stored result), input (the interactive field) |
Input | An interface defining how different input types (short/long) behave. | Update, View, Value, Blur, Blink |
Sources: main.go:27-40, input.go:9-17
Navigation State Diagram
The following diagram illustrates the lifecycle of the application from initialization to the completion screen.
Sources: main.go:64-118
Navigation Logic
The progression through the wizard is handled by the Update method and the Next helper function. Navigation is primarily driven by the enter key, which triggers a transition to the next state.
Linear Progression
When a user presses "enter", the system performs three primary actions:
- Persistence: The current value of the input component is saved into the
current.answerfield. - Transition: The
Next()method is called to increment theindex. If the index is at the end of the slice, it wraps back to 0, though thedoneflag prevents further input. - Cleanup: The
Blurcommand is returned to the runtime to stop the current input component's activity.
case "enter":
if m.index == len(m.questions)-1 {
m.done = true
}
current.answer = current.input.Value()
m.Next()
return m, current.input.Blur
Sources: main.go:76-85, main.go:111-117
Input Component Switching
The navigation flow supports different types of interactive components (Short vs. Long answers) through the Input interface. This allows the flow to remain consistent regardless of whether the user is interacting with a textinput or a textarea.
Sources: input.go:9-17, main.go:36-40
User Interface Rendering
The View function handles the visual representation of the navigation flow. It operates in two distinct modes:
- Active Wizard Mode: While
m.doneis false, it useslipglossto center the current question and its corresponding input field in the terminal window. - Summary Mode: Once
m.doneis true, the flow terminates in a final view that iterates through all questions and answers, printing them as a static list.
View Flow Sequence
Sources: main.go:89-109
Conclusion
The Navigation Flow in the Wizard Tutorial project provides a structured way to handle multi-step user interactions in a CLI environment. By decoupling the input logic via an Input interface and centralizing state transitions in the Main model, the system ensures a predictable path from data entry to final output. This architecture leverages Bubble Tea's Elm-inspired architecture to manage complex terminal states with minimal overhead.