Crossterm

A pure-Rust, cross-platform terminal manipulation library

Library
Cargo
v0.29.0
4,233 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
81 /100 Excellent
Development Activity 80
Maintenance 72
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
76 /100 Good
Architecture 82
Code Quality 76
Innovation 70
Learning Curve 75

Crossterm is a pure-Rust library for cross-platform terminal manipulation, covering cursor movement, text styling and colors, raw/alternate screen modes, and keyboard/mouse/resize event handling. It supports UNIX and Windows terminals down to Windows 7 with a single unified API, abstracting away the very different underlying terminal APIs each platform exposes.

Crossterm is one of the most widely depended-upon crates in the Rust TUI ecosystem, serving as the terminal backend for higher-level TUI frameworks like Ratatui, and is used directly by countless CLI tools that need styled output, interactive prompts, or full-screen terminal UIs without shelling out to platform-specific APIs.

What You Get

  • Cursor control: move, hide/show, blink, save/restore position
  • Styled output: 16-color, 256-color (ANSI), and RGB foreground/background colors plus text attributes (bold, italic, underline)
  • Terminal control: raw mode, alternate screen, scroll, resize, clear, and title-setting
  • A unified event system for keyboard, mouse (press/release/drag), and terminal-resize events with modifier key support
  • A command API (queue!/execute! macros) for buffered, flush-controlled output writing
  • Clipboard integration and bracketed-paste event support

Common Use Cases

  • Building full-screen terminal UIs (TUIs) as the low-level backend beneath frameworks like Ratatui
  • Adding cross-platform colored/styled output to CLI tools without shelling out to OS-specific APIs
  • Building interactive terminal applications that need mouse and keyboard event handling (editors, dashboards, games)
  • Writing portable terminal tooling that must behave identically on Windows and UNIX terminals

Under The Hood

Architecture — The crate is organized by terminal concern: src/cursor/, src/style/, src/terminal/, and src/event/ each expose a public module plus platform-specific backend implementations selected at compile time (UNIX ANSI escape-sequence writers vs Windows Console API calls), unified behind a common Command trait (src/command.rs) so callers write one line of code (execute!(stdout, MoveTo(x, y))) regardless of platform. src/tty.rs and src/ansi_support.rs handle detecting whether a stream is a real TTY and whether the terminal actually supports ANSI sequences (relevant on older Windows consoles), falling back accordingly.

Tech Stack — Pure Rust with a deliberately minimal dependency footprint (a stated design goal in the README’s ‘Dependency Justification’ section), using conditional compilation (cfg(windows)/cfg(unix)) rather than separate crates per platform. Feature flags (bracketed-paste, events, windows, derive-more) let consumers opt out of functionality they don’t need to shrink the dependency graph further, similar to other console-rs-family crates.

Code Quality — Roughly 19 source files carry inline #[test]/mod test blocks covering event parsing, cursor/style command construction, and platform-detection logic — reasonable given how much of the remaining logic is platform-specific behavior that’s difficult to unit test outside a real terminal. The crate has a long release history and is depended upon by enough downstream TUI projects (notably Ratatui) that regressions tend to surface quickly through the ecosystem.

API Design — The Command/execute!/queue! macro pair is the core ergonomic device: every terminal action (MoveTo, SetForegroundColor, Clear) implements Command, so execute!(stdout(), MoveTo(0,0), Print("hi")) composes multiple actions into one buffered write without manual escape-sequence construction. This consistency is what makes Crossterm pleasant to build directly on, though full-screen TUI application authors still typically reach for a higher-level framework (Ratatui) built on top rather than using Crossterm’s primitives directly for complex layouts.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers