Last active
December 20, 2015 09:09
-
-
Save nodegin/0f0b519c4777a34fe8e8 to your computer and use it in GitHub Desktop.
progress bar
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
| // cursor moving | |
| // http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html | |
| static void updateProgress(int currentIndex, int total) { | |
| final int width = 25; // progress bar width in chars | |
| float percentage = (float) currentIndex / (float) total; | |
| int currProgress = (int) Math.floor(percentage * width); | |
| int remainProgress = width - currProgress; | |
| String numCurr = new String(new char[currProgress]).replace("\0", "="); | |
| if (numCurr.length() > 0) | |
| numCurr = numCurr.substring(0, numCurr.length() - 1) + ">"; | |
| String numRemain = new String(new char[remainProgress]).replace("\0", " "); | |
| System.out.print("\33[2A\r[" + numCurr + numRemain + "] " + currentIndex + " of " + total + " (" + ((int) Math.floor(percentage * 100)) + "%)\n\n"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment