Skip to main content

Crate slt

Crate slt 

Source
Expand description

SuperLightTUI — an immediate-mode flexbox-layout terminal UI library.

Build a TUI as easily as a web page: write a closure, SLT calls it every frame. State lives in your code; layout is described every frame; styling uses Tailwind-inspired shorthand; focus and events are threaded through a single Context parameter.

See docs/QUICK_START.md for a 5-minute introduction and docs/DESIGN_PRINCIPLES.md for the principles every public API follows.

§Example

fn main() -> std::io::Result<()> {
    slt::run(|ui| {
        ui.text("hello, world");
    })
}

§SLT — Super Light TUI

Immediate-mode terminal UI for Rust. Small core. Zero unsafe.

SLT gives you an egui-style API for terminals: your closure runs each frame, you describe your UI, and SLT handles layout, diffing, and rendering.

§Quick Start

fn main() -> std::io::Result<()> {
    slt::run(|ui| {
        ui.text("hello, world");
    })
}

§Features

  • Flexbox layoutrow(), col(), gap(), grow()
  • 50+ built-in widgets — input, textarea, table, list, tabs, button, checkbox, toggle, spinner, progress, toast, slider, separator, help bar, scrollable, chart, bar chart, stacked bar chart, sparkline, histogram, heatmap, treemap, candlestick, canvas, grid, select, radio, multi-select, tree, virtual list, command palette, markdown, alert, badge, stat, breadcrumb, accordion, code block, big text, image, modal, tooltip, form, calendar, file picker, qr code
  • Styling — bold, italic, dim, underline, 256 colors, RGB
  • Mouse — click, hover, drag-to-scroll
  • Focus — automatic Tab/Shift+Tab cycling
  • Theming — 10 presets, semantic tokens (ThemeColor), spacing scale, contrast helpers
  • Animation — tween and spring primitives with 9 easing functions
  • Inline mode — render below your prompt, no alternate screen
  • Async — optional tokio integration via async feature
  • Layout debugger — F12 to visualize container bounds

§Feature Flags

FlagDescription
crosstermBuilt-in terminal runtime (run, run_inline, clipboard query helpers). Enabled by default.
bidiReorder right-to-left text (Hebrew, Arabic, …) to visual order per UAX #9 before rendering. Enabled by default; pure-LTR text takes a zero-cost fast path. Since 0.21.0.
asyncEnable run_async() with tokio channel-based message passing
serdeEnable Serialize/Deserialize for Style, Color, Theme, and layout types
imageEnable image-loading helpers for terminal image widgets
qrcodeEnable ui.qr_code(...)
syntax / syntax-*Enable tree-sitter syntax highlighting

§Learn More

Re-exports§

pub use crate::test_utils::EventBuilder;
pub use crate::test_utils::FrameRecord;
pub use crate::test_utils::TestBackend;
pub use crate::test_utils::TestSequence;
pub use crate::test_utils::PtyBackend;pty-test
pub use crate::test_utils::PtyFrame;pty-test
pub use anim::Keyframes;
pub use anim::LoopMode;
pub use anim::Sequence;
pub use anim::Spring;
pub use anim::Stagger;
pub use anim::Tween;
pub use buffer::Buffer;
pub use cell::Cell;
pub use chart::Candle;
pub use chart::ChartBuilder;
pub use chart::ChartConfig;
pub use chart::Dataset;
pub use chart::LegendPosition;
pub use chart::Marker;
pub use context::Anchor;
pub use context::Bar;
pub use context::BarChartConfig;
pub use context::BarDirection;
pub use context::BarGroup;
pub use context::Breadcrumb;
pub use context::CanvasContext;
pub use context::CodeBlock;
pub use context::ContainerBuilder;
pub use context::Context;
pub use context::Gauge;
pub use context::GutterOpts;
pub use context::LineGauge;
pub use context::Memo;
pub use context::Response;
pub use context::State;
pub use context::TreemapItem;
pub use context::Widget;
pub use context::TaskHandle;async
pub use context::TaskOutcome;async
pub use event::Event;
pub use event::KeyCode;
pub use event::KeyEvent;
pub use event::KeyEventKind;
pub use event::KeyModifiers;
pub use event::ModifierKey;
pub use event::MouseButton;
pub use event::MouseEvent;
pub use event::MouseKind;
pub use halfblock::HalfBlockImage;
pub use keymap::Binding;
pub use keymap::KeyMap;
pub use keymap::PublishedKeymap;
pub use keymap::WidgetKeyHelp;
pub use layout::Direction;
pub use palette::Palette;
pub use rect::Rect;
pub use style::ThemeWatcher;theme-watch
pub use style::Align;
pub use style::Border;
pub use style::BorderSides;
pub use style::Breakpoint;
pub use style::Color;
pub use style::ColorDepth;
pub use style::ColorParseError;
pub use style::Constraints;
pub use style::ContainerStyle;
pub use style::HeightSpec;
pub use style::Justify;
pub use style::Margin;
pub use style::Modifiers;
pub use style::Padding;
pub use style::Spacing;
pub use style::Style;
pub use style::SyntaxPalette;
pub use style::Theme;
pub use style::ThemeBuilder;
pub use style::ThemeColor;
pub use style::UnderlineStyle;
pub use style::WidgetColors;
pub use style::WidgetTheme;
pub use style::WidthSpec;
pub use style::ThemeFile;serde
pub use style::ThemeLoadError;serde
pub use widgets::AsyncValidation;async
pub use widgets::validators;
pub use widgets::AlertLevel;
pub use widgets::ApprovalAction;
pub use widgets::BreadcrumbResponse;
pub use widgets::ButtonVariant;
pub use widgets::CalDate;
pub use widgets::CalendarSelect;
pub use widgets::CalendarState;
pub use widgets::ChordState;
pub use widgets::ColorPickerState;
pub use widgets::CommandPaletteState;
pub use widgets::ContextItem;
pub use widgets::DEFAULT_CHORD_TIMEOUT_TICKS;
pub use widgets::DirectoryTreeState;
pub use widgets::FileEntry;
pub use widgets::FilePickerScanError;
pub use widgets::FilePickerScanOperation;
pub use widgets::FilePickerScanStatus;
pub use widgets::FilePickerState;
pub use widgets::FormField;
pub use widgets::FormState;
pub use widgets::GaugeResponse;
pub use widgets::GridColumn;
pub use widgets::GutterResponse;
pub use widgets::HighlightRange;
pub use widgets::ListResponse;
pub use widgets::ListState;
pub use widgets::ModeState;
pub use widgets::MultiSelectState;
pub use widgets::NumberInputState;
pub use widgets::PaginatorState;
pub use widgets::PaginatorStyle;
pub use widgets::PaletteCommand;
pub use widgets::PickerMode;
pub use widgets::RadioState;
pub use widgets::RichLogEntry;
pub use widgets::RichLogState;
pub use widgets::SchedulerState;
pub use widgets::ScreenState;
pub use widgets::ScrollState;
pub use widgets::SelectState;
pub use widgets::SliderOpts;
pub use widgets::SpinnerPreset;
pub use widgets::SpinnerState;
pub use widgets::SplitPaneResponse;
pub use widgets::SplitPaneState;
pub use widgets::StaticOutput;
pub use widgets::StreamingMarkdownState;
pub use widgets::StreamingTextState;
pub use widgets::TableColumn;
pub use widgets::TableState;
pub use widgets::TabsState;
pub use widgets::TextInputState;
pub use widgets::TextareaState;
pub use widgets::ToastLevel;
pub use widgets::ToastMessage;
pub use widgets::ToastState;
pub use widgets::ToolApprovalState;
pub use widgets::TreeNode;
pub use widgets::TreeState;
pub use widgets::Trend;
pub use widgets::ValidateTrigger;
pub use widgets::Validator;
pub use crossterm;crossterm

Modules§

anim
Animation primitives: tween, spring, keyframes, sequence, stagger. Animation primitives: tweens, springs, keyframes, sequences, and staggers.
buffer
Double-buffered cell grid with clip stack and diff tracking. Double-buffer grid of Cells with clip-stack support.
cell
Terminal cell representation. Single terminal cell — the smallest unit of the render buffer.
chart
Chart and data visualization widgets. Data visualization: line charts, scatter plots, bar charts, and histograms.
context
UI context, container builder, and widget rendering. Context — the per-frame handle threaded into every render closure.
event
Input events (keyboard, mouse, resize, paste). Terminal input events.
halfblock
Half-block image rendering. Half-block image rendering for terminals with truecolor support.
keymap
Keyboard shortcut mapping.
layout
Flexbox layout engine and command tree. Flexbox layout engine: builds a tree from commands, computes positions, and renders to a Buffer.
palette
Color palettes (Tailwind-style).
rect
Rectangular region type used throughout SLT layout. Axis-aligned rectangle type used throughout SLT for layout regions, clipping bounds, and hit-test areas.
style
Styling: colors, borders, padding, margins, themes, constraints. Visual styling primitives.
syntax
Tree-sitter syntax highlighting integration. Tree-sitter based syntax highlighting.
test_utils
Headless test utilities for unit-testing TUI closures. Headless testing utilities.
widgets
Widget state types (list, table, input, select, etc.). Widget state types passed to Context widget methods.

Structs§

AppState
Opaque per-session state that persists between frames.
AsyncRunHandleasync and crossterm
Owned lifetime handle for an asynchronous SLT render loop.
AsyncSenderasync and crossterm
Bounded async message sender that wakes its associated render loop.
BlitterSupportcrossterm
Runtime terminal capability probe (issue #264): read-only Capabilities snapshot plus the Blitter ladder it drives. Diagnostics-only — image rendering routes through the ladder automatically. Image-rendering primitives the terminal can drive, used to build the automatic blitter ladder. Each flag is conservative: when the runtime probe returns no answer the defaults assume only the universally available primitives (half-block + quadrants).
Capabilitiescrossterm
Runtime terminal capability probe (issue #264): read-only Capabilities snapshot plus the Blitter ladder it drives. Diagnostics-only — image rendering routes through the ladder automatically. Read-only snapshot of negotiated terminal capabilities, populated once at session enter via DA1/DA2/XTGETTCAP.
InlineTerminalcrossterm
Concrete crossterm terminal backends, exposed (issue #278) so external integrations can drive SLT’s render pipeline with their own event loop — pair with event::from_crossterm. Most apps should use run / run_inline, which build and drive these internally. Inline crossterm terminal backend: renders into a fixed-height region below the cursor instead of taking over the whole screen.
RunConfig
Configuration for a TUI run loop.
Terminalcrossterm
Concrete crossterm terminal backends, exposed (issue #278) so external integrations can drive SLT’s render pipeline with their own event loop — pair with event::from_crossterm. Most apps should use run / run_inline, which build and drive these internally. Fullscreen crossterm terminal backend: owns raw mode + the alternate screen, double-buffers cells, and flushes only the diff each frame.

Enums§

AsyncRunErrorasync and crossterm
Error returned when an asynchronous run loop is joined.
Blittercrossterm
Runtime terminal capability probe (issue #264): read-only Capabilities snapshot plus the Blitter ladder it drives. Diagnostics-only — image rendering routes through the ladder automatically. Descending image-render preference. The first capability that is available wins; app code never selects a Blitter directly.
ColorSchemecrossterm
Detected terminal color scheme from OSC 11.
DebugLayer
Which layers the F12 debug overlay should outline (issue #201).

Traits§

Backend
Rendering backend for SLT.

Functions§

capabilitiescrossterm
Runtime terminal capability probe (issue #264): read-only Capabilities snapshot plus the Blitter ladder it drives. Diagnostics-only — image rendering routes through the ladder automatically. Return the process-global negotiated Capabilities, probing the terminal exactly once on first call and caching the result.
detect_color_schemecrossterm
Query the terminal’s background color via OSC 11 and return the detected scheme.
frame
Process a single UI frame with a custom Backend.
frame_owned
Process a single UI frame, taking ownership of the events Vec (zero-copy).
read_clipboardcrossterm
Read clipboard contents via an OSC 52 terminal query.
runcrossterm
Run the TUI loop with default configuration.
run_asyncasync and crossterm
Run the TUI loop asynchronously with default configuration.
run_async_withasync and crossterm
Run the TUI loop asynchronously with custom configuration.
run_inlinecrossterm
Run the TUI in inline mode with default configuration.
run_inline_withcrossterm
Run the TUI in inline mode with custom configuration.
run_staticcrossterm
Run the TUI in static-output mode.
run_static_withcrossterm
Run the TUI in static-output mode with custom configuration.
run_withcrossterm
Run the TUI loop with custom configuration.