Last active
July 1, 2021 07:34
-
-
Save enten/cef219142ca6350cdd07ef6b58eb7636 to your computer and use it in GitHub Desktop.
Node JS ANSI Styles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = [] | |
.concat([ | |
'reset', | |
'bold', | |
'dim', | |
'italic', | |
'underline', | |
'blink', | |
, | |
'inverse', | |
'hidden', | |
'strikethrough' | |
].reduce((acc, modifier, index) => { | |
acc.push([modifier, [ | |
index, | |
22 + (index > 2 ? index - 2 : 0) | |
]]) | |
return acc | |
}, [])) | |
.concat([ | |
'black', | |
'red', | |
'green', | |
'yellow', | |
'blue', | |
'magenta', | |
'cyan', | |
'white' | |
].reduce((acc, color, index) => { | |
const colorUpper = color[0].toUpperCase() + color.substring(1) | |
;[ | |
30, | |
40 | |
].forEach((code, i) => { | |
const name = ['', 'bg'][i] + (i ? colorUpper : color) | |
const open = code + index | |
const close = code + 9 | |
acc.push( | |
[name, [open, close]], | |
[name + 'Bright', [open + 60, close]] | |
) | |
}) | |
return acc | |
}, [])) | |
// .map(([name, codes]) => [name, codes.map((x) => `\u001b[${x}m`)]) |
Author
enten
commented
Aug 1, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment