Last active
January 6, 2024 18:35
-
-
Save laocoi/0dd2e5ca1af0558b685ffefacafee126 to your computer and use it in GitHub Desktop.
Simple Javascript function to colorize your command-line
This file contains hidden or 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
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