- Percent preloader
- Colors in console
Last active
February 28, 2018 07:09
-
-
Save sixertoy/f26c7177e84bbef9308c96da54325f66 to your computer and use it in GitHub Desktop.
JS Console Utils
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
const colorize = (msg, col) => { | |
// `$ echo -e "\033[1mThis is a BOLD line\033[0m"` | |
const getcolor = (msg, code) => `\x1b[${code}m${msg}\x1b[39m`; | |
switch (col) { | |
case 'bold': | |
return `\u001b[0;1m${msg}\u001b[0;0m`; | |
case 'white': | |
return getcolor(msg, 37); | |
case 'cyan': | |
return getcolor(msg, 36); | |
case 'magenta': | |
return getcolor(msg, 35); | |
case 'blue': | |
return getcolor(msg, 34); | |
case 'yellow': | |
return getcolor(msg, 33); | |
case 'green': | |
return getcolor(msg, 32); | |
case 'red': | |
return getcolor(msg, 31); | |
case 'black': | |
return getcolor(msg, 30); | |
case 'grey': | |
case 'gray': | |
default: | |
return getcolor(msg, 90); | |
return; | |
} | |
} |
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
const preloader = (count, total) => { | |
const percent = (total > 0) | |
? Math.round(((count * 100) / total) * 10) / 10 | |
: 0; | |
process.stdout.write(`\r> loading... ${percent}%`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment