Node: Feature request - add terminal colors to core

Created on 13 Jul 2018  路  3Comments  路  Source: nodejs/node

I have some scripts for which installing dependencies / node_modules would be overkill, but I still could use some colors for the terminal. Right now, I think in userland it's standard to install colors/chalk in node_modules but I am wondering if there is a way to do so with just Node.js core?

Seems like it would be handy for scripts and wouldn't add too much to core? dunno

feature request

Most helpful comment

i don't think core needs to expose this, it's quite simple to do even without a library:

const colors = {
  'bold': [1, 22],
  'italic': [3, 23],
  'underline': [4, 24],
  'inverse': [7, 27],
  'white': [37, 39],
  'grey': [90, 39],
  'black': [30, 39],
  'blue': [34, 39],
  'cyan': [36, 39],
  'green': [32, 39],
  'magenta': [35, 39],
  'red': [31, 39],
  'yellow': [33, 39]
};

function stylize(color, str) {
  const [start, end] = colors[color];
  return `\u001b[${start}m${str}\u001b[${end}m`;
}

All 3 comments

i don't think core needs to expose this, it's quite simple to do even without a library:

const colors = {
  'bold': [1, 22],
  'italic': [3, 23],
  'underline': [4, 24],
  'inverse': [7, 27],
  'white': [37, 39],
  'grey': [90, 39],
  'black': [30, 39],
  'blue': [34, 39],
  'cyan': [36, 39],
  'green': [32, 39],
  'magenta': [35, 39],
  'red': [31, 39],
  'yellow': [33, 39]
};

function stylize(color, str) {
  const [start, end] = colors[color];
  return `\u001b[${start}m${str}\u001b[${end}m`;
}

I agree, this isn't something that needs to explicitly live in or be exposed in core.

Closing this, as @devsnek pointed out a solution that doesn't involve adding things to core any more than what's absolutely necessary. Also, popular solutions exist in the userland. Feel free to reopen this if you feel otherwise.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jmichae3 picture jmichae3  路  3Comments

sandeepks1 picture sandeepks1  路  3Comments

Brekmister picture Brekmister  路  3Comments

srl295 picture srl295  路  3Comments

willnwhite picture willnwhite  路  3Comments