Program is the entry point for every TUI4J application. It owns the terminal, starts the event loop, and drives the Model/Update/View cycle until a QuitMessage is received.
Basic usage
1
Implement Model
Write a class that implements the
Model interface with init(), update(), and view(). See The Elm Architecture for details.2
Instantiate Program
Pass your model to the
Program constructor.3
Run the event loop
Call
run(). This blocks the calling thread, puts the terminal into raw mode, and begins processing events.Getting the final model state
run() returns void. If you need to inspect the model after the program exits — for example, to read a value the user entered — use runWithFinalModel() instead.
runWithFinalModel() is a tui4j extension with no equivalent in Bubble Tea. In Go the
idiomatic approach is to read state from a shared pointer; in Java, accessing the typed final
model is usually cleaner.ProgramOptions
Pass one or moreProgramOption values to the constructor to configure the program at startup.
The common options also exist as fluent methods directly on
Program:
Sending messages from background threads
UseProgram.send(Message) to inject a message into the running event loop from any thread. This is useful for pushing events from background goroutines — HTTP responses, file watchers, timers managed outside the command system, etc.
Waiting for initialization
If you need to wait untilinit() has completed before proceeding (for example in tests), use waitForInit():
Checking program state
The Elm Architecture
How Model, Update, and View fit together.
Messages and commands
All built-in messages and how to create custom ones.