node.js - What is this \u001b[9... syntax of choosing what color text appears on console, and how can I add more colors? -
i messing around debug , colors.js more colors limited 4-6 colors i'm stuck @ figuring out coloring syntax
args[0] = ' \u001b[9' + c + 'm' + name + ' ' + '\u001b[3' + c + 'm\u001b[90m' + args[0] + '\u001b[3' + c + 'm' + ' +' + exports.humanize(ms) + '\u001b[0m';
'blue' : ['\x1b[34m', '\x1b[39m'], 'cyan' : ['\x1b[36m', '\x1b[39m'], 'green' : ['\x1b[32m', '\x1b[39m'], 'magenta' : ['\x1b[35m', '\x1b[39m'], 'red' : ['\x1b[31m', '\x1b[39m'], 'yellow' : ['\x1b[33m', '\x1b[39m'],
i know windows console allows more colors six, color /?
shows
0 = black 8 = gray 1 = blue 9 = light blue 2 = green = light green 3 = aqua b = light aqua 4 = red c = light red 5 = purple d = light purple 6 = yellow e = light yellow 7 = white f = bright white
how go understanding syntax , adding colors windows has offer?
those ansi terminal escape codes. specifically, they're "select graphic rendition" (sgr) escape codes, consist of:
- the "command sequence introducer", consisting of characters
\x1b
(esc) ,[
, - one or more numeric commands, separated semicolons, and
- the letter
m
, ending code , indicating sgr code.
there many possible numeric commands (and many other escape codes besides sgr), relevant ones are:
- 30–37: set text color 1 of colors 0 7,
- 40–47: set background color 1 of colors 0 7,
- 39: reset text color default,
- 49: reset background color default,
- 1: make text bold / bright (this standard way access bright color variants),
- 22: turn off bold / bright effect, and
- 0: reset text properties (color, background, brightness, etc.) default values.
thus, example, 1 select bright purple text on green background (eww!) code \x1b[35;1;42m
.
Comments
Post a Comment