The Data Model
Relevant source files
The following files were used as context for generating this wiki page:
The Data Model for the Terminal Wizard project serves as the foundational structure for managing a sequence of user prompts and their corresponding responses within a CLI environment. It is built upon the Bubble Tea framework, which utilizes a Model-View-Update (MVU) architecture to handle state management and terminal rendering.
The model is designed to encapsulate terminal styling, application state (such as window dimensions and completion status), and a collection of interactive questions. Each question is associated with a specific input type, allowing the wizard to transition between short-text fields and multi-line text areas seamlessly.
Sources: README.md:1-13, main.go:21-40
Core Data Structures
The application's state is primarily managed through two core structs: Main and Question. The Main struct acts as the top-level container for the application lifecycle, while the Question struct defines the individual data points collected during the wizard session.
Main Application State
The Main struct holds the global state necessary for rendering the wizard and tracking progress through the questionnaire.
| Field | Type | Description |
|---|---|---|
styles | *Styles | Contains Lip Gloss styling definitions for the UI. |
index | int | The index of the currently active question. |
questions | []Question | A slice containing all defined questions for the wizard. |
width | int | The current width of the terminal window. |
height | int | The current height of the terminal window. |
done | bool | A flag indicating if all questions have been answered. |
Sources: main.go:21-28
Question and Input Interface
The Question struct pairs a string prompt with its resulting answer and an interface-driven input component. This abstraction allows the wizard to handle different types of user input (short vs. long) through a unified interface.
type Question struct {
question string
answer string
input Input
}
Sources: main.go:30-34
The Input interface defines the behavior required for any input component to be compatible with the wizard's update and view cycles.
The diagram shows how the Input interface is implemented by specific field types to wrap Charm Bubbles components.
Sources: input.go:9-18, input.go:24-26, input.go:73-75
Input Implementation Logic
The data model uses wrappers to integrate standard Bubble Tea components (textinput and textarea) into the project's custom Input interface. This allows the Main model to interact with different input types without knowing their internal implementation.
Short vs. Long Answer Fields
- shortAnswerField: Wraps
textinput.Modelfor single-line inputs like names or editors. - longAnswerField: Wraps
textarea.Modelfor multi-line inputs like quotes or descriptions.
Sources: input.go:28-71, input.go:77-120
Visual and Layout Styling
The Styles struct defines the visual constraints and aesthetic properties of the data model's output. It leverages the lipgloss library to manage colors and borders.
| Style Attribute | Type | Default/Value | Source |
|---|---|---|---|
BorderColor | lipgloss.Color | "36" (Teal/Cyan) | main.go:17 |
InputField | lipgloss.Style | Normal Border, Padding 1, Width 80 | main.go:18 |
Sources: main.go:12-20
Data Flow and State Transitions
The data model follows a linear flow where user input updates the current question's state. When a user presses "enter", the current value is committed to the answer field, and the model advances the index.
The flow diagram illustrates the lifecycle of the data model from initialization through the sequential question-answering process to the final summary view.
Sources: main.go:56-85, main.go:106-112
Summary of Logic
The data model is a state-driven container that leverages Go interfaces to provide a polymorphic approach to CLI forms. By separating the prompt (Question) from the input mechanism (Input), the architecture remains extensible, allowing for new input types (e.g., multi-select or toggle) to be added with minimal changes to the core Main update loop.
Sources: main.go:30-54, input.go:9-18