ansistyles.js 978 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. /*
  3. * Info: http://www.termsys.demon.co.uk/vtansi.htm#colors
  4. * Following caveats
  5. * bright - brightens the color (bold-blue is same as brigthtBlue)
  6. * dim - nothing on Mac or Linux
  7. * italic - nothing on Mac or Linux
  8. * underline - underlines string
  9. * blink - nothing on Mac or linux
  10. * inverse - background becomes foreground and vice versa
  11. *
  12. * In summary, the only styles that work are:
  13. * - bright, underline and inverse
  14. * - the others are only included for completeness
  15. */
  16. var styleNums = {
  17. reset : [0, 22]
  18. , bright : [1, 22]
  19. , dim : [2, 22]
  20. , italic : [3, 23]
  21. , underline : [4, 24]
  22. , blink : [5, 25]
  23. , inverse : [7, 27]
  24. }
  25. , styles = {}
  26. ;
  27. Object.keys(styleNums).forEach(function (k) {
  28. styles[k] = function (s) {
  29. var open = styleNums[k][0]
  30. , close = styleNums[k][1];
  31. return '\u001b[' + open + 'm' + s + '\u001b[' + close + 'm';
  32. };
  33. });
  34. module.exports = styles;