console
A Rust library for terminal and console abstraction: colors, styles, cursor control, and terminal size detection
Repository Health
Technical Analysis
console is a Rust library that abstracts over terminal capabilities, giving CLI authors a single API for colored/styled text, cursor movement, terminal size detection, and reading keyboard input, working consistently across Unix, Windows, and WebAssembly targets. It automatically detects whether output is a TTY and whether colors should be enabled, following the clicolors convention, so styled output degrades gracefully when piped to a file or another program.
The crate is designed as a foundational building block for the wider Rust CLI ecosystem — it is the terminal layer underneath sibling crates like dialoguer (interactive prompts) and indicatif (progress bars), both part of the same console-rs GitHub organization. Its Term type provides direct or buffered terminal access, while Style/style() provide a fluent API for composing ANSI-styled text without manually managing escape codes.
What You Get
- A
Termtype for direct or buffered access to the connected terminal (write, clear line, move cursor) - A
style()/StyleAPI for composing ANSI-colored and styled text with automatic TTY/color detection - Cross-platform support for Unix, Windows (native console APIs), and WebAssembly targets
- Terminal size detection and Unicode-width-aware text measurement via the
unicode-widthfeature - Keyboard input reading utilities (
kbmodule) for building interactive terminal interfaces
Common Use Cases
- Adding colored/styled output to a Rust CLI tool that automatically disables color when piped or redirected
- Building interactive terminal prompts or progress indicators as the terminal layer under
dialoguerorindicatif - Detecting terminal width to wrap or truncate CLI output correctly across different terminal sizes
- Reading raw keyboard input for CLI tools that need interactive keypress handling
Under The Hood
Architecture
The crate splits terminal handling by platform: unix_term.rs (422 lines) and a windows_term/ module implement OS-specific terminal control (via libc on Unix, windows-sys Win32 console APIs on Windows), unified behind the public Term type in term.rs (687 lines); ansi.rs (471 lines) handles ANSI escape-sequence parsing/generation for styling, and utils.rs (1229 lines) hosts the Style/color-detection logic including the clicolors-standard TTY detection. A wasm_term.rs stub provides a no-op/limited implementation for WebAssembly targets where no real terminal exists.
Tech Stack
Rust with feature-gated dependencies: libc (optional, gated behind std), unicode-width (optional, for correct-width text measurement), windows-sys and encode_unicode only on Windows targets. The crate supports no_std-adjacent configurations via an alloc-only feature for environments without full std. Dev-dependencies include proptest for property-based testing and regex, run via a standard cargo test / Makefile-driven CI on GitHub Actions.
Code Quality
The tests/ directory includes a data fixture set alongside inline unit tests within the platform-specific source modules, and CI runs across multiple platforms per the badge in the README. The codebase is organized by clear platform/concern boundaries (ansi parsing vs. term control vs. utils), each file staying focused on one responsibility, though utils.rs at 1229 lines carries a large share of the styling and color-detection logic in one place.
API Design
The style() function and Term::stdout()/Term::stderr() entry points make the common case (print styled text, write a line) essentially zero-configuration, while Style::new() supports a fluent builder chain (.cyan().bold()) for more complex styling reused across multiple print calls. Being the shared terminal layer for dialoguer and indicatif means its API conventions are already familiar to a large share of the Rust CLI ecosystem, lowering the learning curve for anyone who has used those sibling crates.
Used by 8 apps in this directory
AppFlowy
Productivity · Project Management · Collaboration
The open-source AI workspace that puts your data, your rules — with local LLMs, CRDT collaboration, and full self-hosting built in.
Hook0
Devops
Open-source Webhooks-as-a-Service: deliver events to your users with auto-retry, signed payloads, and a real-time subscriber dashboard — all without building the infrastructure yourself.
iii
Developer Tools · Devops
Compose, extend, and observe every backend service in real time using three primitives: Workers, Functions, and Triggers.
Jan
AI Assistants
Run LLMs 100% locally with full privacy, or connect to cloud AI — your machine, your data, your control.
melty
Developer Tools · AI Code Assistants · Code Editors
The AI code editor where every chat message is a git commit you can revert, branch, or squash
Rivet
AI Agents · Developer Tools
Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.
Spacedrive
File Storage · Collaboration
One file manager for all your devices and clouds — powered by a Virtual Distributed File System built in Rust.
Void
AI Code Assistants · Code Editors · Automation
Open-source AI code editor with direct LLM integration and data privacy