GitHub
Skip to content

Color and glyphs

The one rule readerly uses to turn color on or off, which formats never print escape codes, and the glyphs and colors the text format uses.

readerly decides color once per run, with one rule, and prints the same small set of glyphs in every tool. This page covers both.

Only the text format prints color. agent, json and jsonl never print an escape code, even with --color, so an agent or a parser never has to strip one.

For text, colorDecision() in src/color.ts takes the first signal that applies:

  1. --color turns color on, and --no-color turns it off. The last one given wins.
  2. FORCE_COLOR, when set, turns color off for 0 or false and on for any other value, the empty string included.
  3. NO_COLOR with any non-empty value turns color off.
  4. When stdout is not a TTY, color is off.
  5. TERM=dumb turns color off.
  6. Otherwise, color is on.

The TTY in step 4 is stdout's, as detect() saw it, even for what readerly writes to stderr. Without --color or FORCE_COLOR, piping stdout to a file turns color off for the whole run.

colorDecision() returns the decision and the signal that made it, the same string --verbose prints:

import { colorDecision, colorEnabled } from "readerly/color";

colorDecision({ env: { FORCE_COLOR: "0" }, isTTY: true });
// { enabled: false, why: "FORCE_COLOR=0" }

colorDecision({ flag: true, env: { NO_COLOR: "1" }, isTTY: false });
// { enabled: true, why: "--color" }

colorEnabled({ env: { TERM: "dumb" }, isTTY: true });
// false
color.ts

In a createOut command, the result is out.profile.color, and out.profile.why.color holds the reason. Use it when you color something yourself, such as a Markdown answer you render with @comark/ansi.

readerly colors text with styleText from node:util, and names styles such as red, bold and dim instead of RGB values. The terminal's theme picks the real color. createStyle(enabled) returns a function that takes a style name, or a list of them, and the text:

import { createStyle } from "readerly/color";

const style = createStyle(out.profile.color);
style("red", "✖");
style(["bold", "red"], "error");
style.ts

When enabled is true, it always emits escape codes, whatever stream the text ends up on. readerly has already made the decision, so styleText's own stream check is off. When enabled is false, it returns the text unchanged.

readerly uses a small set of glyphs, and each has one meaning. A tool built on readerly uses them the same way and adds no others.

GlyphColorMeansPrinted by
✖redThe run failed, or the failure that stopped ittext: the verdict line and a failure's headline
⚠yellowThe run finished with errors or warnings, or needs input (action_required)text: the verdict line
✔greenThe run finished cleantext: the verdict line
├▶dimA branch of the line above; more followtext, tree()
╰▶dimThe last branchtext, tree()
… N moredimRows the row cap hid, with the rerun commandtext
hidden:noneLines the budget dropped, with the rerun commandsagent, the last line
next:noneA command to run next, then its reasontext, agent
?noneA prompt waiting for an answer, on stderrtext at a terminal
█ ░noneA progress bar, on stderrtext at a terminal

Besides the glyphs, text colors the severity labels, error red, warn yellow and info cyan, and prints the verdict's words, each diagnostic's headline and the branch labels such as why: in bold.

Only a failed status shows ✖. A run that a tool ends with out.end({ status: "ok" }) shows ⚠ when it counted errors or warnings, and ✔ when it counted neither.

A status never depends on color alone. The glyph says it, and the words say it again: ✖ 2 errors, error ACME001. With color off, in a pipe, in CI or under NO_COLOR, the output keeps every glyph and every word, so it reads the same.

The agent format goes further and drops the glyphs too. A coding agent reads acme check: failed. and error ACME001 as plain words. See Coding agents.