Terminal colors in Nodejs without extra dependencies
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
const util = require('util'); | |
const colorize = (str, colorCodes) => `\x1b[${colorCodes[0]}m${str}\x1b[${colorCodes[1]}m`; | |
const bold = str => colorize(str, util.inspect.colors.bold); | |
const italic = str => colorize(str, util.inspect.colors.italic); | |
const underline = str => colorize(str, util.inspect.colors.underline); | |
const inverse = str => colorize(str, util.inspect.colors.inverse); | |
const white = str => colorize(str, util.inspect.colors.white); | |
const grey = str => colorize(str, util.inspect.colors.grey); | |
const black = str => colorize(str, util.inspect.colors.black); | |
const blue = str => colorize(str, util.inspect.colors.blue); | |
const cyan = str => colorize(str, util.inspect.colors.cyan); | |
const green = str => colorize(str, util.inspect.colors.green); | |
const magenta = str => colorize(str, util.inspect.colors.magenta); | |
const red = str => colorize(str, util.inspect.colors.red); | |
const yellow = str => colorize(str, util.inspect.colors.yellow); | |
console.log(grey('Woow,'), cyan('This'), blue('is'), green('a'), magenta('colorful'), red('text'), yellow('!')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment