Skip to content

TERM=dumb is ignored when COLORTERM is set #49

Description

@TomerAberbach

Ansis checks COLORTERM before TERM=dumb, so a dumb terminal that inherited COLORTERM=truecolor from its parent gets truecolor output.

Current Behavior

With TERM=dumb and COLORTERM=truecolor on a TTY, ansis.level is 3. The COLORTERM lookup at color-support.js:46-54 returns before the TERM=dumb check at line 74. The README documents this order, but it emits escape sequences into a terminal that reports it cannot render them.

This happens in Emacs: M-x shell and M-x compile set TERM=dumb (comint-terminfo-terminal), and Emacs launched from a terminal that sets COLORTERM=truecolor inherits it. Node's tty.WriteStream#getColorDepth and supports-color report no color in this environment.

Expected Behavior

ansis.level is 0 when TERM=dumb, regardless of COLORTERM.

Reproduction

npm i ansis@4.3.1
cat > repro.mjs <<'JS'
import ansis from 'ansis'
console.log(process.stdout.isTTY, ansis.level, JSON.stringify(ansis.red('x')))
JS
# `script` allocates a pty so stdout.isTTY is true
TERM=dumb COLORTERM=truecolor script -q /dev/null node repro.mjs

Output:

true 3 "\u001b[31mx\u001b[39m"

Unsetting COLORTERM produces true 0 "x".

Environment

  • OS: macOS 14.6.1
  • Node.js: v26.7.0
  • Package version: 4.3.1

Additional Context

Testing term === 'dumb' before the COLORTERM lookup, with !isTTY() left where it is, keeps COLORTERM working for non-TTY output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions