Skip to content

Where did my colored output go?

Qix edited this page Jul 6, 2021 · 2 revisions

If you've been linked here, you're probably wondering why your Chalk output is missing color or other formatting. Please understand that we get this question a lot - there is no bug, nor is there anything we can do, and explaining this takes a lot of our time.

Chalk uses what are called "escape sequences" or "escape codes" to tell supporting terminals how to style/format program output. Any program can output a stream of text to be displayed, but escape codes enable additional colors and formatting styles (bold, italic, underline, etc.).

Chalk uses "standard" escape sequences and API calls to do what it does. There is nothing 'magical' or unique about how Chalk outputs color. In MOST cases, "bugs" reported to us are cases of user-error.

Not all terminals support these sequences, and many terminal emulators that do support them often omit certain styles or behave much differently than other terminal emulators might.

Further, escape sequences are not magic. They are simply specific bytes that hold special meaning to terminal emulators, interleaved with normal program output. This causes problems when programs are piped into one another since those escape sequences are sometimes considered as 'normal' input, causing a variety of problems - the best case being the piped program refusing the input altogether.

Thus, most programs (in most programming languages, on most platforms, using most terminal output libraries, in most cases - not just Chalk) tend to check whether or not the target of the colorful output is a TTY - in which case, it is a safe assumption that a user is interactively running the program.

If it is not a TTY, then we choose not to output escape sequences, since it is a pretty safe assumption that the output of the program is being piped into another program as input where escape sequences might cause problems.

Some cases where your program's output might be piped to another program (and thus cause Chalk not to show colors):

  • Your program is running as a background process
  • It's running in a Docker container (including those created by Kubernetes)
  • It's running in PM2
  • It's running within a systemd unit (e.g. a service or timer)
  • It's being monitored by some logging/error detection system
  • It's running within GNU Screen (though this is unlikely as Screen tends to emulate a TTY)
  • It's running within a CI system (though we support many CI services)
  • It's running inside of a shell script
  • It's running on an old version of Windows
  • Your terminal emulator doesn't support color codes
  • About 1000 other potential causes.

Chalk uses a library called supports-color to perform this check, which uses Node's built-in isatty() functionality to determine if either stdout or stderr are TTYs, depending on which stream you're using Chalk with.

Based on the result of supports-color, Chalk will determine whether or not escape sequences should be ommitted from output.


So, where did your colors go? They probably aren't being displayed to begin with!

If you're in a situation where you know colors can be safely displayed, we provide a variety of ways to override supports-color's result. All of this information, and more, is available in the Chalk README :)

Clone this wiki locally