rtui 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
+
@@ -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.
@@ -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
@@ -0,0 +1,139 @@
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 install rtui
46
+
47
+
48
+ == API
49
+
50
+ === Progress#new (title, total, *options)
51
+ Display the initial progress bar and return a
52
+ ProgressBar object. ((|title|)) specifies the title,
53
+ and ((|total|)) specifies the total cost of processing.
54
+ Options parameter ((|:out|)) specifies the output IO.
55
+
56
+ The display of the progress bar is updated when one or
57
+ more percent is proceeded or one or more seconds are
58
+ elapsed from the previous display.
59
+
60
+ === Options:
61
+
62
+ { :bar => "=", :out => STDERR, :components => [
63
+ :title,
64
+ :bar,
65
+ :spinner,
66
+ :subject,
67
+ :pong,
68
+ :percentage,
69
+ :stat
70
+ ]}
71
+
72
+
73
+ === Progress#inc (step = 1)
74
+ Increase the internal counter by ((|step|)) and update
75
+ the display of the progress bar. Display the estimated
76
+ remaining time on the right side of the bar. The counter
77
+ does not go beyond the ((|total|)).
78
+
79
+ === Progress#set (count)
80
+ Set the internal counter to ((|count|)) and update the
81
+ display of the progress bar. Display the estimated
82
+ remaining time on the right side of the bar. Raise if
83
+ ((|count|)) is a negative number or a number more than
84
+ the ((|total|)).
85
+
86
+ === Progress#subject (subject)
87
+ Set the bar current subject.
88
+
89
+ === Progress#finish
90
+ Stop the progress bar and update the display of progress
91
+ bar. Display the elapsed time on the right side of the bar.
92
+ The progress bar always stops at 100 % by the method.
93
+
94
+ === Progress#halt
95
+ Stop the progress bar and update the display of progress
96
+ bar. Display the elapsed time on the right side of the bar.
97
+ The progress bar stops at the current percentage by the method.
98
+
99
+ === Progress#format_arguments=
100
+ Set the methods for displaying a progress bar.
101
+ Default: [:title, :percentage, :bar, :stat].
102
+
103
+ === Progress#file_transfer_mode
104
+ Use :stat_for_file_transfer instead of :stat to display
105
+ transfered bytes and transfer rate.
106
+
107
+
108
+ ReverseProgress class is also available. The
109
+ functionality is identical to Progress but the direction
110
+ of the progress bar is just opposite.
111
+
112
+
113
+ == Limitations
114
+
115
+ Since the progress is calculated by the proportion to the
116
+ total cost of processing, Ruby/ProgressBar cannot be used if
117
+ the total cost of processing is unknown in advance.
118
+ Moreover, the estimation of remaining time cannot be
119
+ accurately performed if the progress does not flow uniformly.
120
+
121
+
122
+ == LICENSE:
123
+ Copyright (C) 2008
124
+
125
+
126
+ === Original Gem
127
+
128
+ * http://namazu.org/~satoru/ruby-progressbar/ruby-progressbar-0.9.tar.gz
129
+ * http://cvs.namazu.org/ruby-progressbar
130
+
131
+ Satoru Takabayashi
132
+ http://namazu.org/~satoru
133
+
134
+
135
+ Copyright (C) 2001-2005 Satoru Takabayashi <satoru@namazu.org>
136
+ All rights reserved.
137
+ This is free software with ABSOLUTELY NO WARRANTY.
138
+
139
+ You can redistribute it and/or modify it under the terms of Ruby's license.
@@ -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,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.8'
9
+ end
@@ -0,0 +1,301 @@
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 ||= ""
138
+ blank = @terminal_width - @subject.length
139
+ out = " " + @subject
140
+ out << " " * blank if blank > 0
141
+ out[0, @terminal_width - 5]
142
+ end
143
+
144
+ def fmt_bar
145
+ bar_width = do_percentage * @terminal_width / 100
146
+ sprintf("|%s%s|",
147
+ @bar_mark * bar_width,
148
+ " " * (@terminal_width - bar_width))
149
+ end
150
+
151
+ def fmt_spinner
152
+ bar_width = do_percentage * @terminal_width / 100
153
+ sprintf(" %s%s ",
154
+ do_percentage == 100 ? " " : '/-\\|'[do_percentage%4].chr ,
155
+ " " * (@terminal_width / 100) )
156
+ end
157
+
158
+ def fmt_pong
159
+ bar_width = do_percentage * @terminal_width / 100
160
+ sprintf("|%s%s|",
161
+ " " * bar_width + @bar_mark,
162
+ " " * (@terminal_width - bar_width))
163
+ end
164
+
165
+ def fmt_percentage
166
+ "%3d%%" % do_percentage
167
+ end
168
+
169
+ def fmt_stat
170
+ @finished ? elapsed : eta
171
+ end
172
+
173
+ def fmt_stat_for_file_transfer
174
+ sprintf("%s %s %s", bytes, transfer_rate, fmt_stat)
175
+ end
176
+
177
+ def fmt_title
178
+ @title[0,(@title_width - 1)] + ":"
179
+ end
180
+
181
+ def convert_bytes (bytes)
182
+ if bytes < 1024
183
+ sprintf("%6dB", bytes)
184
+ elsif bytes < 1024 * 1000 # 1000kb
185
+ sprintf("%5.1fKB", bytes.to_f / 1024)
186
+ elsif bytes < 1024 * 1024 * 1000 # 1000mb
187
+ sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
188
+ else
189
+ sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
190
+ end
191
+ end
192
+
193
+ def transfer_rate
194
+ bytes_per_second = @current.to_f / (Time.now - @start_time)
195
+ sprintf("%s/s", convert_bytes(bytes_per_second))
196
+ end
197
+
198
+ def bytes
199
+ convert_bytes(@current)
200
+ end
201
+
202
+ def format_time t
203
+ t = t.to_i
204
+ sec = t % 60
205
+ min = (t / 60) % 60
206
+ hour = t / 3600
207
+ sprintf("%02d:%02d:%02d", hour, min, sec);
208
+ end
209
+
210
+ # ETA stands for Estimated Time of Arrival.
211
+ def eta
212
+ if @current == 0
213
+ "ETA: --:--:--"
214
+ else
215
+ elapsed = Time.now - @start_time
216
+ eta = elapsed * @total / @current - elapsed;
217
+ sprintf("ETA: %s", format_time(eta))
218
+ end
219
+ end
220
+
221
+ def elapsed
222
+ sprintf("Time: %s", format_time(Time.now - @start_time))
223
+ end
224
+
225
+ def eol
226
+ @finished ? "\n" : "\r"
227
+ end
228
+
229
+ def do_percentage
230
+ return 100 if @total.zero?
231
+ @current * 100 / @total
232
+ end
233
+
234
+ def get_width
235
+ # FIXME: I don't know how portable it is.
236
+ #
237
+ # Works linux...
238
+ # Fails OSX
239
+ #
240
+ default_width = 80
241
+ begin
242
+ tiocgwinsz = 0x5413
243
+ data = [0, 0, 0, 0].pack("SSSS")
244
+ if @out.ioctl(tiocgwinsz, data) >= 0 then
245
+ rows, cols, xpixels, ypixels = data.unpack("SSSS")
246
+ if cols >= 0 then cols else default_width end
247
+ else
248
+ default_width
249
+ end
250
+ rescue Exception
251
+ default_width
252
+ end
253
+ end
254
+
255
+ def show
256
+ line = @components.map {|method|
257
+ send(sprintf("fmt_%s", method))
258
+ }.join " "
259
+
260
+ width = get_width
261
+ if line.length == width - 1
262
+ @out.print(line + eol)
263
+ @out.flush
264
+ elsif line.length >= width
265
+ @terminal_width = [@terminal_width - (line.length - width + 1), 0].max
266
+ if @terminal_width == 0 then @out.print(line + eol) else show end
267
+ else # line.length < width - 1
268
+ @terminal_width += width - line.length + 1
269
+ show
270
+ end
271
+ @previous_time = Time.now
272
+ end
273
+
274
+ def show_if_needed
275
+ if @total.zero?
276
+ cur_percentage = 100
277
+ prev_percentage = 0
278
+ else
279
+ cur_percentage = (@current * 100 / @total).to_i
280
+ prev_percentage = (@previous * 100 / @total).to_i
281
+ end
282
+
283
+ # Use "!=" instead of ">" to support negative changes
284
+ if cur_percentage != prev_percentage ||
285
+ Time.now - @previous_time >= 1 || @finished
286
+ show
287
+ end
288
+
289
+ end
290
+
291
+ end
292
+
293
+ class ReversedProgress < Progress
294
+
295
+ def do_percentage
296
+ 100 - super
297
+ end
298
+
299
+ end
300
+
301
+ end
@@ -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
@@ -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.8"
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-21}
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
@@ -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"
@@ -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)
@@ -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,155 @@
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.subject = "finish it"
68
+ pbar.finish
69
+ end
70
+ #
71
+ # it "should clear" do
72
+ # total = 100
73
+ # pbar = do_make_progress_bar("test(clear)", total)
74
+ # total.times {
75
+ # sleep(SleepUnit)
76
+ # pbar.inc
77
+ # }
78
+ # pbar.clear
79
+ # puts
80
+ # end
81
+ #
82
+ # def test_halt
83
+ # total = 100
84
+ # pbar = do_make_progress_bar("test(halt)", total)
85
+ # (total / 2).times {
86
+ # sleep(SleepUnit)
87
+ # pbar.inc
88
+ # }
89
+ # pbar.halt
90
+ # end
91
+ #
92
+ # it "should test_inc" do
93
+ # total = 100
94
+ # pbar = do_make_progress_bar("test(inc)", total)
95
+ # total.times {
96
+ # sleep(SleepUnit)
97
+ # pbar.inc
98
+ # }
99
+ # pbar.finish
100
+ # end
101
+ #
102
+ # it "should test_inc_x" do
103
+ # total = File.size(File.dirname(__FILE__) + '/bar_spec.rb')
104
+ # pbar = do_make_progress_bar("test(inc(x))", total)
105
+ # File.new(File.dirname(__FILE__) + '/bar_spec.rb').each {|line|
106
+ # sleep(SleepUnit)
107
+ # pbar.inc(line.length)
108
+ # }
109
+ # pbar.finish
110
+ # end
111
+ #
112
+ # def test_invalid_set
113
+ # total = 100
114
+ # pbar = do_make_progress_bar("test(invalid set)", total)
115
+ # begin
116
+ # pbar.set(200)
117
+ # rescue RuntimeError => e
118
+ # puts e.message
119
+ # end
120
+ # end
121
+ #
122
+ # def test_set
123
+ # total = 1000
124
+ # pbar = do_make_progress_bar("test(set)", total)
125
+ # (1..total).find_all {|x| x % 10 == 0}.each {|x|
126
+ # sleep(SleepUnit)
127
+ # pbar.set(x)
128
+ # }
129
+ # pbar.finish
130
+ # end
131
+ #
132
+ # def test_slow
133
+ # total = 100000
134
+ # pbar = do_make_progress_bar("test(slow)", total)
135
+ # 0.step(500, 1) {|x|
136
+ # pbar.set(x)
137
+ # sleep(SleepUnit)
138
+ # }
139
+ # pbar.halt
140
+ # end
141
+ #
142
+ # def test_total_zero
143
+ # total = 0
144
+ # pbar = do_make_progress_bar("test(total=0)", total)
145
+ # pbar.finish
146
+ # end
147
+ # end
148
+ #
149
+ # class ReversedProgressBarTest < ProgressBarTest
150
+ # def do_make_progress_bar (title, total)
151
+ # ReversedProgressBar.new(title, total)
152
+ # end
153
+ # end
154
+ end
155
+ end
@@ -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
@@ -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'
@@ -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,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rtui
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.8
5
+ platform: ruby
6
+ authors:
7
+ - Marcos Piccinini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-21 00:00:00 -02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: newgem
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.0
34
+ version:
35
+ description: Set of tools for TUI Eye Candy
36
+ email:
37
+ - x@nofxx.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - History.txt
44
+ - LICENSE.txt
45
+ - Manifest.txt
46
+ - README.rdoc
47
+ files:
48
+ - History.txt
49
+ - LICENSE.txt
50
+ - Manifest.txt
51
+ - README.rdoc
52
+ - Rakefile
53
+ - lib/rtui.rb
54
+ - lib/rtui/progress.rb
55
+ - rspec.rake
56
+ - rtui.gemspec
57
+ - script/console
58
+ - script/destroy
59
+ - script/generate
60
+ - spec/rtui/progress_spec.rb
61
+ - spec/rtui_spec.rb
62
+ - spec/spec.opts
63
+ - spec/spec_helper.rb
64
+ - tasks/rspec.rake
65
+ has_rdoc: true
66
+ homepage: http://github.com/nofxx/rtui
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --main
72
+ - README.rdoc
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ requirements: []
88
+
89
+ rubyforge_project: rtui
90
+ rubygems_version: 1.3.5
91
+ signing_key:
92
+ specification_version: 2
93
+ summary: Ruby TUI Helpers
94
+ test_files: []
95
+