Expand description
An opinionated, minimal terminal UI crate.
§Rect based rendering and layout
Rect is the core abstraction in extui, use builder style methods to paint to the screen using an DoubleBuffer for rendering to screen efficiently.
use extui::{Rect, DoubleBuffer, Style, Color};
fn render_list(items: &[&str], mut area: Rect, buf: &mut DoubleBuffer) {
for item in items {
if area.h == 0 {
break;
}
area.take_top(1).with(Style::DEFAULT).text(buf, item);
}
}§Deliberate Limitations
extui intentionally omits certain features for simpler interfaces and better performance:
- 8-bit color only - No 24-bit (true color) support. The 256-color palette covers most use cases with significantly simpler encoding.
- 4-byte grapheme limit - Characters exceeding 4 bytes are truncated. This
enables fixed-size
Cellstorage. Most text fits within this limit. - Unix only - No Windows support. This allows direct use of POSIX APIs without abstraction overhead.
§Getting Started
use extui::{Terminal, TerminalFlags, DoubleBuffer, Style, Color};
use extui::event::{self, Event, KeyCode, Events};
// Open terminal in raw mode with alternate screen
let mut term = Terminal::open(
TerminalFlags::RAW_MODE | TerminalFlags::ALT_SCREEN | TerminalFlags::HIDE_CURSOR
)?;
let (w, h) = term.size()?;
let mut buf = DoubleBuffer::new(w, h);
let mut events = Events::default();
loop {
// Render
buf.rect().with(Color::Blue1.as_bg()).fill(&mut buf);
buf.rect().with(Style::DEFAULT).text(&mut buf, "Press 'q' to quit");
buf.render(&mut term);
// Poll for events
if event::poll(&std::io::stdin(), None)?.is_readable() {
events.read_from(&std::io::stdin())?;
while let Some(ev) = events.next(term.is_raw()) {
if let Event::Key(key) = ev {
if key.code == KeyCode::Char('q') {
return Ok(());
}
}
}
}
}Modules§
- event
- Terminal event polling and parsing.
- vt
- VT escape sequence generation.
- widget
- Optional widget primitives.
Macros§
- splat
- Writes multiple VT escape sequences to a byte buffer.
Structs§
- Block
- A bordered container widget with optional title.
- BoxStyle
- Characters used to draw box borders.
- Buffer
- A rectangular grid of terminal cells.
- Cell
- A single terminal cell containing styled text.
- Color
- A 256-color palette index.
- Display
Rect - A rectangle with associated rendering properties.
- Double
Buffer - Double-buffered terminal output with differential rendering.
- Rect
- A rectangular region defined by position and size.
- RelSet
- A set of relative positions for partial box rendering.
- Render
Properties - Properties controlling how content is rendered within a region.
- Style
- Text styling attributes including foreground color, background color, and modifiers.
- Style
Delta - Tracks a style transition for efficient escape sequence generation.
- Terminal
- A handle to the terminal with RAII-based mode management.
- Terminal
Flags - Configuration flags for terminal mode and capabilities.
Enums§
- Alignment
- Horizontal text alignment within a region.
- Border
Type - Style of border characters for blocks.
- HAlign
- Horizontal alignment within a region.
- Rel
- A relative position within a 3x3 grid.
- VAlign
- Vertical alignment within a region.
Traits§
- Render
Property - A property that can be applied to
RenderProperties. - Split
Rule - Defines how to split a dimension into two parts.