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
924stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
50/100Fair
Development Activity44
Maintenance12
Community56
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
65/100Good
Architecture72
Code Quality70
Innovation62
Learning Curve55

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 16 apps in this directory

Go
55%
Apache 2.0

Authgear

Authentication

2,014

Open-source, self-hostable authentication platform with passkeys, biometric login, SSO, MFA, and GraphQL admin API — a full Auth0/Clerk/Firebase alternative for SaaS and mobile apps.

View details
88
Repo Health
81
Technical
69
Dependency
Built with
Go55%
HTML25%
TypeScript17%
Updated 4 days ago
Go
75%
AGPL 3.0

Coder

Devops · Developer Tools · Code Editors

14,299

Self-hosted cloud development environments and AI coding agents — defined in Terraform, connected via WireGuard, automatically shut down when idle.

View details
93
Repo Health
90
Technical
69
Dependency
Built with
Go75%
TypeScript23%
Updated today
Go
59%
Apache 2.0

Cog

AI Development · Devops · Developer Tools

9,464

An open-source CLI that packages machine learning models into standard, production-ready Docker containers — no Dockerfile wrangling, no CUDA version hell.

View details
90
Repo Health
88
Technical
69
Dependency
Built with
Go59%
Rust17%
HTML13%
Updated 4 days ago
Go
98%
Other

Crush

Developer Tools · AI Code Assistants · AI Assistants

27,798

Your terminal coding companion — wire up any LLM with LSP intelligence, MCP extensibility, and a skills system that learns your workflow.

View details
87
Repo Health
86
Technical
69
Dependency
Built with
Go98%
Updated today
Shell
48%
MIT

Dokku

Devops · Hosting Control Panel

32,114

The smallest PaaS implementation you've ever seen — deploy apps via git push using Docker and Heroku buildpacks on your own server.

View details
93
Repo Health
85
Technical
71
Dependency
Built with
Shell48%
Go48%
Updated today
Go
79%
Apache 2.0

Dolt

Databases · Data Engineering · Developer Tools

24,298

The SQL database you can branch, merge, diff, and clone — Git for your data, MySQL-compatible and ready for multi-agent AI workflows.

View details
90
Repo Health
9
Technical
67
Dependency
Built with
Go79%
Shell20%
Updated 2 days ago
Go
73%
Other

Flipt

Devops · Developer Tools

4,884

Git-native feature flag platform that stores, versions, and deploys feature toggles directly in your own Git repositories with no external database required.

View details
89
Repo Health
83
Technical
70
Dependency
Built with
Go73%
TypeScript26%
Updated yesterday
Go
83%
MIT

Gitea

Devops · Developer Tools · Project Management

57,677

Self-hosted DevOps in a single Go binary — Git hosting, GitHub Actions-compatible CI/CD, and 30+ package registries without any SaaS dependency.

View details
93
Repo Health
79
Technical
66
Dependency
Built with
Go83%
Updated today
Go
69%
MIT

Gotify

Monitoring · Developer Tools

15,818

A lightweight, self-hosted push notification server that sends and receives messages in real time over WebSocket, with a sleek web UI and a native Go plugin system.

View details
89
Repo Health
74
Technical
70
Dependency
Built with
Go69%
TypeScript30%
Updated 3 days 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

Search