Created
June 1, 2011 21:39
-
-
Save tiegz/1003393 to your computer and use it in GitHub Desktop.
A ruby helper for printing out ongoing progess (for shell).
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
module Kernel | |
# Prints out progress | |
@@printp_spinner = %w(⇐ ⇖ ⇑ ⇗ ⇒ ⇘ ⇓ ⇙) | |
@@printp_spinnerpos = 0 | |
@@printp_cols = [`tput cols`.to_i - 20, 50].max | |
def printp(symbol, i) | |
print @@printp_spinnerpos % @@printp_cols == 0 ? "\n" : ("\b" * (16 + symbol.size)) | |
print "#{symbol}#{" %3d%" % i} complete #{@@printp_spinner[(@@printp_spinnerpos+=1) % 8]} " | |
STDOUT.flush | |
end | |
end | |
(1..100).to_a.each { |i| printp(".", i); sleep 0.1; } |
thinking about cleaning it up and maybe doing a C extension for this? Kinda useful for migrations so far :)
leave it in ruby!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
awesome!