Skip to content

Instantly share code, notes, and snippets.

@miketierney
Created December 22, 2010 21:12
Show Gist options
  • Save miketierney/752107 to your computer and use it in GitHub Desktop.
Save miketierney/752107 to your computer and use it in GitHub Desktop.
A CLI-style progress bar
# Original credit goes to Aaron Patterson (@tenderlove) for posting the following to Twitter (http://pnpnt.me/2m):
# i = 0; while i <= 15; print "[#{'=' * i}#{' ' * (15 - i)}] #{((i/15.0) * 100).round}%\r"; i += 1; sleep 0.2; end; puts
# Apparently he borrowed this from Yehuda Katz (@wycats) -- http://pnpnt.me/2n.
# And then to Magnus Holm (@judofyr) for pointing out that Range#each could work (he actually references Range#map, too, but I'm not using that here). -- http://pnpnt.me/2o
#
# TODO: Figure out a more succinct way of doing this (more Ruby-esque, less JS-esque).
(0..15).each { |i| print "[#{'=' * i}#{' ' * (15 - i)}] #{((i/15.0) * 100).round}%\r"; sleep 0.2; }; puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment