ansi.js 929 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. var colors = require('ansi-colors');
  3. var supportsColor = require('color-support');
  4. var hasColors = colorize();
  5. /* istanbul ignore next */
  6. module.exports = {
  7. red: hasColors ? colors.red : noColor,
  8. green: hasColors ? colors.green : noColor,
  9. blue: hasColors ? colors.blue : noColor,
  10. magenta: hasColors ? colors.magenta : noColor,
  11. cyan: hasColors ? colors.cyan : noColor,
  12. white: hasColors ? colors.white : noColor,
  13. gray: hasColors ? colors.gray : noColor,
  14. bgred: hasColors ? colors.bgred : noColor,
  15. bold: hasColors ? colors.bold : noColor,
  16. yellow: hasColors ? colors.yellow : noColor,
  17. };
  18. function noColor(message) {
  19. return message;
  20. }
  21. function hasFlag(flag) {
  22. return (process.argv.indexOf('--' + flag) !== -1);
  23. }
  24. function colorize() {
  25. if (hasFlag('no-color')) {
  26. return false;
  27. }
  28. /* istanbul ignore if */
  29. if (hasFlag('color')) {
  30. return true;
  31. }
  32. return supportsColor();
  33. }