TTYHAWK 0.1.1 (C) kwy404, MIT Self test ...... 2.6 kB, 0 deps [ OK ] Probing terminal: TERM=xterm-256color COLORTERM=truecolor colorLevel ... 3 truecolor [ OK ] unicode ...... true [ OK ] hyperlinks ... true [ OK ] isCI ......... false [ OK ] size ......... 80 x 24 [ OK ] Ready.
Know what the terminal can do, in one tiny call.
Color depth, unicode, clickable links, size and CI, answered by one consistent rulebook that respects NO_COLOR, FORCE_COLOR and CLICOLOR, with every input injectable for tests.
$ npm i ttyhawk
Runs onNode 18+BunDeno 2Browsers
1Live playground
Flip the environment, watch the hawk adapt
This is the real ttyhawk source running in your browser. Pick a terminal, toggle variables and see the detection and sample output change at every level.
- { p.label }
- { p.label }
Decided by: { decided }
2Why it exists
One question, four packages, four rulebooks
Scattered answers
Color, unicode, hyperlinks and CI each lived in a different package, each with its own idea of which variable wins. Two of them read the same TERM and still disagreed.
Standards, followed to the letter
NO_COLOR, FORCE_COLOR and CLICOLOR are documented conventions. ttyhawk implements them as written, in a precedence order that is printed in the README and pinned by tests.
Testable by design
Pass env, argv, platform, osRelease and isTTY to get a deterministic answer. No global mutation, no re-import, no flaky CI because the runner had a TTY.
$ Same input, five answers supports-color NO_COLOR=1 2 supports-color FORCE_COLOR=yes, no TTY 0 is-unicode-supported LANG=en_US.ISO-8859-1 true supports-hyperlinks Netlify build true $ ttyhawk detect() NO_COLOR=1 0 detect() FORCE_COLOR=yes, no TTY 1 detect() LANG=en_US.ISO-8859-1 false detect() Netlify build false = one rulebook
3Features
Everything a CLI needs to know before it prints
Color level 0 to 3
No color, 16, 256 or truecolor, from TERM, COLORTERM, TERM_PROGRAM, Windows builds and CI log viewers.
Unicode that renders
Knows the Linux console, legacy Windows consoles, Windows Terminal, VS Code and non UTF-8 locales.
Clickable links
OSC 8 support for iTerm, WezTerm, VS Code, ghostty, kitty, VTE, foot and Windows Terminal, with FORCE_HYPERLINK.
Eleven CI providers
GitHub Actions, GitLab, CircleCI, Travis, Buildkite, Azure, Jenkins, TeamCity, Bitbucket, Vercel, Netlify, and CI=false to opt out.
The conventions, done right
NO_COLOR and FORCE_COLOR ignore empty values, FORCE_COLOR=0..3 sets exact levels, CLICOLOR and CLICOLOR_FORCE behave as specified.
Size with fallbacks
Columns and rows from the stream, then COLUMNS and LINES, then 80 by 24. Never throws.
Every runtime
Node 18+, Bun, Deno 2 with or without permissions, and browsers. ESM, CommonJS and types.
Speaks Node
toColorDepth and fromColorDepth convert levels to the bit depth of Node's getColorDepth, with parity tests.
toColorDepth(colorLevel(stream)); // 1, 4, 8 or 24 fromColorDepth(stream.getColorDepth()); // 0 to 3
4Precedence
Who wins, in order
The first rule that applies decides the color level. Everything below is covered by tests with injected environments.
- Command line flags such as --no-color and --color=256, only when you pass argv: true.
- FORCE_COLOR: 0 or false turns color off, 1 to 3 set the level, true forces color at the detected depth.
- NO_COLOR and NODE_DISABLE_COLORS: any non empty value turns color off.
- CLICOLOR_FORCE forces color on, then CLICOLOR=0 turns it off.
- No TTY means no color, unless a rule above forced it. TERM=dumb means no color.
- Windows Terminal and the Windows build number, then CI log viewers.
- COLORTERM, TERM_PROGRAM and finally the TERM name.
5How to
Small surface, sharp answers
NAME
ttyhawk: Check if a terminal supports color, truecolor, unicode and hyperlinks, and detect CI, in one call. Honors NO_COLOR and FORCE_COLOR. Zero dependencies.
SYNOPSIS
import { detect, colorLevel, supportsUnicode, supportsHyperlinks, isCI, ciName, terminalSize, toColorDepth, fromColorDepth } from 'ttyhawk'; detect(stream, { env, argv, platform, osRelease, isTTY }); // { isTTY, colorLevel, unicode, hyperlinks, columns, rows, isCI, ciName }
DESCRIPTION
Every function takes the same options: env, argv, platform, osRelease and isTTY. The full reference, with every rule, is in the README.
EXAMPLES
import { detect, colorLevel } from 'ttyhawk';const caps = detect(process.stderr);// { isTTY: true, colorLevel: 3, unicode: true, hyperlinks: true,// columns: 120, rows: 34, isCI: false, ciName: null }const tick = caps.unicode ? '\u2714' : 'v';if (colorLevel(process.stderr) >= 2) { // 256 colors or more: use the richer palette}
import { test } from 'node:test';import assert from 'node:assert/strict';import { detect } from 'ttyhawk';test('respects NO_COLOR', () => { const caps = detect(null, { env: { TERM: 'xterm-256color', NO_COLOR: '1' }, platform: 'linux', isTTY: true, }); assert.equal(caps.colorLevel, 0);});
#!/usr/bin/env nodeimport { colorLevel, supportsHyperlinks } from 'ttyhawk';// Only the CLI entry point opts in to --color and --no-color.const level = colorLevel(process.stdout, { argv: true });const links = supportsHyperlinks(process.stdout, { argv: true });const link = (text, url) => links ? `\x1b]8;;${url}\x07${text}\x1b]8;;\x07` : `${text} (${url})`;
import { colorLevel, toColorDepth, fromColorDepth } from 'ttyhawk';toColorDepth(colorLevel(process.stdout, { isTTY: true })); // 24// same scale as process.stdout.getColorDepth()fromColorDepth(8); // 2
SEE ALSO
6Comparison
One package instead of four
What each package covers, checked against its source code and the scenarios in the next table.
| Capability | ttyhawk | supports-color | is-unicode-supported | supports-hyperlinks | ci-info |
|---|---|---|---|---|---|
| Color level 0 to 3 | |||||
| Honors NO_COLOR | |||||
| Honors CLICOLOR and CLICOLOR_FORCE | |||||
| Unicode detection | |||||
| OSC 8 hyperlink detection | |||||
| CI provider detection | |||||
| Injectable env object for tests | |||||
| Reads command line flags only when asked | |||||
| Zero dependencies |
Partial: supports-color always reads flags in its default export; createSupportsColor accepts sniffFlags: false. 34 scenarios, supports-color 11.0.0, is-unicode-supported 2.1.0, supports-hyperlinks 5.0.0, ci-info 4.5.0, Node v24.16.0
Where ttyhawk answers differently
Each scenario ran through ttyhawk and the popular single purpose packages in a fresh process. These are the cases where the answers differ; the README explains why for each one.
| Scenario | Package | Their answer | ttyhawk |
|---|---|---|---|
NO_COLOR=1 | supports-color | 2 | 0 |
FORCE_COLOR empty, no TTY | supports-color | 1 | 0 |
FORCE_COLOR=yes, no TTY | supports-color | 0 | 1 |
CLICOLOR_FORCE=1, no TTY | supports-color | 0 | 1 |
CLICOLOR=0 | supports-color | 2 | 0 |
TERM=xterm-direct | supports-color | 1 | 3 |
TERM=alacritty | supports-color | 0 | 3 |
TERM=alacritty | supports-hyperlinks | false | true |
vscode 1.95 | supports-color | 2 | 3 |
WezTerm | supports-color | 2 | 3 |
LANG=en_US.ISO-8859-1 | is-unicode-supported | true | false |
Windows, GitHub Actions | is-unicode-supported | false | true |
GitLab CI on a TTY | supports-color | 1 | 2 |
Azure Pipelines | supports-color | 1 | 0 |
Netlify build | supports-hyperlinks | true | false |
Netlify build | ci-info name | "Netlify CI" | "Netlify" |
CI=false with GitHub vars | supports-color | 3 | 0 |
7Benchmarks
Honest numbers
Operations per second, median of five runs, every library reading the same process.env. On Windows each process.env read is slow and ttyhawk reads more variables because it follows more rules, so it trails per call. With a plain env object it is the fastest. Detection runs once at startup either way.
Color level
Unicode
Hyperlinks
Everything
ops/s
Size
Smaller than this paragraph's screenshot
Measured on the ESM entry with terser and gzip. No dependencies, no side effects, tree shakeable named exports.
min + gzip
Compatibility
Runs where your CLI runs
- Node 18 to 24 Tested in CI on Linux, Node 24 also on Windows and macOS
- Bun 1.x Smoke tested in CI
- Deno 2 Smoke tested in CI, with and without --allow-env and --allow-sys
- Browsers Works: reports no TTY and no color unless you pass options
8FAQ
Questions people ask
Give your CLI a hawk eye view
One import, one call, and your output fits every terminal it lands in.
$ npm i ttyhawk