# Color and glyphs

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

## The color rule

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`](https://github.com/loadsheet/readerly/blob/main/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:

```ts [color.ts]
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
```

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](https://readerly.loadsheet.dev/integrations/markdown-answers).

## Styling without a dependency

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:

```ts [style.ts]
import { createStyle } from "readerly/color";

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

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.

## Glyphs

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.

| Glyph | Color | Means | Printed by |
| --- | --- | --- | --- |
| `✖` | red | The run failed, or the failure that stopped it | `text`: the verdict line and a failure's headline |
| `⚠` | yellow | The run finished with errors or warnings, or needs input (`action_required`) | `text`: the verdict line |
| `✔` | green | The run finished clean | `text`: the verdict line |
| `├▶` | dim | A branch of the line above; more follow | `text`, `tree()` |
| `╰▶` | dim | The last branch | `text`, `tree()` |
| `… N more` | dim | Rows the row cap hid, with the rerun command | `text` |
| `hidden:` | none | Lines the budget dropped, with the rerun commands | `agent`, the last line |
| `next:` | none | A command to run next, then its reason | `text`, `agent` |
| `?` | none | A prompt waiting for an answer, on stderr | `text` at a terminal |
| `█ ░` | none | A progress bar, on stderr | `text` 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.

## Color is never the only signal

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](https://readerly.loadsheet.dev/guide/agents).

<!-- vitehub-docs:section-links -->
## In this section

- [Introduction](https://readerly.loadsheet.dev/raw/guide.md)
- [Installation](https://readerly.loadsheet.dev/raw/guide/installation.md)
- [Readers](https://readerly.loadsheet.dev/raw/guide/readers.md)
- [Coding agents](https://readerly.loadsheet.dev/raw/guide/agents.md)
- [Formats](https://readerly.loadsheet.dev/raw/guide/formats.md)
- [Shared flags](https://readerly.loadsheet.dev/raw/guide/flags.md)
- [Color and glyphs](https://readerly.loadsheet.dev/raw/guide/color.md) (this page)
- [Diagnostics](https://readerly.loadsheet.dev/raw/guide/diagnostics.md)
- [Budget](https://readerly.loadsheet.dev/raw/guide/budget.md)
- [Prompts and input](https://readerly.loadsheet.dev/raw/guide/prompts.md)
- [Failures and exit codes](https://readerly.loadsheet.dev/raw/guide/failures.md)
- [JSON and JSONL](https://readerly.loadsheet.dev/raw/guide/json.md)
- [Custom renderers](https://readerly.loadsheet.dev/raw/guide/renderers.md)
- [API](https://readerly.loadsheet.dev/raw/guide/api.md)

Next: [Diagnostics](https://readerly.loadsheet.dev/raw/guide/diagnostics.md)

All pages: [llms.txt](https://readerly.loadsheet.dev/llms.txt)
