Permalink
Browse files

Default to ascii bar-chars when running under Ruby 1.8.

  • Loading branch information...
1 parent 641153a commit fa36b82a4ea1f5959333c07b27af254e74c71fbf @m-o-e m-o-e committed Oct 11, 2012
Showing with 11 additions and 10 deletions.
  1. +6 −6 bin/powerbar-demo
  2. +5 −4 lib/powerbar.rb
View
@@ -76,8 +76,8 @@ def demo_4
p.settings.tty.finite.template.main = \
"${<msg>} ${<bar> }\e[0m${<rate>/s} \e[33;1m${<percent>%} " +
"\e[36;1m${<elapsed>}\e[31;1m${ ETA: <eta>}"
- p.settings.tty.finite.template.padchar = "\e[30;1m\u2589"
- p.settings.tty.finite.template.barchar = "\e[34;1m\u2589"
+ p.settings.tty.finite.template.padchar = "\e[30;1m#{p.settings.tty.finite.template.padchar}"
+ p.settings.tty.finite.template.barchar = "\e[34;1m#{p.settings.tty.finite.template.barchar}"
p.settings.tty.finite.template.exit = "\e[?25h\e[0m" # clean up after us
p.settings.tty.finite.template.close = "\e[?25h\e[0m\n" # clean up after us
p.settings.tty.finite.output = Proc.new{ |s|
@@ -209,8 +209,8 @@ def demo_10
step = 1000
text = " " * 30 + "DEMO 10 - OMGWTFBBQ!"
p = PowerBar.new
- p.settings.tty.finite.template.padchar = "\e[30;1m\u2589"
- p.settings.tty.finite.template.barchar = "\e[34;1m\u2589"
+ p.settings.tty.finite.template.padchar = "\e[30;1m#{p.settings.tty.finite.template.padchar}"
+ p.settings.tty.finite.template.barchar = "\e[34;1m#{p.settings.tty.finite.template.barchar}"
p.settings.tty.finite.output = Proc.new{ |s| $stderr.print s }
j = 0
total = 300000000
@@ -232,8 +232,8 @@ def demo_10
:tty => {
:finite => {
:template => {
- :barchar => "\e[36;1m" + spin[j%spin.length],
- :padchar => "\e[0;34m" + spun[j%spun.length],
+ :barchar => "\e[36;1m#{spin[j%spin.length..j%spin.length]}",
+ :padchar => "\e[0;34m#{spun[j%spun.length..j%spun.length]}",
:main => "\e[#{rand(1)};3#{rand(7)}m${<msg>}\e[0m "+
"\e[0m${<bar> }\e[0m${<rate>/s} "+
"\e[33;1m${<percent>%} " +
View
@@ -29,6 +29,7 @@
#
class PowerBar
STRIP_ANSI = Regexp.compile '\e\[(\d+)(;\d+)?(;\d+)?[m|K]', nil
+ RUBY18 = RUBY_VERSION[0..2] == "1.8"
def initialize(opts={})
@@exit_hooked = false
@@ -71,8 +72,8 @@ def initialize(opts={})
:wipe => "\e[0m\e[1000D\e[K", # printed when 'wipe' is called
:close => "\e[?25h\n", # printed when 'close' is called
:exit => "\e[?25h", # printed if the process exits unexpectedly
- :barchar => "\u2588", # fill-char for the progress-bar
- :padchar => "\u2022" # padding-char for the progress-bar
+ :barchar => RUBY18 ? '#' : "\u2588", # fill-char for the progress-bar
+ :padchar => RUBY18 ? '.' : "\u2022" # padding-char for the progress-bar
},
},
:infinite => { # <== Settings for an infinite progress "bar" (when total is :unknown)
@@ -86,8 +87,8 @@ def initialize(opts={})
:wipe => "\e[0m\e[1000D\e[K",
:close => "\e[?25h\n",
:exit => "\e[?25h",
- :barchar => "\u2588",
- :padchar => "\u2022"
+ :barchar => RUBY18 ? '#' : "\u2588",
+ :padchar => RUBY18 ? '.' : "\u2022"
},
}
},

0 comments on commit fa36b82

Please sign in to comment.