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
tsasync function getColorEnabledAsync(): Promise<boolean>
Returns: Promise<boolean>
Diagram
mermaidgraph LR A[Caller] --> B[getColorEnabledAsync] B --> C{NO_COLOR set?} C -->|Yes| D[Return false] C -->|No| E[Return color-enabled status]
Usage
tsimport { getColorEnabledAsync } from './utils/color';
const colorEnabled = await getColorEnabledAsync();
if (colorEnabled) {
console.log('\u001b[32mSuccess\u001b[0m');
} else {
console.log('Success');
}
AI Coding Instructions
- Always
awaitgetColorEnabledAsyncbefore deciding whether to write terminal color escape sequences. - Respect a
falseresult and emit plain text when color changes are disabled. - Do not override the
NO_COLORenvironment 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)
logger—src/middleware/logger/index.ts:81
Was this page helpful?