Skip to content

getColorEnabledAsync

reference
1 min readUpdated

Kind: Function

Source: src/utils/color.ts

Part of: Utils

Get whether color change on terminal is enabled or disabled. If NO_COLOR environment variable is set, this function returns false.

getColorEnabledAsync asynchronously determines whether terminal color changes are enabled. When the NO_COLOR environment variable is set, it returns false so callers can avoid emitting color formatting.

Signature

ts
async function getColorEnabledAsync(): Promise<boolean>

Returns: Promise<boolean>

Diagram

mermaid
graph LR
  A[Caller] --> B[getColorEnabledAsync]
  B --> C{NO_COLOR set?}
  C -->|Yes| D[Return false]
  C -->|No| E[Return color-enabled status]

Usage

ts
import { getColorEnabledAsync } from './utils/color';

const colorEnabled = await getColorEnabledAsync();

if (colorEnabled) {
  console.log('\u001b[32mSuccess\u001b[0m');
} else {
  console.log('Success');
}

AI Coding Instructions

  • Always await getColorEnabledAsync before deciding whether to write terminal color escape sequences.
  • Respect a false result and emit plain text when color changes are disabled.
  • Do not override the NO_COLOR environment variable behavior in calling code.
  • Keep terminal output formatting decisions close to the code that writes to the terminal.

Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (1)

  • loggersrc/middleware/logger/index.ts:81

Was this page helpful?

Download as PDF
getColorEnabledAsync — Hono (narrator proof)