ansi.js 828 B

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