go-isatty

Cross-platform Go library that detects whether a file descriptor is connected to a terminal, including Cygwin and MSYS2 ptys on Windows.

Library
Go
vv0.0.24
927 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
40 /100 Fair
Development Activity 16
Maintenance 0
Community 56
Maturity 60
Momentum 28

Technical Analysis

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

go-isatty is a minimal, dependency-light Go package that answers one question reliably across platforms: is this file descriptor attached to an interactive terminal? It underpins color and TTY-detection logic in some of the Go ecosystem’s most widely used CLI tools, letting them decide when to emit ANSI colors, progress bars, or interactive prompts versus falling back to plain output for pipes, redirects, and CI logs.

The implementation is split by build tags into platform-specific files — BSD/Darwin using ioctl TIOCGETA via golang.org/x/sys/unix, Windows using GetConsoleMode plus an NtQueryObject-based Cygwin/MSYS2 pty name check, Plan9, Solaris, and a catch-all stub for sandboxed runtimes like js/wasm and App Engine. Each file compiles only for its target OS via Go build constraints, so the public IsTerminal and IsCygwinTerminal functions stay a small, stable two-function API regardless of platform.

What You Get

  • A single IsTerminal(fd uintptr) bool function that works uniformly across Linux, BSD/Darwin, Windows, Plan9, Solaris, and sandboxed runtimes
  • IsCygwinTerminal(fd uintptr) bool for detecting Cygwin and MSYS2 pseudo-terminals on Windows, where the native console API alone can’t tell
  • Platform-specific implementations selected automatically at compile time via Go build tags, with no runtime detection overhead
  • A dependency footprint limited to golang.org/x/sys, keeping it safe to vendor into CLI tools without dragging in a larger toolkit

Common Use Cases

  • CLI tools deciding whether to emit ANSI color codes or plain text depending on whether stdout is a terminal or a redirected file/pipe
  • Interactive prompts and spinners that should only render when attached to a real terminal, not when running in CI or as part of a script
  • Logging libraries that switch between colorized human-readable output and structured plain output based on terminal detection
  • Cross-platform Go tools that need consistent terminal detection on Windows including Cygwin/MSYS2 environments, not just native Windows consoles

Under The Hood

Architecture

go-isatty is a flat, single-package library with no internal layering — its entire public surface is two functions, IsTerminal and IsCygwinTerminal, declared once conceptually and implemented separately per platform via Go build constraints (isatty_bsd.go, isatty_windows.go, isatty_others.go, and platform equivalents for Linux, Plan9, and Solaris). Each file satisfies the same signature so the compiler selects exactly one implementation per build target, meaning there’s no runtime branching, interface indirection, or dependency injection — callers pass a raw uintptr file descriptor directly to a syscall wrapper. If the core two-function signature ever changed, every downstream consumer that gates terminal-aware behavior — colorized CLIs, prompt libraries, loggers — would need updating, which is why the API has stayed stable for over a decade.

Tech Stack

The stack is intentionally minimal: Go 1.20+ as declared in go.mod, with a single external dependency, golang.org/x/sys v0.28.0, used only on BSD/Darwin targets to call unix.IoctlGetTermios. The Windows implementation bypasses any external package and calls kernel32.dll (GetConsoleMode, GetFileInformationByHandleEx, GetFileType) and ntdll.dll (NtQueryObject) directly via syscall.NewLazyDLL, avoiding cgo entirely. There’s no build tooling beyond the standard go build/go test toolchain and a go.test.sh coverage script; the library has no deployment target of its own since it’s consumed as a vendored dependency inside other Go binaries.

Code Quality

Test coverage is present but shallow — the non-Windows and Windows test files run largely smoke-level checks (one test’s own comment notes it verifies non-panic behavior rather than a specific return value, since terminal state depends on how the test runner is invoked). Error handling favors returning a plain bool over propagating errors, which fits a boolean-predicate API. What compensates for the thin unit assertions is a genuinely rigorous CI setup: GitHub Actions runs the full suite with the race detector across Linux, macOS, and Windows runners on multiple Go versions each, uploading coverage to Codecov on every push and pull request. Naming is idiomatic Go throughout, and there’s no dedicated linter configuration, but the surface area is small enough that this is a low-risk gap.

What Makes It Unique

go-isatty doesn’t innovate technically — TTY detection via ioctl or GetConsoleMode is a well-understood, decades-old technique — but its practical contribution is being the de facto standard implementation the Go ecosystem converged on for exactly this problem, correctly handling an edge case most naive implementations miss: Cygwin and MSYS2 terminals on Windows report as pipes rather than consoles, so a plain GetConsoleMode check returns false even inside an interactive Cygwin shell. Its named-pipe pattern inspection to recover that information, plus a documented fallback to the undocumented NtQueryObject API for older Windows versions, reflects accumulated platform knowledge rather than a novel architecture.

Used by 17 apps in this directory

TypeScript
47%
AGPL 3.0

Grafana

Analytics · Monitoring

77,469

The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.

View details
95
Repo Health
91
Technical
63
Dependency
Built with
TypeScript 47%
Go 47%
Updated 6 days ago
Go
62%
Apache 2.0

Harness Open Source

Code Editors · Developer Tools · Devops

38,684

A unified open source DevOps platform combining Git hosting, CI/CD pipelines, cloud development environments, and artifact registries in a single self-hosted system.

View details
90
Repo Health
79
Technical
64
Dependency
Built with
Go 62%
TypeScript 33%
Updated 1 weeks ago
Go
69%
MIT

hoop

Monitoring · Security

836

A wire-protocol gateway that enforces data masking, command blocking, approval workflows, and full session recording for engineers and AI agents accessing production infrastructure.

View details
86
Repo Health
80
Technical
64
Dependency
Built with
Go 69%
Clojure 13%
Updated 6 days ago
TypeScript
44%
Other

Magic

AI Agents · Automation · Low Code Platforms

5,055

Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.

View details
68
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 44%
PHP 32%
Updated 2 months ago
Go
48%
GPL 3.0

Netdata

Devops · Monitoring

81,111

Real-time per-second metrics, ML-powered anomaly detection, and zero-config observability for any infrastructure.

View details
93
Repo Health
86
Technical
70
Dependency
Built with
Go 48%
C 29%
Rust 15%
Updated 6 days ago
Go
98%
Apache 2.0

Nightingale

Monitoring

13,383

Open-source alerting engine that connects to any time-series or log data source and routes alarms to 20+ notification channels with AI-assisted triage.

View details
95
Repo Health
77
Technical
67
Dependency
Built with
Go 98%
Updated 1 weeks ago
Go
100%
Apache 2.0

SpiceDB

Authentication · Databases · Security

7,169

An open source, Google Zanzibar-inspired authorization database that models permissions as relationships and evaluates fine-grained access checks at massive scale with single-digit millisecond latency.

View details
89
Repo Health
89
Technical
67
Dependency
Built with
Go 100%
Updated 1 weeks ago
Go
99%
Apache 2.0

Tusk

AI Code Assistants · Developer Tools · Devops

143

Record live API traffic and replay it as deterministic, sandboxed tests, plus AI code review and unit test generation, all from one Go CLI built by YC W2024's Use-Tusk.

View details
42
Repo Health
77
Technical
76
Dependency
Built with
Go 99%
Updated 5 months ago

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