Skip to content
Browse files

adds subject

  • Loading branch information...
1 parent fc3faa8 commit 1829ad562da067147d89582095634f41724d0be2 @nofxx committed Dec 20, 2008
Showing with 55 additions and 38 deletions.
  1. +18 −20 README.rdoc
  2. +2 −4 Rakefile
  3. +2 −2 lib/rtui.rb
  4. +14 −2 lib/rtui/progress.rb
  5. +7 −7 rtui.gemspec
  6. +11 −2 spec/rtui/progress_spec.rb
  7. +1 −1 spec/spec.opts
View
38 README.rdoc
@@ -1,53 +1,47 @@
-= Rtui
+ ______ _______ _______ _______
+ | __ \_ _| | |_ _|
+ | < | | | | |_| |_
+ |___|__| |___| |_______|_______|
-This gem goal is to provide TUI eye candy for ruby. Think HighLine extras...
+This gem goal is to provide TUI eye candy for ruby.
For now, we got:
-From Ruby/ProgressBar by Satoru Takabayashi
+* 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 api and adds some methods.
-This fork changes the initializer to be a lil more rails like and add the spinner and pong formatters.
== Examples
pbar = Rtui::Progress.new("test", 100)
100.times {sleep(0.1); pbar.inc}; pbar.finish
- test: 100% |========================================| Time: 00:00:10
+ test: 100% |===============================================| Time: 00:00:10
pbar = Rtui::Progress.new("test", 100, :components => [:bar, :percentage])
100.times {sleep(0.1); pbar.inc}; pbar.finish
- |======================================================================| 100%
+ |====================================================================| 100%
- 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, :subject, :percentage])
+ 100.times { |i| sleep(0.1); pbar.subject = "Iteration #{i}.."; pbar.inc}; pbar.finish
-
- pbar = Progress.new("test", 100, :components => [:spinner, :percentage])
- 100.times {sleep(0.1); pbar.inc}; pbar.finish
-
- \ 100%
+ \ Iteration 68 68%
pbar = Progress.new("foo", 100, :bar => "o", :components => [:pong, :percentage])
(1..100).each{|x| sleep(0.1); pbar.set(x)}; pbar.finish
- | o | 67%
+ | o | 67%
== Install
-Ruby/ProgressBar is a free software with ABSOLUTELY NO WARRANTY
-under the terms of Ruby's license.
-
sudo gem sources --add http://gems.github.com
sudo gem install nofxx-rtui
@@ -70,6 +64,7 @@ under the terms of Ruby's license.
:title,
:bar,
:spinner,
+ :subject,
:pong,
:percentage,
:stat
@@ -89,6 +84,9 @@ under the terms of Ruby's license.
((|count|)) is a negative number or a number more than
the ((|total|)).
+=== Progress#subject (subject)
+ Set the bar current subject.
+
=== Progress#finish
Stop the progress bar and update the display of progress
bar. Display the elapsed time on the right side of the bar.
@@ -139,4 +137,4 @@ accurately performed if the progress does not flow uniformly.
All rights reserved.
This is free software with ABSOLUTELY NO WARRANTY.
-You can redistribute it and/or modify it under the terms of Ruby's license.
+You can redistribute it and/or modify it under the terms of Ruby's license.
View
6 Rakefile
@@ -6,12 +6,10 @@ require File.dirname(__FILE__) + '/lib/rtui'
$hoe = Hoe.new('rtui', Rtui::VERSION) do |p|
p.developer('Marcos Piccinini', 'x@nofxx.com')
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
- # p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
p.rubyforge_name = p.name # TODO this is default value
p.summary = "Ruby TUI Helpers"
- # p.extra_deps = [
- # ['activesupport','>= 2.0.2'],
- # ]
+ p.description = "Set of tools for TUI Eye Candy"
+ p.url = "http://github.com/nofxx/rtui"
p.extra_dev_deps = [
['newgem', ">= #{::Newgem::VERSION}"]
]
View
4 lib/rtui.rb
@@ -5,5 +5,5 @@
module Rtui
- VERSION = '0.0.3'
-end
+ VERSION = '0.1.1'
+end
View
16 lib/rtui/progress.rb
@@ -63,6 +63,7 @@ def initialize (title, total, *options)
@start_time = Time.now
@previous_time = @start_time
@title_width = 14
+ @subject = ""
@out = options[:out] || STDERR
@bar_mark = options[:bar] || "="
@@ -100,6 +101,10 @@ def components= (arguments)
@components = arguments
end
+ def subject=(subject)
+ @subject = subject
+ end
+
def halt
@finished = true
show
@@ -128,7 +133,10 @@ def inspect
private
-
+ def fmt_subject
+ " " + @subject + ( " " * (@terminal_width - @subject.length))
+ end
+
def fmt_bar
bar_width = do_percentage * @terminal_width / 100
sprintf("|%s%s|",
@@ -221,6 +229,10 @@ def do_percentage
def get_width
# FIXME: I don't know how portable it is.
+ #
+ # Works linux...
+ # Fails OSX
+ #
default_width = 80
begin
tiocgwinsz = 0x5413
@@ -282,4 +294,4 @@ def do_percentage
end
-end
+end
View
14 rtui.gemspec
@@ -2,17 +2,17 @@
Gem::Specification.new do |s|
s.name = %q{rtui}
- s.version = "0.0.3"
+ s.version = "0.1.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Marcos Piccinini"]
- s.date = %q{2008-12-13}
- s.description = %q{Ruby TUI Helpers}
+ s.date = %q{2008-12-20}
+ s.description = %q{Set of tools for TUI Eye Candy}
s.email = ["x@nofxx.com"]
s.extra_rdoc_files = ["History.txt", "LICENSE.txt", "Manifest.txt", "README.rdoc"]
s.files = ["History.txt", "LICENSE.txt", "Manifest.txt", "README.rdoc", "Rakefile", "lib/rtui.rb", "lib/rtui/progress.rb", "rspec.rake", "rtui.gemspec", "script/console", "script/destroy", "script/generate", "spec/rtui/progress_spec.rb", "spec/rtui_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake"]
s.has_rdoc = true
- s.homepage = %q{From Ruby/ProgressBar: A Text Progress Bar Library for Ruby}
+ s.homepage = %q{http://github.com/nofxx/rtui}
s.rdoc_options = ["--main", "README.rdoc"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{rtui}
@@ -24,14 +24,14 @@ Gem::Specification.new do |s|
s.specification_version = 2
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- s.add_development_dependency(%q<newgem>, [">= 1.1.0"])
+ s.add_development_dependency(%q<newgem>, [">= 1.2.1"])
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
else
- s.add_dependency(%q<newgem>, [">= 1.1.0"])
+ s.add_dependency(%q<newgem>, [">= 1.2.1"])
s.add_dependency(%q<hoe>, [">= 1.8.0"])
end
else
- s.add_dependency(%q<newgem>, [">= 1.1.0"])
+ s.add_dependency(%q<newgem>, [">= 1.2.1"])
s.add_dependency(%q<hoe>, [">= 1.8.0"])
end
end
View
13 spec/rtui/progress_spec.rb
@@ -43,7 +43,7 @@ def do_make_progress_bar (title, total)
total = 100
pbar = Rtui::Progress.new("test(inc)", total,
:components => [:spinner, :percentage])
- total.times { sleep(0.05); pbar.inc }
+ total.times { sleep(0.01); pbar.inc }
pbar.finish
end
@@ -56,6 +56,15 @@ def do_make_progress_bar (title, total)
sleep(SleepUnit)
}
pbar.finish
+
+ end
+
+ it "should show a subject!" do
+ total = 100
+ pbar = Rtui::Progress.new("test(inc)", total,
+ :components => [:spinner, :percentage, :subject, :stat])
+ total.times { |i| sleep(0.1); pbar.subject = "inter #{i} times!!!"; pbar.inc }
+ pbar.finish
end
#
# it "should clear" do
@@ -142,4 +151,4 @@ def do_make_progress_bar (title, total)
# end
# end
end
-end
+end
View
2 spec/spec.opts
@@ -1,2 +1,2 @@
--colour
---format spinner
+--format progress

0 comments on commit 1829ad5

Please sign in to comment.
Something went wrong with that request. Please try again.