is-terminal

A tiny Rust crate that tests whether a given I/O stream is a terminal (tty)

Library
Cargo
v0.4.17
53stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
29/100Needs Attention
Development Activity0
Maintenance0
Community48
Maturity56
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture80
Code Quality82
Innovation72
Learning Curve92

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.

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

Search