itui.
A modular Terminal UI (TUI) framework for iyi — declarative TrueColor styling, one-liner prompts, and interactive multi-panel components.
v0.1.0Get started
iyi get github.com/canermastan/itui
iyi get adds it to iyi.mod and fetches its newest version tag. Import it as github.com/canermastan/itui::*.
README
Features
- One-liner prompts â
TUI.select,TUI.multi_select,TUI.input, andTUI.confirmwork out of the box with zero boilerplat - Declarative styling â Immutable
Stylebuilder with 24-bit TrueColor RGB/Hex, 256-color palette, padding, margin, alignment, and box borders (:single,:rounded,:double,:thick - Built-in components â
ProgressBar,Viewport,FilterList,TextArea,Table,Tabs,Modal,Spinner, andHelpBar - Multi-panel layout â Responsive
WindowSizesplits andTab/Shift+TabFocusManager - Mouse support â SGR mouse clicks (
is_click?,is_right_click?), wheel scrolling (is_wheel_up?,is_wheel_down?), and hit-testing (mouse.in_rect? - Cross-platform â Runs on macOS, Linux, and Windows terminals with zero external C dependencie
Installation
itui is an iyi module. Add it to your project under the short name itui, which the examples below use:
iyi get github.com/canermastan/itui --as itui
That writes one line to iyi.mod:
require github.com/canermastan/itui v0.1.0 as itui
and itui/src/tui then names itui's entry module. Run iyi get -u to update to the latest release.
Quick Start
One-Liner Interactive Prompts
Need quick user input without writing a model or event loop? Import TUI and call a prompt directly:
module app/cli
import itui/src/tui::{TUI}
name = TUI.input("Project name:", "my-app")
choice = TUI.select("Pick a component:", ["ProgressBar", "Viewport", "FilterList", "TextArea"])
selected = TUI.multi_select("Enable features:", ["Tabs", "Modal", "Spinner", "HelpBar"])
proceed = TUI.confirm("Start build?")
Tutorial: Building a Stateful App
Full-screen apps follow an immutable Model â update â view l
First, declare your module and import itui/src/tui::* (or pick individual types with import itui/src/tui::{Style, ProgressBar, KeyEvent}):
module app/main
import itui/src/tui::*
Define your application state (Model) as an immutable struct:
pub struct AppModel
getter progress : ProgressBar
getter spinner : Spinner
getter quit : Bool
def initialize(@progress : ProgressBar, @spinner : Spinner, @quit : Bool = false)
end
def self.initial : AppModel
bar = ProgressBar.new(40, 32).with_label("Progress:")
sp = Spinner.dots("RUNNING")
AppModel.new(bar, sp, false)
end
end
Handle keyboard input in update â every event returns a new AppModel
def update(key : KeyEvent) : AppModel
return AppModel.new(@progress, @spinner, true) if key.is_quit?
next_pct = @progress.percent
if key.is_right? || key.is_up?
next_pct = next_pct + 10
elsif key.is_left? || key.is_down?
next_pct = next_pct - 10
end
AppModel.new(@progress.with_percent(next_pct), @spinner.tick, false)
end
Describe your UI in view by returning a String:
def view : String
help = HelpBar.new([
KeyBinding.on_any(["left", "right"], "←/→", "adjust"),
KeyBinding.on("q", "q/Esc", "quit")
])
card = Style.new_style
.border(:rounded)
.border_foreground(Theme.iyi.primary)
.padding(1, 3)
.render("#{@spinner.render}\n\n#{@progress.render}")
Style.join_vertical([card, help.render])
end
Finally, wire the raw-mode event loop with Terminal (pass mouse: true to receive mouse clicks and wheel scroll events):
model = AppModel.initial
Terminal.enter_alt_screen
defer Terminal.exit_alt_screen
Terminal.with_raw_mode(mouse: true) do
while !model.quit
Terminal.cursor_home
model.view.split('\n').each { |line| STDOUT.write(line + "\e[K\r\n") }
STDOUT.write("\e[J")
key = KeyEvent.read
break if key.none?
if key.is_click? && key.mouse.in_rect?(1, 1, 40, 6)
model = model.update(KeyEvent.parse("\e[C"))
else
model = model.update(key)
end
end
end
Mouse Support
Enable SGR mouse tracking with Terminal.with_raw_mode(mouse: true) (mouse reporting is automatically disabled on exit). Viewport and Table handle mouse wheel scrolling out of the box, and you can hit-test clicks anywhere on screen:
if key.is_click?
puts "Left click at col=#{key.mouse.x}, row=#{key.mouse.y}"
if key.mouse.in_rect?(left: 2, top: 4, width: 30, height: 10)
# Clicked inside panel
end
elsif key.is_wheel_up?
viewport = viewport.scroll_up
end
Components
| Component | Description |
|---|---|
ProgressBar | Clamped 0..100% bar with labels, custom glyphs, and theme colors |
Viewport | Scrollable text/log window (↑/↓, PgUp/PgDn, Home/End) with scro |
FilterList | Live searchable list with gold (#FACC15) substring match highlighting |
TextArea | Multi-line UTF-8 editor with line numbers and 2D cursor navigation |
Table | Column-aligned data table with ellipsis truncation and row selection |
Tabs | Horizontal tab bar controllable via ←/→ and ` |
Modal | Word-wrapped dialog box with centered render_over(screen) overlay |
Spinner | Animated status indicators (Spinner.dots, Spinner.line, Spinner.pulse) |
HelpBar | Automatic bottom key-hint bar rendered from KeyBinding arrays |
Running the Demo & Tests
iyi run examples/demo.iyi
iyi test tests
AI Agents (AGENTS.md)
Using an AI coding agent with itui? Point it to AGENTS.md for the full exported API map, component recipes, and iyi module rules.