Skip to content

Instantly share code, notes, and snippets.

@tiegz
Created June 1, 2011 21:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiegz/1003393 to your computer and use it in GitHub Desktop.
Save tiegz/1003393 to your computer and use it in GitHub Desktop.
A ruby helper for printing out ongoing progess (for shell).
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; }
@iamjwc
Copy link

iamjwc commented Jun 2, 2011

awesome!

@tiegz
Copy link
Author

tiegz commented Jun 2, 2011

thinking about cleaning it up and maybe doing a C extension for this? Kinda useful for migrations so far :)

@iamjwc
Copy link

iamjwc commented Jun 2, 2011

leave it in ruby!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment