Skip to content

Modules

Caleb Leavell edited this page Mar 12, 2026 · 4 revisions

A Modular Approach to TUIs

Why might we want to modularize TUI development? Similarly to other declarative UI libraries, a modular UI framework allows for organized, dynamic, reusable units that can be run, edited, or copied as needed. Not only can this accelerate development, but it often makes code significantly more readable as well.

The TUIModule

At the core of Jatui is the TUIModule. Every TUIModule has the following immutable properties:

  • name (the identifier of the module; should be unique!)
  • application (the ApplicationModule orchestrating the TUI).
  • scanner (to read input from)
  • printStream (to write output to)
  • ansi (to determine the styling of the module)
  • enableAnsi (a flag that says whether the styling should be applied)

Additionally, every TUIModule has a list of children modules that are executed sequentially after the parent finishes. This fundamentally makes a Jatui TUI a Directed Graph of modules.

Creating and Running a TUIModule

To create a TUIModule, we use the corresponding Builder (we'll talk more about Builders in the next section). Let's build and run a simple TextModule that displays "Hello, World!"

TextModule helloWorld = TextModule.builder("hello-world", "Hello, World!").build();
helloWorld.start();

Every module we create will need a unique name that's used for referencing at runtime (it even allows forward referencing in some cases!), as well as any other fields needed by the module type (the display text, in this case). Note that this example worked without an ApplicationModule! More on this later.

[children]

The Primitive Modules

TextModule

TextInputModule

FunctionModule

ApplicationModule

ContainerModule

Example

Next: Builders and Properties

Clone this wiki locally