Created
September 6, 2013 06:54
-
-
Save kuntoaji/6460383 to your computer and use it in GitHub Desktop.
Simple progress bar script without Gem using Ruby.
This file contains 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
#!/usr/bin/env ruby | |
progress = 'Progress [' | |
1000.times do |i| | |
# i is number from 0-999 | |
j = i + 1 | |
# add 1 percent every 10 times | |
if j % 10 == 0 | |
progress << "=" | |
# move the cursor to the beginning of the line with \r | |
print "\r" | |
# puts add \n to the end of string, use print instead | |
print progress + " #{j / 10} %" | |
# force the output to appear immediately when using print | |
# by default when \n is printed to the standard output, the buffer is flushed. | |
$stdout.flush | |
sleep 0.05 | |
end | |
end | |
puts "\nDone!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anyone that tries this with a number other than 1000 I think that this might make things a little more clear: