Project Background
Relevant source files
The following files were used as context for generating this wiki page:
The Wizard Tutorial project is a technical demonstration and companion repository for building interactive Terminal User Interfaces (TUIs) using the Go programming language. It specifically leverages the Charm libraries—Bubble Tea for the Elm-inspired runtime architecture and Lip Gloss for terminal styling—to create a multi-step "wizard" or questionnaire.
The project serves as a foundational guide for developers to understand state management, keyboard input handling, and component-based UI design within a CLI environment. It allows users to progress through a series of questions, providing both short-form and long-form text inputs, and finally displays a summary of all collected data upon completion.
Sources: README.md:1-15, main.go:121-135
Core Architecture and Frameworks
The application is built on the Model-View-Update (MVU) pattern provided by the Bubble Tea framework. It modularizes UI components and manages the lifecycle of the terminal application through a central Main model.
Primary Technologies
| Component | Library/Tool | Purpose |
|---|---|---|
| Runtime | Bubble Tea | Handles the application loop, events, and state updates. |
| Styling | Lip Gloss | Provides primitive UI building blocks like borders, padding, and alignment. |
| Input Components | Bubbles | Pre-built UI components like textinput and textarea. |
Sources: README.md:12-14, main.go:7-10, input.go:4-7
Component Relationship
The following class diagram illustrates the relationship between the central application state and the polymorphic input system.
Sources: main.go:23-38, input.go:9-18
Data Models and State Management
The application state is encapsulated in the Main struct. It tracks the current question index, the window dimensions for centering, and whether the wizard has finished processing.
The Question Structure
Each step of the wizard is represented by a Question struct.
- question: The string prompt shown to the user.
- answer: The string value captured from the user's input.
- input: An instance of the
Inputinterface, which allows for different types of UI input fields (short or long).
Sources: main.go:32-37
Input Interface Implementation
To handle different types of text entries while maintaining a unified update loop, the project uses a custom Input interface. This wraps standard bubbles components to ensure they conform to the application's needs.
Sources: main.go:44-58, input.go:21-95
Execution Flow and Event Handling
The application follows a linear progression through the defined questions. The Update function acts as the central router for all terminal events, including window resizing and keyboard strokes.
Interaction Sequence
When a user interacts with the wizard, the following sequence occurs:
Sources: main.go:70-90
Key Handlers
| Key | Action | File Reference |
|---|---|---|
ctrl+c, q | Quits the application immediately. | main.go:78 |
enter | Saves current answer, moves to next question, or finishes wizard. | main.go:80-87 |
WindowSizeMsg | Updates internal width/height for responsive centering. | main.go:74-76 |
Visual Rendering and Styling
The project uses Lip Gloss to define a consistent visual style, including a specific border color (ANSI color "36") and padding for input fields.
Layout Logic
The wizard utilizes lipgloss.Place to ensure the questionnaire is perfectly centered within the terminal window, regardless of the user's terminal size. It joins the question text and the input field vertically using lipgloss.JoinVertical.
Sources: main.go:104-115
Final Output
Once m.done is set to true (after the last question is answered), the View function switches from the input interface to a summary display that iterates through all stored questions and answers.
Sources: main.go:94-100
Summary
The Wizard Tutorial provides a structured approach to building multi-step CLI applications in Go. By abstracting input components through an interface and utilizing the Bubble Tea framework, it demonstrates a scalable pattern for managing user input and terminal state. The use of Lip Gloss further ensures that the resulting interface is both functional and aesthetically aligned with modern terminal standards.
Sources: README.md:1-10, main.go:1-20