Running the Application
Relevant source files
The following files were used as context for generating this wiki page:
The wizard-tutorial application is a terminal-based wizard built using the Go programming language. It leverages the Bubble Tea framework for its operational loop and Lip Gloss for UI styling. The application guides users through a series of questions, collecting inputs via terminal-based text fields and text areas before displaying a summary of the collected data.
Sources: README.md:1-12, main.go:7-11
Application Entry Point and Initialization
The application lifecycle begins in the main function. It initializes a set of predefined Question objects, configures the terminal environment, and starts the Bubble Tea runtime.
Execution Flow
- Model Preparation: A slice of
Questionstructs is created, containing both short and long answer prompts. - Logging: The application initializes a local debug log file named
debug.log. - Program Execution: The
tea.NewProgramfunction is called with theMainmodel and thetea.WithAltScreen()option, which ensures the application runs in the terminal's alternate screen buffer to prevent cluttering the scrollback history.
Sources: main.go:121-140
The diagram above illustrates the startup sequence from the main function to the start of the application loop. Sources: main.go:121-140
Core Components and Architecture
The application is structured around a central Main model that implements the tea.Model interface. This model manages the state of the wizard, including the current question index, dimensions of the terminal, and completion status.
Component Summary
| Component | Description | File Reference |
|---|---|---|
Main | The primary state machine managing questions, window size, and navigation. | main.go:23-30 |
Question | A container for the prompt string, the user's answer, and the input component. | main.go:32-36 |
Input | An interface defining how question input fields behave (Blink, Focus, Update, View). | input.go:9-17 |
Styles | Defines the visual appearance using Lip Gloss colors and borders. | main.go:13-21 |
Sources: main.go:13-36, input.go:9-17
Input Models
The application supports two types of input fields, which are wrapped to satisfy the internal Input interface:
- Short Answer: Uses
textinput.Modelfor single-line entry. - Long Answer: Uses
textarea.Modelfor multi-line text entry.
Sources: input.go:22-113
Interaction and State Management
The application operates on the standard Bubble Tea Elm-architecture: Init, Update, and View.
Update Logic
The Update function handles terminal events. It specifically listens for:
- Window Resizing: Updates the internal
widthandheightstate to maintain UI alignment. - Quitting: Responds to
ctrl+corqby returningtea.Quit. - Submission: Responds to the
enterkey by capturing the current input value, advancing to the next question via theNext()method, or marking the session asdone.
Sources: main.go:65-85
This sequence diagram shows the data flow when a user submits a response to a question. Sources: main.go:73-84
Rendering and Layout
The View function handles the visual output. It uses lipgloss.Place to center the wizard UI within the terminal window based on the detected width and height.
- Active State: Displays the current question text stacked vertically with the styled input field.
- Done State: Iterates through all questions and answers, printing them as a summary list.
- Styles: The input field is rendered with a specific border color (
"36") and a width of 80 characters.
Sources: main.go:18-20, main.go:88-112
Summary
Running the wizard-tutorial application involves executing a Go binary that initializes a TUI environment. It manages user state through a structured sequence of Question models, handles input via specialized wrappers for textinput and textarea, and provides a centered, styled user interface that concludes with a data summary.
Sources: main.go:23-119, README.md:1-12