nofxx-rtui 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,118 @@
1
+ 2008-12-11
2
+
3
+ * Forked
4
+
5
+
6
+ 2005-05-21 Satoru Takabayashi <satoru@namazu.org>
7
+
8
+ * progressbar.rb (ProgressBar::show): Call IO#flush. Suggestted by
9
+ "Geert Fannes" <Geert.Fannes at ikanconsulting.com>
10
+
11
+ 2005-01-07 Satoru Takabayashi <satoru@namazu.org>
12
+
13
+ * progressbar.rb (ProgressBar::VERSION): Bumped version number to 0.9.
14
+ (ProgressBar::finished?): New method.
15
+ (ProgressBar::current): New attribute.
16
+ (ProgressBar::total): New attribute.
17
+ (ProgressBar::title): New attribute.
18
+ (ProgressBar::start_time): New attribute.
19
+ (ProgressBar::inspect): Change the format.
20
+ (ProgressBar::show_if_needed): Renamed from show_progress.
21
+ (ProgressBar::clear): New method.
22
+ (ProgressBar::initialize): Renamed a field: bar_width ->
23
+ terminal_width.
24
+ (ProgressBar::do_percentage): New method.
25
+ (ProgressBar::percentage): Use it.
26
+ (ReversedProgressBar): New class.
27
+ (ProgressBar::initialize): Use #clear.
28
+ (ProgressBar::fmt_bar): Ditto.
29
+ (ProgressBar::fmt_percentage): Renamed from percentage.
30
+ (ProgressBar::fmt_stat): Ditto.
31
+ (ProgressBar::fmt_stat_for_file_transfer): Ditto.
32
+ (ProgressBar::fmt_title): Ditto.
33
+
34
+ * test.rb: Use Test::Unit.
35
+
36
+ * Makefile (docs): Removed.
37
+ (progressbar.ja.html): Ditto.
38
+ (progressbar.en.html): Ditto.
39
+ (dist): New rule.
40
+ (check): New rule.
41
+
42
+ 2004-02-05 Satoru Takabayashi <satoru@namazu.org>
43
+
44
+ * Ruby/ProgressBar: Version 0.8 released!
45
+
46
+ * progressbar.rb (ProgressBar::set): Fixed the bug when caused by
47
+ the invalid count. <http://bugs.debian.org/231009>
48
+ (ProgressBar::VERSION): Bumped version number to 0.8.
49
+
50
+ 2004-01-19 Satoru Takabayashi <satoru@namazu.org>
51
+
52
+ * Ruby/ProgressBar: Version 0.7 released!
53
+
54
+ * progressbar.rb (ProgressBar::initialize): Rename a field:
55
+ @bar_length -> @bar_width.
56
+ (ProgressBar::initialize): New field: @title_width.
57
+ (ProgressBar::title): use it.
58
+ (ProgressBar::initialize): New field: @previous_time.
59
+ (ProgressBar::show_progress): Use it and update the progress bar
60
+ if one sec. elapsed.
61
+ (ProgressBar::initialize): Call show instead of show_progress.
62
+
63
+ 2004-01-16 Satoru Takabayashi <satoru@namazu.org>
64
+
65
+ * Ruby/ProgressBar: Version 0.6 released!
66
+
67
+ * progressbar.rb (ProgressBar::show): Remove the useless condition
68
+ after "else". Thanks to Neil Spring <nspring@cs.washington.edu>
69
+ for the report.
70
+ <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=227966>
71
+ (ProgressBar):
72
+
73
+ 2003-07-24 Satoru Takabayashi <satoru@namazu.org>
74
+
75
+ * Ruby/ProgressBar: Version 0.5 released!
76
+
77
+ * progressbar.rb (ProgressBar::initialize): New parameter: config.
78
+ (ProgressBar::convert_prefix_multiplier): New method.
79
+ (ProgressBar::transfer_rate): New method.
80
+ (ProgressBar::percentage): New method.
81
+ (ProgressBar::title): New method.
82
+ (ProgressBar::initialize): New fields: @bar_mark, @format,
83
+ @arguments.
84
+ (ProgressBar::get_width): New method.
85
+ (ProgressBar::stat_for_file_transfer): New method.
86
+ (ProgressBar::stat): Renamed from time.
87
+ (ProgressBar::format=): New method.
88
+ (ProgressBar::format_arguments=): New method.
89
+ (ProgressBar::convert_bytes): New method.
90
+ (ProgressBar::file_transfer_mode): New method.
91
+
92
+ 2002-10-21 Satoru Takabayashi <satoru@namazu.org>
93
+
94
+ * Ruby/ProgressBar: Version 0.4 released!
95
+
96
+ * progressbar.rb (ProgressBar::halt): New method. allowing a
97
+ "broken" ProgressBar in the event of error.
98
+ - Suggestted by Austin Ziegler <austin@halostatue.ca>
99
+
100
+ 2002-01-05 Satoru Takabayashi <satoru@namazu.org>
101
+
102
+ * Ruby/ProgressBar: Version 0.3 released!
103
+
104
+ * progressbar.rb (ProgressBar::show): Shorten @title to fall into
105
+ the format well.
106
+
107
+ 2001-11-03 Satoru Takabayashi <satoru@namazu.org>
108
+
109
+ * Ruby/ProgressBar: Version 0.2 released!
110
+
111
+ * progressbar.rb (ProgressBar::eta): Remove an unnecessary condition.
112
+
113
+ * progressbar.rb (ProgressBar::eta): Fix the return value bug.
114
+
115
+ * progressbar.rb (ProgressBar::inc): Add an optional parameter `step'.
116
+
117
+ * Ruby/ProgressBar: Version 0.1 released!
118
+
data/LICENSE.txt ADDED
@@ -0,0 +1,59 @@
1
+ http://www.ruby-lang.org/en/LICENSE.txt
2
+
3
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.co.jp>.
4
+ You can redistribute it and/or modify it under either the terms of the GPL
5
+ (see COPYING.txt file), or the conditions below:
6
+
7
+ 1. You may make and give away verbatim copies of the source form of the
8
+ software without restriction, provided that you duplicate all of the
9
+ original copyright notices and associated disclaimers.
10
+
11
+ 2. You may modify your copy of the software in any way, provided that
12
+ you do at least ONE of the following:
13
+
14
+ a) place your modifications in the Public Domain or otherwise
15
+ make them Freely Available, such as by posting said
16
+ modifications to Usenet or an equivalent medium, or by allowing
17
+ the author to include your modifications in the software.
18
+
19
+ b) use the modified software only within your corporation or
20
+ organization.
21
+
22
+ c) rename any non-standard executables so the names do not conflict
23
+ with standard executables, which must also be provided.
24
+
25
+ d) make other distribution arrangements with the author.
26
+
27
+ 3. You may distribute the software in object code or executable
28
+ form, provided that you do at least ONE of the following:
29
+
30
+ a) distribute the executables and library files of the software,
31
+ together with instructions (in the manual page or equivalent)
32
+ on where to get the original distribution.
33
+
34
+ b) accompany the distribution with the machine-readable source of
35
+ the software.
36
+
37
+ c) give non-standard executables non-standard names, with
38
+ instructions on where to get the original software distribution.
39
+
40
+ d) make other distribution arrangements with the author.
41
+
42
+ 4. You may modify and include the part of the software into any other
43
+ software (possibly commercial). But some files in the distribution
44
+ are not written by the author, so that they are not under this terms.
45
+
46
+ They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
47
+ files under the ./missing directory. See each file for the copying
48
+ condition.
49
+
50
+ 5. The scripts and library files supplied as input to or produced as
51
+ output from the software do not automatically fall under the
52
+ copyright of the software, but belong to whomever generated them,
53
+ and may be sold commercially, and may be aggregated with this
54
+ software.
55
+
56
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
57
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
58
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59
+ PURPOSE.
data/Manifest.txt ADDED
@@ -0,0 +1,17 @@
1
+ History.txt
2
+ LICENSE.txt
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/rtui.rb
7
+ lib/rtui/progress.rb
8
+ rspec.rake
9
+ rtui.gemspec
10
+ script/console
11
+ script/destroy
12
+ script/generate
13
+ spec/rtui/progress_spec.rb
14
+ spec/rtui_spec.rb
15
+ spec/spec.opts
16
+ spec/spec_helper.rb
17
+ tasks/rspec.rake
data/README.rdoc ADDED
@@ -0,0 +1,140 @@
1
+ ______ _______ _______ _______
2
+ | __ \_ _| | |_ _|
3
+ | < | | | | |_| |_
4
+ |___|__| |___| |_______|_______|
5
+
6
+ This gem goal is to provide TUI eye candy for ruby.
7
+
8
+ For now, we got:
9
+
10
+ * From Ruby/ProgressBar by Satoru Takabayashi
11
+
12
+ Ruby/ProgressBar is a text progress bar library for Ruby.
13
+ It can indicate progress with percentage, a progress bar,
14
+ and estimated remaining time.
15
+ This fork changes the api and adds some methods.
16
+
17
+
18
+ == Examples
19
+
20
+ pbar = Rtui::Progress.new("test", 100)
21
+ 100.times {sleep(0.1); pbar.inc}; pbar.finish
22
+
23
+ test: 100% |===============================================| Time: 00:00:10
24
+
25
+
26
+ pbar = Rtui::Progress.new("test", 100, :components => [:bar, :percentage])
27
+ 100.times {sleep(0.1); pbar.inc}; pbar.finish
28
+
29
+ |====================================================================| 100%
30
+
31
+
32
+ pbar = Progress.new("test", 100, :components => [:spinner, :subject, :percentage])
33
+ 100.times { |i| sleep(0.1); pbar.subject = "Iteration #{i}.."; pbar.inc}; pbar.finish
34
+
35
+ \ Iteration 68 68%
36
+
37
+ pbar = Progress.new("foo", 100, :bar => "o", :components => [:pong, :percentage])
38
+ (1..100).each{|x| sleep(0.1); pbar.set(x)}; pbar.finish
39
+
40
+ | o | 67%
41
+
42
+
43
+ == Install
44
+
45
+ sudo gem sources --add http://gems.github.com
46
+ sudo gem install nofxx-rtui
47
+
48
+
49
+ == API
50
+
51
+ === Progress#new (title, total, *options)
52
+ Display the initial progress bar and return a
53
+ ProgressBar object. ((|title|)) specifies the title,
54
+ and ((|total|)) specifies the total cost of processing.
55
+ Options parameter ((|:out|)) specifies the output IO.
56
+
57
+ The display of the progress bar is updated when one or
58
+ more percent is proceeded or one or more seconds are
59
+ elapsed from the previous display.
60
+
61
+ === Options:
62
+
63
+ { :bar => "=", :out => STDERR, :components => [
64
+ :title,
65
+ :bar,
66
+ :spinner,
67
+ :subject,
68
+ :pong,
69
+ :percentage,
70
+ :stat
71
+ ]}
72
+
73
+
74
+ === Progress#inc (step = 1)
75
+ Increase the internal counter by ((|step|)) and update
76
+ the display of the progress bar. Display the estimated
77
+ remaining time on the right side of the bar. The counter
78
+ does not go beyond the ((|total|)).
79
+
80
+ === Progress#set (count)
81
+ Set the internal counter to ((|count|)) and update the
82
+ display of the progress bar. Display the estimated
83
+ remaining time on the right side of the bar. Raise if
84
+ ((|count|)) is a negative number or a number more than
85
+ the ((|total|)).
86
+
87
+ === Progress#subject (subject)
88
+ Set the bar current subject.
89
+
90
+ === Progress#finish
91
+ Stop the progress bar and update the display of progress
92
+ bar. Display the elapsed time on the right side of the bar.
93
+ The progress bar always stops at 100 % by the method.
94
+
95
+ === Progress#halt
96
+ Stop the progress bar and update the display of progress
97
+ bar. Display the elapsed time on the right side of the bar.
98
+ The progress bar stops at the current percentage by the method.
99
+
100
+ === Progress#format_arguments=
101
+ Set the methods for displaying a progress bar.
102
+ Default: [:title, :percentage, :bar, :stat].
103
+
104
+ === Progress#file_transfer_mode
105
+ Use :stat_for_file_transfer instead of :stat to display
106
+ transfered bytes and transfer rate.
107
+
108
+
109
+ ReverseProgress class is also available. The
110
+ functionality is identical to Progress but the direction
111
+ of the progress bar is just opposite.
112
+
113
+
114
+ == Limitations
115
+
116
+ Since the progress is calculated by the proportion to the
117
+ total cost of processing, Ruby/ProgressBar cannot be used if
118
+ the total cost of processing is unknown in advance.
119
+ Moreover, the estimation of remaining time cannot be
120
+ accurately performed if the progress does not flow uniformly.
121
+
122
+
123
+ == LICENSE:
124
+ Copyright (C) 2008
125
+
126
+
127
+ === Original Gem
128
+
129
+ * http://namazu.org/~satoru/ruby-progressbar/ruby-progressbar-0.9.tar.gz
130
+ * http://cvs.namazu.org/ruby-progressbar
131
+
132
+ Satoru Takabayashi
133
+ http://namazu.org/~satoru
134
+
135
+
136
+ Copyright (C) 2001-2005 Satoru Takabayashi <satoru@namazu.org>
137
+ All rights reserved.
138
+ This is free software with ABSOLUTELY NO WARRANTY.
139
+
140
+ You can redistribute it and/or modify it under the terms of Ruby's license.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/rtui'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('rtui', Rtui::VERSION) do |p|
7
+ p.developer('Marcos Piccinini', 'x@nofxx.com')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.rubyforge_name = p.name # TODO this is default value
10
+ p.summary = "Ruby TUI Helpers"
11
+ p.description = "Set of tools for TUI Eye Candy"
12
+ p.url = "http://github.com/nofxx/rtui"
13
+ p.extra_dev_deps = [
14
+ ['newgem', ">= #{::Newgem::VERSION}"]
15
+ ]
16
+
17
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
18
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
19
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
20
+ p.rsync_args = '-av --delete --ignore-errors'
21
+ end
22
+
23
+ require 'newgem/tasks' # load /tasks/*.rake
24
+ Dir['tasks/**/*.rake'].each { |t| load t }
25
+
26
+ # TODO - want other tests/tasks run by default? Add them to the list
27
+ # task :default => [:spec, :features]
@@ -0,0 +1,297 @@
1
+ #
2
+ #
3
+ #
4
+ #
5
+ # Original code:
6
+ #
7
+ # Ruby/ProgressBar - a text progress bar library VERSION = "0.9"
8
+ #
9
+ # Copyright (C) 2001-2005 Satoru Takabayashi <satoru@namazu.org>
10
+ # All rights reserved.
11
+ # This is free software with ABSOLUTELY NO WARRANTY.
12
+ #
13
+ # You can redistribute it and/or modify it under the terms
14
+ # of Ruby's license.
15
+ #
16
+ #
17
+ #
18
+ #require 'rtui/progress/bar'
19
+ #require 'rtui/progress/spinner'
20
+
21
+ module Rtui
22
+
23
+ #
24
+ # Progress indicators
25
+ #
26
+ class Progress
27
+ attr_reader :title
28
+ attr_reader :current
29
+ attr_reader :total
30
+ attr_accessor :start_time
31
+
32
+ #
33
+ # Initializes a progress indicator.
34
+ #
35
+ # Examples:
36
+ #
37
+ # Just a bar and ETA:
38
+ # Rtui::Progress.new("Foo", 10, { :components => [:bar, :stat]})
39
+ #
40
+ # A Spinner with just percentage:
41
+ # Rtui::Progress.new("Foo", 10, { :components => [:spinner, :percentage]})
42
+ #
43
+ #
44
+ # Options:
45
+ # - bar => "="
46
+ # - out => STDERR
47
+ #
48
+ # Components:
49
+ # - title
50
+ # - spinner
51
+ # - percentage
52
+ # - stat
53
+ # - bar
54
+ #
55
+ def initialize (title, total, *options)
56
+ options = options.first || {}
57
+ @title = title
58
+ @total = total
59
+ @terminal_width = 80
60
+ @current = 0
61
+ @previous = 0
62
+ @finished = false
63
+ @start_time = Time.now
64
+ @previous_time = @start_time
65
+ @title_width = 14
66
+ @subject = ""
67
+
68
+ @out = options[:out] || STDERR
69
+ @bar_mark = options[:bar] || "="
70
+ @colors = options[:colors] || false
71
+ @components = options[:components] || [:title, :percentage, :bar, :stat]
72
+
73
+ clear
74
+ show
75
+ end
76
+
77
+ def clear
78
+ @out.print "\r#{(" " * (get_width - 1))}\r"
79
+ end
80
+
81
+ def finish
82
+ @current = @total
83
+ @finished = true
84
+ show
85
+ end
86
+
87
+ def finished?
88
+ @finished
89
+ end
90
+
91
+ def file_transfer_mode
92
+ return unless @components.index(:stat)
93
+ @components[@components.index(:stat)] = :stat_for_file_transfer
94
+ end
95
+
96
+ # def format= (format)
97
+ # @format = format
98
+ # end
99
+
100
+ def components= (arguments)
101
+ @components = arguments
102
+ end
103
+
104
+ def subject=(subject)
105
+ @subject = subject
106
+ end
107
+
108
+ def halt
109
+ @finished = true
110
+ show
111
+ end
112
+
113
+ def inc step = 1
114
+ @current += step
115
+ @current = @total if @current > @total
116
+ show_if_needed
117
+ @previous = @current
118
+ end
119
+
120
+ def set (count)
121
+ if count < 0 || count > @total
122
+ raise "invalid count: #{count} (total: #{@total})"
123
+ end
124
+ @current = count
125
+ show_if_needed
126
+ @previous = @current
127
+ end
128
+
129
+ def inspect
130
+ "#<Rtui::Progress:#{@current}/#{@total}>"
131
+ end
132
+
133
+
134
+ private
135
+
136
+ def fmt_subject
137
+ " " + @subject + ( " " * (@terminal_width - @subject.length))
138
+ end
139
+
140
+ def fmt_bar
141
+ bar_width = do_percentage * @terminal_width / 100
142
+ sprintf("|%s%s|",
143
+ @bar_mark * bar_width,
144
+ " " * (@terminal_width - bar_width))
145
+ end
146
+
147
+ def fmt_spinner
148
+ bar_width = do_percentage * @terminal_width / 100
149
+ sprintf(" %s%s ",
150
+ do_percentage == 100 ? " " : '/-\\|'[do_percentage%4].chr ,
151
+ " " * (@terminal_width / 100) )
152
+ end
153
+
154
+ def fmt_pong
155
+ bar_width = do_percentage * @terminal_width / 100
156
+ sprintf("|%s%s|",
157
+ " " * bar_width + @bar_mark,
158
+ " " * (@terminal_width - bar_width))
159
+ end
160
+
161
+ def fmt_percentage
162
+ "%3d%%" % do_percentage
163
+ end
164
+
165
+ def fmt_stat
166
+ @finished ? elapsed : eta
167
+ end
168
+
169
+ def fmt_stat_for_file_transfer
170
+ sprintf("%s %s %s", bytes, transfer_rate, fmt_stat)
171
+ end
172
+
173
+ def fmt_title
174
+ @title[0,(@title_width - 1)] + ":"
175
+ end
176
+
177
+ def convert_bytes (bytes)
178
+ if bytes < 1024
179
+ sprintf("%6dB", bytes)
180
+ elsif bytes < 1024 * 1000 # 1000kb
181
+ sprintf("%5.1fKB", bytes.to_f / 1024)
182
+ elsif bytes < 1024 * 1024 * 1000 # 1000mb
183
+ sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
184
+ else
185
+ sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
186
+ end
187
+ end
188
+
189
+ def transfer_rate
190
+ bytes_per_second = @current.to_f / (Time.now - @start_time)
191
+ sprintf("%s/s", convert_bytes(bytes_per_second))
192
+ end
193
+
194
+ def bytes
195
+ convert_bytes(@current)
196
+ end
197
+
198
+ def format_time (t)
199
+ t = t.to_i
200
+ sec = t % 60
201
+ min = (t / 60) % 60
202
+ hour = t / 3600
203
+ sprintf("%02d:%02d:%02d", hour, min, sec);
204
+ end
205
+
206
+ # ETA stands for Estimated Time of Arrival.
207
+ def eta
208
+ if @current == 0
209
+ "ETA: --:--:--"
210
+ else
211
+ elapsed = Time.now - @start_time
212
+ eta = elapsed * @total / @current - elapsed;
213
+ sprintf("ETA: %s", format_time(eta))
214
+ end
215
+ end
216
+
217
+ def elapsed
218
+ sprintf("Time: %s", format_time(Time.now - @start_time))
219
+ end
220
+
221
+ def eol
222
+ @finished ? "\n" : "\r"
223
+ end
224
+
225
+ def do_percentage
226
+ return 100 if @total.zero?
227
+ @current * 100 / @total
228
+ end
229
+
230
+ def get_width
231
+ # FIXME: I don't know how portable it is.
232
+ #
233
+ # Works linux...
234
+ # Fails OSX
235
+ #
236
+ default_width = 80
237
+ begin
238
+ tiocgwinsz = 0x5413
239
+ data = [0, 0, 0, 0].pack("SSSS")
240
+ if @out.ioctl(tiocgwinsz, data) >= 0 then
241
+ rows, cols, xpixels, ypixels = data.unpack("SSSS")
242
+ if cols >= 0 then cols else default_width end
243
+ else
244
+ default_width
245
+ end
246
+ rescue Exception
247
+ default_width
248
+ end
249
+ end
250
+
251
+ def show
252
+ line = @components.map {|method|
253
+ send(sprintf("fmt_%s", method))
254
+ }.join " "
255
+
256
+ width = get_width
257
+ if line.length == width - 1
258
+ @out.print(line + eol)
259
+ @out.flush
260
+ elsif line.length >= width
261
+ @terminal_width = [@terminal_width - (line.length - width + 1), 0].max
262
+ if @terminal_width == 0 then @out.print(line + eol) else show end
263
+ else # line.length < width - 1
264
+ @terminal_width += width - line.length + 1
265
+ show
266
+ end
267
+ @previous_time = Time.now
268
+ end
269
+
270
+ def show_if_needed
271
+ if @total.zero?
272
+ cur_percentage = 100
273
+ prev_percentage = 0
274
+ else
275
+ cur_percentage = (@current * 100 / @total).to_i
276
+ prev_percentage = (@previous * 100 / @total).to_i
277
+ end
278
+
279
+ # Use "!=" instead of ">" to support negative changes
280
+ if cur_percentage != prev_percentage ||
281
+ Time.now - @previous_time >= 1 || @finished
282
+ show
283
+ end
284
+
285
+ end
286
+
287
+ end
288
+
289
+ class ReversedProgress < Progress
290
+
291
+ def do_percentage
292
+ 100 - super
293
+ end
294
+
295
+ end
296
+
297
+ end
data/lib/rtui.rb ADDED
@@ -0,0 +1,9 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'rtui/progress'
5
+
6
+
7
+ module Rtui
8
+ VERSION = '0.1.1'
9
+ end
data/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
data/rtui.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rtui}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Marcos Piccinini"]
9
+ s.date = %q{2008-12-20}
10
+ s.description = %q{Set of tools for TUI Eye Candy}
11
+ s.email = ["x@nofxx.com"]
12
+ s.extra_rdoc_files = ["History.txt", "LICENSE.txt", "Manifest.txt", "README.rdoc"]
13
+ 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"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/nofxx/rtui}
16
+ s.rdoc_options = ["--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{rtui}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Ruby TUI Helpers}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<newgem>, [">= 1.2.1"])
28
+ s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
29
+ else
30
+ s.add_dependency(%q<newgem>, [">= 1.2.1"])
31
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
32
+ end
33
+ else
34
+ s.add_dependency(%q<newgem>, [">= 1.2.1"])
35
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
36
+ end
37
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/rtui.rb'}"
9
+ puts "Loading rtui gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,154 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe "Progress Bar" do
4
+
5
+
6
+ #
7
+ # Ok. Need real tests.
8
+ # But this REALLY works =D
9
+ #
10
+ describe "Visual tests" do
11
+
12
+ SleepUnit = 0.01
13
+
14
+ def do_make_progress_bar (title, total)
15
+ Rtui::Progress.new(title, total)
16
+ end
17
+
18
+ it "should pong" do
19
+ total = 100
20
+ pbar = Rtui::Progress.new("test(inc)", total, :bar => "o",
21
+ :components => [:pong, :percentage])
22
+ total.times { sleep(0.01); pbar.inc }
23
+ pbar.finish
24
+ end
25
+
26
+ it "should spin!" do
27
+ total = 100
28
+ pbar = Rtui::Progress.new("test(inc)", total,
29
+ :components => [:spinner, :percentage, :stat])
30
+ total.times { sleep(0.01); pbar.inc }
31
+ pbar.finish
32
+ end
33
+
34
+ it "different bar" do
35
+ total = 100
36
+ pbar = Rtui::Progress.new("test(inc)", total, :bar => "_",
37
+ :components => [ :stat, :bar, :percentage])
38
+ total.times { sleep(SleepUnit); pbar.inc }
39
+ pbar.finish
40
+ end
41
+
42
+ it "should spin 2!" do
43
+ total = 100
44
+ pbar = Rtui::Progress.new("test(inc)", total,
45
+ :components => [:spinner, :percentage])
46
+ total.times { sleep(0.01); pbar.inc }
47
+ pbar.finish
48
+ end
49
+
50
+ it "should handle bytes" do
51
+ total = 1024 * 1024
52
+ pbar = do_make_progress_bar("test(bytes)", total)
53
+ pbar.file_transfer_mode
54
+ 0.step(total, 2**14) {|x|
55
+ pbar.set(x)
56
+ sleep(SleepUnit)
57
+ }
58
+ pbar.finish
59
+
60
+ end
61
+
62
+ it "should show a subject!" do
63
+ total = 100
64
+ pbar = Rtui::Progress.new("test(inc)", total,
65
+ :components => [:spinner, :percentage, :subject, :stat])
66
+ total.times { |i| sleep(0.1); pbar.subject = "inter #{i} times!!!"; pbar.inc }
67
+ pbar.finish
68
+ end
69
+ #
70
+ # it "should clear" do
71
+ # total = 100
72
+ # pbar = do_make_progress_bar("test(clear)", total)
73
+ # total.times {
74
+ # sleep(SleepUnit)
75
+ # pbar.inc
76
+ # }
77
+ # pbar.clear
78
+ # puts
79
+ # end
80
+ #
81
+ # def test_halt
82
+ # total = 100
83
+ # pbar = do_make_progress_bar("test(halt)", total)
84
+ # (total / 2).times {
85
+ # sleep(SleepUnit)
86
+ # pbar.inc
87
+ # }
88
+ # pbar.halt
89
+ # end
90
+ #
91
+ # it "should test_inc" do
92
+ # total = 100
93
+ # pbar = do_make_progress_bar("test(inc)", total)
94
+ # total.times {
95
+ # sleep(SleepUnit)
96
+ # pbar.inc
97
+ # }
98
+ # pbar.finish
99
+ # end
100
+ #
101
+ # it "should test_inc_x" do
102
+ # total = File.size(File.dirname(__FILE__) + '/bar_spec.rb')
103
+ # pbar = do_make_progress_bar("test(inc(x))", total)
104
+ # File.new(File.dirname(__FILE__) + '/bar_spec.rb').each {|line|
105
+ # sleep(SleepUnit)
106
+ # pbar.inc(line.length)
107
+ # }
108
+ # pbar.finish
109
+ # end
110
+ #
111
+ # def test_invalid_set
112
+ # total = 100
113
+ # pbar = do_make_progress_bar("test(invalid set)", total)
114
+ # begin
115
+ # pbar.set(200)
116
+ # rescue RuntimeError => e
117
+ # puts e.message
118
+ # end
119
+ # end
120
+ #
121
+ # def test_set
122
+ # total = 1000
123
+ # pbar = do_make_progress_bar("test(set)", total)
124
+ # (1..total).find_all {|x| x % 10 == 0}.each {|x|
125
+ # sleep(SleepUnit)
126
+ # pbar.set(x)
127
+ # }
128
+ # pbar.finish
129
+ # end
130
+ #
131
+ # def test_slow
132
+ # total = 100000
133
+ # pbar = do_make_progress_bar("test(slow)", total)
134
+ # 0.step(500, 1) {|x|
135
+ # pbar.set(x)
136
+ # sleep(SleepUnit)
137
+ # }
138
+ # pbar.halt
139
+ # end
140
+ #
141
+ # def test_total_zero
142
+ # total = 0
143
+ # pbar = do_make_progress_bar("test(total=0)", total)
144
+ # pbar.finish
145
+ # end
146
+ # end
147
+ #
148
+ # class ReversedProgressBarTest < ProgressBarTest
149
+ # def do_make_progress_bar (title, total)
150
+ # ReversedProgressBar.new(title, total)
151
+ # end
152
+ # end
153
+ end
154
+ end
data/spec/rtui_spec.rb ADDED
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ describe "Place your specs here" do
6
+
7
+ it "find this spec in spec directory" do
8
+ "Be sure to write your specs"
9
+ end
10
+
11
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format progress
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'rtui'
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nofxx-rtui
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Marcos Piccinini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-20 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: newgem
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.2.1
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: hoe
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.8.0
32
+ version:
33
+ description: Set of tools for TUI Eye Candy
34
+ email:
35
+ - x@nofxx.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - History.txt
42
+ - LICENSE.txt
43
+ - Manifest.txt
44
+ - README.rdoc
45
+ files:
46
+ - History.txt
47
+ - LICENSE.txt
48
+ - Manifest.txt
49
+ - README.rdoc
50
+ - Rakefile
51
+ - lib/rtui.rb
52
+ - lib/rtui/progress.rb
53
+ - rspec.rake
54
+ - rtui.gemspec
55
+ - script/console
56
+ - script/destroy
57
+ - script/generate
58
+ - spec/rtui/progress_spec.rb
59
+ - spec/rtui_spec.rb
60
+ - spec/spec.opts
61
+ - spec/spec_helper.rb
62
+ - tasks/rspec.rake
63
+ has_rdoc: true
64
+ homepage: http://github.com/nofxx/rtui
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --main
68
+ - README.rdoc
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project: rtui
86
+ rubygems_version: 1.2.0
87
+ signing_key:
88
+ specification_version: 2
89
+ summary: Ruby TUI Helpers
90
+ test_files: []
91
+