Skip to main content
TUI4J includes a port of Lip Gloss, Charm’s terminal styling library. It provides a fluent Java API for colors, borders, padding, margins, alignment, and multi-column layout — all resolved to ANSI escape sequences at render time.

Creating a style

Every style starts from Style.newStyle(). Methods return this, so the entire style is configured in a single chain and applied by calling render(...).
render() accepts one or more strings. Multiple strings are joined with a space before styling is applied.

Colors

All colors implement TerminalColor and can be passed to .foreground() and .background().

ANSI-256 and hex colors

Color.color(String) accepts ANSI-256 index strings ("0"–"255") and hex color strings ("#FF5F87").

Adaptive colors

AdaptiveColor selects between a light and dark variant depending on whether the terminal has a dark background.
Use AdaptiveColor for any color that should look good in both light and dark terminal themes.

Text attributes

Width and height

Set explicit dimensions to constrain content. Text is wrapped to fit the specified width.
Cap dimensions without hard-wrapping using maxWidth and maxHeight:

Padding

Padding uses CSS-like shorthand: one value applies to all sides, two values apply to vertical then horizontal, four values apply top → right → bottom → left.

Margins

Margins work identically to padding but add space outside any border.

Borders

Choose a border style from Borders and apply it with .border().
Available border styles: Apply borders selectively with boolean side flags:
Color the border independently of the content:

Alignment

Layout: joining styled blocks

Join combines multiple rendered strings side-by-side or stacked. Pass a Position to control alignment along the cross-axis.

Status bar example

This pattern, taken from the Lipgloss examples, builds a multi-segment status bar using Join.joinHorizontal:

Copying and inheriting styles

Use .copy() to create an independent clone of a style (safe for modification without affecting the original):
Use .inherit(other) to fill in only the properties that have not been explicitly set on the receiver:

The Elm Architecture

Model, Update, and View pattern.

Messages and commands

Events and side effects in TUI4J.