Permalink
Browse files

new stuff, up version , readme...

  • Loading branch information...
1 parent a3896d5 commit fc3faa865645c502612c34cb9513642ff0a8b45d @nofxx nofxx committed Dec 13, 2008
Showing with 82 additions and 49 deletions.
  1. +35 −21 README.rdoc
  2. +1 −1 lib/rtui.rb
  3. +18 −7 lib/rtui/progress.rb
  4. +2 −2 rtui.gemspec
  5. +26 −18 spec/rtui/progress_spec.rb
View
@@ -1,34 +1,47 @@
= Rtui
+This gem goal is to provide TUI eye candy for ruby. Think HighLine extras...
+For now, we got:
-From Ruby/ProgressBar: A Text Progress Bar Library for Ruby
+From Ruby/ProgressBar by Satoru Takabayashi
Ruby/ProgressBar is a text progress bar library for Ruby.
It can indicate progress with percentage, a progress bar,
and estimated remaining time.
+This fork changes the initializer to be a lil more rails like and add the spinner and pong formatters.
+
== Examples
- % irb -r rtui
- >> pbar = Progress.new("test", 100)
- >> 100.times {sleep(0.1); pbar.inc}; pbar.finish
+ pbar = Rtui::Progress.new("test", 100)
+ 100.times {sleep(0.1); pbar.inc}; pbar.finish
+
test: 100% |========================================| Time: 00:00:10
- >> pbar = Progress.new("test", 100, :components => [:bar, :percentage])
- >> 100.times {sleep(0.1); pbar.inc}; pbar.finish
+ pbar = Rtui::Progress.new("test", 100, :components => [:bar, :percentage])
+ 100.times {sleep(0.1); pbar.inc}; pbar.finish
+
|======================================================================| 100%
- >> pbar = Progress.new("test", 100, :bar => "_")
- >> (1..100).each{|x| sleep(0.1); pbar.set(x)}; pbar.finish
+ pbar = Rtui::Progress.new("test", 100, :bar => "_")
+ (1..100).each{|x| sleep(0.1); pbar.set(x)}; pbar.finish
+
test: 67% |__________________________ | ETA: 00:00:03
- >> pbar = Progress.new("test", 100, :components => [:spinner, :percentage])
- >> 100.times {sleep(0.1); pbar.inc}; pbar.finish
- \ 100%
+ pbar = Progress.new("test", 100, :components => [:spinner, :percentage])
+ 100.times {sleep(0.1); pbar.inc}; pbar.finish
+
+ \ 100%
+
+ pbar = Progress.new("foo", 100, :bar => "o", :components => [:pong, :percentage])
+ (1..100).each{|x| sleep(0.1); pbar.set(x)}; pbar.finish
+
+ | o | 67%
+
== Install
@@ -41,11 +54,11 @@ under the terms of Ruby's license.
== API
-=== ProgressBar#new (title, total, *options)
+=== Progress#new (title, total, *options)
Display the initial progress bar and return a
ProgressBar object. ((|title|)) specifies the title,
and ((|total|)) specifies the total cost of processing.
- Optional parameter ((|out|)) specifies the output IO.
+ Options parameter ((|:out|)) specifies the output IO.
The display of the progress bar is updated when one or
more percent is proceeded or one or more seconds are
@@ -57,45 +70,46 @@ under the terms of Ruby's license.
:title,
:bar,
:spinner,
+ :pong,
:percentage,
:stat
]}
-=== ProgressBar#inc (step = 1)
+=== Progress#inc (step = 1)
Increase the internal counter by ((|step|)) and update
the display of the progress bar. Display the estimated
remaining time on the right side of the bar. The counter
does not go beyond the ((|total|)).
-=== ProgressBar#set (count)
+=== Progress#set (count)
Set the internal counter to ((|count|)) and update the
display of the progress bar. Display the estimated
remaining time on the right side of the bar. Raise if
((|count|)) is a negative number or a number more than
the ((|total|)).
-=== ProgressBar#finish
+=== Progress#finish
Stop the progress bar and update the display of progress
bar. Display the elapsed time on the right side of the bar.
The progress bar always stops at 100 % by the method.
-=== ProgressBar#halt
+=== Progress#halt
Stop the progress bar and update the display of progress
bar. Display the elapsed time on the right side of the bar.
The progress bar stops at the current percentage by the method.
-=== ProgressBar#format_arguments=
+=== Progress#format_arguments=
Set the methods for displaying a progress bar.
Default: [:title, :percentage, :bar, :stat].
-=== ProgressBar#file_transfer_mode
+=== Progress#file_transfer_mode
Use :stat_for_file_transfer instead of :stat to display
transfered bytes and transfer rate.
-ReverseProgressBar class is also available. The
-functionality is identical to ProgressBar but the direction
+ReverseProgress class is also available. The
+functionality is identical to Progress but the direction
of the progress bar is just opposite.
View
@@ -5,5 +5,5 @@
module Rtui
- VERSION = '0.0.2'
+ VERSION = '0.0.3'
end
View
@@ -1,4 +1,9 @@
#
+#
+#
+#
+# Original code:
+#
# Ruby/ProgressBar - a text progress bar library VERSION = "0.9"
#
# Copyright (C) 2001-2005 Satoru Takabayashi <satoru@namazu.org>
@@ -87,9 +92,9 @@ def file_transfer_mode
@components[@components.index(:stat)] = :stat_for_file_transfer
end
- def format= (format)
- @format = format
- end
+ # def format= (format)
+ # @format = format
+ # end
def components= (arguments)
@components = arguments
@@ -127,17 +132,23 @@ def inspect
def fmt_bar
bar_width = do_percentage * @terminal_width / 100
sprintf("|%s%s|",
- @bar_mark * bar_width,
- " " * (@terminal_width - bar_width))
+ @bar_mark * bar_width,
+ " " * (@terminal_width - bar_width))
end
def fmt_spinner
bar_width = do_percentage * @terminal_width / 100
sprintf(" %s%s ",
- do_percentage == 100 ? " " : '/-\\|'[do_percentage%4].chr ,
- " " * (@terminal_width / 100) )
+ do_percentage == 100 ? " " : '/-\\|'[do_percentage%4].chr ,
+ " " * (@terminal_width / 100) )
end
+ def fmt_pong
+ bar_width = do_percentage * @terminal_width / 100
+ sprintf("|%s%s|",
+ " " * bar_width + @bar_mark,
+ " " * (@terminal_width - bar_width))
+ end
def fmt_percentage
"%3d%%" % do_percentage
View
@@ -2,11 +2,11 @@
Gem::Specification.new do |s|
s.name = %q{rtui}
- s.version = "0.0.2"
+ s.version = "0.0.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Marcos Piccinini"]
- s.date = %q{2008-12-11}
+ s.date = %q{2008-12-13}
s.description = %q{Ruby TUI Helpers}
s.email = ["x@nofxx.com"]
s.extra_rdoc_files = ["History.txt", "LICENSE.txt", "Manifest.txt", "README.rdoc"]
View
@@ -1,44 +1,52 @@
require File.dirname(__FILE__) + '/../spec_helper.rb'
describe "Progress Bar" do
-
- describe "Visual tests =D" do
-
+
+
+ #
+ # Ok. Need real tests.
+ # But this REALLY works =D
+ #
+ describe "Visual tests" do
SleepUnit = 0.01
def do_make_progress_bar (title, total)
Rtui::Progress.new(title, total)
end
+ it "should pong" do
+ total = 100
+ pbar = Rtui::Progress.new("test(inc)", total, :bar => "o",
+ :components => [:pong, :percentage])
+ total.times { sleep(0.01); pbar.inc }
+ pbar.finish
+ end
+
it "should spin!" do
-
total = 100
pbar = Rtui::Progress.new("test(inc)", total,
:components => [:spinner, :percentage, :stat])
- total.times {
- sleep(0.01)
- pbar.inc
- }
- pbar.finish
-
+ total.times { sleep(0.01); pbar.inc }
+ pbar.finish
end
-
it "different bar" do
-
total = 100
pbar = Rtui::Progress.new("test(inc)", total, :bar => "_",
:components => [ :stat, :bar, :percentage])
- total.times {
- sleep(SleepUnit)
- pbar.inc
- }
+ total.times { sleep(SleepUnit); pbar.inc }
pbar.finish
-
-
end
+ it "should spin 2!" do
+ total = 100
+ pbar = Rtui::Progress.new("test(inc)", total,
+ :components => [:spinner, :percentage])
+ total.times { sleep(0.05); pbar.inc }
+ pbar.finish
+ end
+
it "should handle bytes" do
total = 1024 * 1024
pbar = do_make_progress_bar("test(bytes)", total)

0 comments on commit fc3faa8

Please sign in to comment.