1'use strict'; 2 3let internalTTy; 4function lazyInternalTTY() { 5 internalTTy ??= require('internal/tty'); 6 return internalTTy; 7} 8 9module.exports = { 10 blue: '', 11 green: '', 12 white: '', 13 red: '', 14 gray: '', 15 clear: '', 16 hasColors: false, 17 shouldColorize(stream) { 18 if (process.env.FORCE_COLOR !== undefined) { 19 return lazyInternalTTY().getColorDepth() > 2; 20 } 21 return stream?.isTTY && ( 22 typeof stream.getColorDepth === 'function' ? 23 stream.getColorDepth() > 2 : true); 24 }, 25 refresh() { 26 if (process.stderr.isTTY) { 27 const hasColors = module.exports.shouldColorize(process.stderr); 28 module.exports.blue = hasColors ? '\u001b[34m' : ''; 29 module.exports.green = hasColors ? '\u001b[32m' : ''; 30 module.exports.white = hasColors ? '\u001b[39m' : ''; 31 module.exports.yellow = hasColors ? '\u001b[33m' : ''; 32 module.exports.red = hasColors ? '\u001b[31m' : ''; 33 module.exports.gray = hasColors ? '\u001b[90m' : ''; 34 module.exports.clear = hasColors ? '\u001bc' : ''; 35 module.exports.hasColors = hasColors; 36 } 37 }, 38}; 39 40module.exports.refresh(); 41