is-terminal
A tiny Rust crate that tests whether a given I/O stream is a terminal (tty)
Repository Health
Technical Analysis
is-terminal is a small, focused Rust utility that answers a single question: is this stream a terminal? It provides an IsTerminal trait implemented for high-level standard stream types, behaving like the classic isatty check on Unix while using platform-appropriate techniques on Windows, WASI, and Hermit.
Command-line tools rely on this signal to decide whether to emit ANSI colors, draw progress bars, or switch to plain output when piped. Now that Rust 1.70 ships an IsTerminal trait in the standard library, most users can migrate, but this crate remains a widely depended-upon, portable option supporting a broad range of targets.
What You Get
- An IsTerminal trait with an is_terminal() method for standard stream types
- Consistent tty detection across Unix, Windows, WASI, and Hermit targets
- A libc-based Unix implementation matching the standard library’s behavior
- Windows-specific detection using console and file-system APIs
- A tiny dependency footprint with no runtime overhead beyond the syscall
Common Use Cases
- Deciding whether a CLI should emit ANSI color codes or plain text
- Enabling interactive prompts and progress bars only when attached to a tty
- Detecting piped or redirected output to switch to machine-readable formatting
- Providing portable terminal detection on platforms beyond Unix and Windows
Under The Hood
Architecture - The entire crate is a single src/lib.rs (~380 lines) defining the IsTerminal trait and per-platform implementations gated by cfg attributes. On Unix and WASI it calls into libc’s isatty equivalent; on Windows it combines console and file-system probes; Hermit uses hermit-abi; unsupported targets fall back to no_std.
Tech Stack - Pure Rust with platform-conditional dependencies: libc on Unix/WASI, windows-sys on Windows, and hermit-abi on Hermit. Dev-dependencies (atty, rustix, tempfile) back the test suite. Built with Cargo.
Code Quality - The implementation is small, focused, and battle-tested through nearly 300M downloads, with runnable examples and tests that cross-check results against alternative implementations like rustix and atty. The README transparently points newer users to the std IsTerminal trait.
API Design - The public surface is a single method, is_terminal(), mirroring the standard library’s later trait exactly, so adoption and migration are trivial with essentially zero boilerplate.
Used by 2 apps in this directory
Meilisearch
Search
Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.
PostgresML
Databases · AI Development
Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.