const noop = (str) => str;
const color = (colorFn) => process.stdout.isTTY ? colorFn : noop;
const red = color(colors.red);
console.log(red("This should be red only if it's an interactive shell"));
Most CLI developers end up writing boilerplate like this to conditionally disable colors in non-interactive environments (e.g., when output is redirected). It would be extremely helpful to have a built-in option or global toggle that makes all color functions no-ops automatically when needed.
This would simplify codebases and eliminate the need to wrap every color usage manually.
Most CLI developers end up writing boilerplate like this to conditionally disable colors in non-interactive environments (e.g., when output is redirected). It would be extremely helpful to have a built-in option or global toggle that makes all color functions no-ops automatically when needed.
This would simplify codebases and eliminate the need to wrap every color usage manually.