Skip to content

Instantly share code, notes, and snippets.

@laocoi
Last active January 6, 2024 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laocoi/0dd2e5ca1af0558b685ffefacafee126 to your computer and use it in GitHub Desktop.
Save laocoi/0dd2e5ca1af0558b685ffefacafee126 to your computer and use it in GitHub Desktop.
Simple Javascript function to colorize your command-line
function colorLog(text, type, getStr = false){
let str;
switch (type) {
case 'e': // error
str = '\u001b[38;2;255;0;0m'+text+'\u001b[0m'
break;
case 's': // success
str = '\u001b[38;2;0;255;0m'+text+'\u001b[0m'
break;
case 'w': // warning
str = '\u001b[38;2;255;140;0m'+text+'\u001b[0m'
break;
case 'bold':
str = '\u001b[1m'+text+'\u001b[0m'
break;
case 'underlined':
str = '\u001b[4m'+text+'\u001b[0m'
break;
default:
str = text
break;
}
return getStr ? str : console.log(str)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment