Created
September 29, 2021 09:37
-
-
Save mCzolko/5bdc29a1e285ef3c38e6b8ceb3aeedcf to your computer and use it in GitHub Desktop.
Simple progress bar in TS
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
export default (prc: number) => { | |
const cols = process.stdout.columns - 7 | |
const oneBar = cols / 100 | |
let i = 0 | |
let progressBar = '[' | |
const prcCrc = prc * oneBar | |
while (true) { | |
if (i === cols) { | |
break | |
} | |
if (i <= prcCrc) { | |
progressBar += '=' | |
} else { | |
progressBar += '-' | |
} | |
i++ | |
} | |
progressBar = progressBar + `] ${(' ' + prc).slice(-3)}%` | |
return progressBar | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment