uncurses 0.0.1

A Rust terminal rendering library
Documentation

uncurses

CI License: MIT Rust 1.88+ Website

A Rust library for building terminal user interfaces. It provides a direct, framework-free way to draw to the terminal and read input, giving you control over every cell and your own event loop, whether you run inline, take over the full screen, mix the two, or leave the console unmanaged and just shape your output. It includes a diffing renderer that redraws only what changed, Unicode-aware width, truecolor styling with automatic downsampling, hyperlinks, and typed keyboard, mouse, and paste input. Rather than a terminfo database, it detects capabilities through terminal queries and runs across Linux, macOS, and Windows.

Usage

The whole lifecycle is three calls: init() claims the terminal, render() ships changed cells, finish() restores it.

use uncurses::event::Event;
use uncurses::screen::Screen;
use uncurses::style::Style;
use uncurses::text::TextSurface;

fn main() -> std::io::Result<()> {
    let mut screen = Screen::stdio()?;
    screen.init()?;
    screen.enter_alt_screen()?; // take over the full screen
    screen.set_str((0, 0), "hello, uncurses", Style::new());
    screen.render()?;
    while !matches!(screen.read_event()?, Event::KeyPress(_)) {} // wait for a key
    screen.finish()
}

Add an event loop to react to input. A Screen session starts inline (drawing in the normal buffer) with the cursor visible; the alternate screen and a hidden cursor are opt-in.

use uncurses::buffer::Bounded;
use uncurses::event::{Event, Key};
use uncurses::screen::Screen;
use uncurses::style::Style;
use uncurses::text::TextSurface;

fn main() -> std::io::Result<()> {
    let mut screen = Screen::stdio()?;
    screen.init()?; // raw mode + capability detection; inline, cursor visible
    let w = screen.width();
    screen.resize((w, 2)); // inline: one text row plus a trailing blank line

    screen.set_str((0, 0), "Hello! Press q to quit.", Style::new());
    screen.render()?;

    let q: Key = "q".parse().unwrap();
    loop {
        let ev = screen.read_event()?;
        screen.observe_event(&ev)?;
        if matches!(ev, Event::KeyPress(k) if k == q) {
            break;
        }
    }

    screen.finish() // restore the terminal, always, one call
}

observe_event is opt-in. Skip it and reads still work; you only forgo capability tracking for mouse, kitty keyboard, in-band resize, truecolor, and grapheme support.

That's the shape of it; the full API and guides live at uncurses.org.

Install

Not on crates.io yet, so depend on it straight from git:

[dependencies]
uncurses = { git = "https://github.com/aymanbagabas/uncurses" }

Runs on Linux, macOS, Windows, and the BSDs. Uses the 2024 edition and tracks the latest stable Rust (currently 1.88 or newer).

Features: unicode-rs (default) for width and segmentation, icu for ICU4X-backed correctness, and async for runtime-agnostic event_stream(), an owned futures_core::Stream over the screen's own decoder with no executor dependency.

Credits

  • ncurses: the original the name nods to, minus the terminfo baggage.
  • ultraviolet: Charm's terminal library, the inspiration for the cell and screen model.
  • colorprofile: Charm's color degradation library, the model behind uncurses color profiles.
  • ratatui: the Rust TUI framework, wired up through uncurses-ratatui.

License

MIT. See LICENSE.