Skip to main content
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.
Putting it together:

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 more ProgramOption values to the constructor to configure the program at startup.
The following options are available: The common options also exist as fluent methods directly on Program:
Use withAltScreen() for full-screen applications so the terminal is restored cleanly on exit. Omit it for programs that print output that should remain visible after the TUI exits.

Sending messages from background threads

Use Program.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.
send() enqueues the message asynchronously. Do not call it before run() has been called or after the program has exited.

Waiting for initialization

If you need to wait until init() 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.