sprout 0.7.219-i686-darwin10

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sprout might be problematic. Click here for more details.

data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Pattern Park
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/TODO ADDED
@@ -0,0 +1,12 @@
1
+
2
+ ---------------------------------
3
+ In the interest of being a better member of our growing community,
4
+ I have extracted the contents of this file to the googlecode site at:
5
+
6
+ http://code.google.com/p/projectsprouts/issues/list?q=label:Beta1.0&can=2
7
+
8
+ Please feel free to check over the available issues and see if any look appealing!
9
+
10
+ If you're considering a contribution, please check in on our mailing list first just to be sure.
11
+ (projectsprouts@googlegroups.com)
12
+
data/bin/sprout ADDED
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Luke Bayes on 2007-4-29.
4
+ # Copyright (c) 2007. All rights reserved.
5
+
6
+ begin
7
+ require 'rubygems'
8
+ rescue LoadError
9
+ # no rubygems to load, so we fail silently
10
+ end
11
+
12
+ $:.push(File.dirname(__FILE__) + '/../lib')
13
+ require 'sprout'
14
+ require 'sprout/generator'
15
+ require 'optparse'
16
+
17
+ OPTIONS = {
18
+ :sources => [],
19
+ :project_name => nil,
20
+ :sprout_name => nil,
21
+ :requirements => nil,
22
+ :remove_all => false
23
+ }
24
+
25
+ def fail_with(opts, message)
26
+ puts "[ERROR] #{message}"
27
+ puts ""
28
+ puts opts
29
+ exit
30
+ end
31
+
32
+ parser = OptionParser.new do |opts|
33
+ opts.banner = <<BANNER
34
+ Sprout is an open-source, cross-platform project generation and configuration tool
35
+
36
+ Usage: #{File.basename($0)} [options] [ProjectName]
37
+
38
+ Examples:
39
+
40
+ Create a new ActionScript 3.0 project named 'SomeProject':
41
+ #{File.basename($0)} -n as3 SomeProject
42
+
43
+ Create a new ActionScript 2.0 project named 'OtherProject':
44
+ #{File.basename($0)} -n as2 OtherProject
45
+
46
+ Remove all Sprout gems and cached files:
47
+ #{File.basename($0)} -R
48
+
49
+ Options are:
50
+ BANNER
51
+ opts.separator ""
52
+
53
+ opts.on("-n", "--name NAME", String, "The name of the sprout bundle whose project generator will be executed (e.g., as2 or as3)") do |name|
54
+ OPTIONS[:sprout_name] = name
55
+ end
56
+
57
+ opts.on('--source [URL]', String, "Use URL as the remote source for gems") do |source|
58
+ OPTIONS[:sources] << source
59
+ end
60
+
61
+ opts.on('-r', '--requirements REQUIREMENTS', String, "The specific gem version requirements for the named bundle (e.g., 0.3.2)") do |requirements|
62
+ OPTIONS[:requirements] = requirements
63
+ end
64
+
65
+ opts.on("-R", "--remove-all", "Remove all sprout gems and cached files") do
66
+ OPTIONS[:remove_all] = true
67
+ Sprout::Sprout.remove_all
68
+ end
69
+
70
+ opts.on("-v", "--version", "Display the installed version of the sprout gem") do |version|
71
+ puts "sprout #{Sprout::VERSION::STRING}"
72
+ exit
73
+ end
74
+
75
+ opts.on("-h", "--help", "Show this help message.") do
76
+ puts opts
77
+ exit
78
+ end
79
+
80
+ opts.parse!(ARGV)
81
+
82
+ if(OPTIONS[:sources].size > 0)
83
+ set_sources OPTIONS[:sources]
84
+ end
85
+
86
+ if(ARGV.size > 0)
87
+ if(OPTIONS[:sprout_name])
88
+ OPTIONS[:project_name] = ARGV.pop
89
+ if(OPTIONS[:project_name] == "=")
90
+ fail_with(opts, "Invalid project name #{OPTIONS[:project_name]}")
91
+ end
92
+ else
93
+ fail_with(opts, "You must provide a sprout name argument such as, '-n as2' or '-n as3'")
94
+ end
95
+ elsif(OPTIONS[:remove_all])
96
+ exit
97
+ else
98
+ fail_with(opts, "Expected a sprout bundle name and project name like: 'sprout -n as2 SomeProject'")
99
+ end
100
+
101
+ end
102
+
103
+ #############################################
104
+
105
+ sprout_name = OPTIONS[:sprout_name]
106
+ sprout_requirements = OPTIONS[:requirements]
107
+ project_name = OPTIONS[:project_name]
108
+
109
+ #############################################
110
+
111
+ puts ">> Creating new project '#{project_name}' with #{sprout_name}"
112
+ Sprout::Sprout.project_name = project_name
113
+
114
+ begin
115
+ # Fallback if a version was specified
116
+ if(sprout_requirements)
117
+ sprout(sprout_name, sprout_requirements)
118
+ end
119
+ # Try to run the generator against user home and existing gems first
120
+ Sprout::Sprout.generate(sprout_name, 'project', [project_name])
121
+ rescue RubiGen::GeneratorError
122
+ # Failing that, try to download a sprout gem by name
123
+ sprout(sprout_name, sprout_requirements)
124
+ # Then try again....
125
+ Sprout::Sprout.generate(sprout_name, 'project', [project_name])
126
+ end
127
+
128
+ Sprout::Log.flush
data/doc/Bundle ADDED
@@ -0,0 +1,14 @@
1
+
2
+ A Sprout Bundle is a collection of Ruby code that supports a particular interest or technology. At the time of this writing, we have two bundles available.
3
+
4
+ * ActionScript 2 Bundle (link[link:files/bundles/as2/README.html]) which supports ActionScript 2.0 development
5
+ * ActionScript 3 Bundle (link[link:files/bundles/as3/README.html]) which supports ActionScript 3.0, MXML and AIR development
6
+
7
+ Bundles are the named entry point that the +sprout+ shell tool uses to find project generators[link:files/doc/Generator.html].
8
+
9
+ Bundles should be packaged and published to the RubyForge gem repository with very specific names as follows:
10
+
11
+ sprout-#{bundle_name}-bundle where ${bundle_name} is what will be given to the -n parameter of the +sprout+ gem.
12
+
13
+ The as3 bundle is released as sprout-as3-bundle on RubyForge, but we can simply enter the short name when creating new as3 projects.
14
+
data/doc/Generator ADDED
@@ -0,0 +1,35 @@
1
+ A SproutGenerator is a set of specifically configured folders and files that have been placed in a particular, expected location on disk.
2
+ The Sprout generator feature is a minor modification to the standard Rubigen generators.
3
+
4
+ Sprouts modifies the underlying Rubigen Generator implementation in that we need support for multiple languages or technologies while Rubigen is able to simply expect that it's generating Ruby code.
5
+
6
+ Generators can exist in multiple different locations on disk, to learn how to create a new generator, see the Rubigen documentation[http://rubigen.rubyforge.org/].
7
+
8
+ To use a new or existing generator, simply enter it's name from within a project after calling
9
+ script/generate
10
+
11
+ When a string is passed to the generate command, sprouts will look in the following locations in the following order with 'name' being the generator name that you have requested:
12
+ * #{project_path}/generators/#{name}
13
+ * #{project_path}/script/generators/#{name}
14
+ * #{project_path}/vendor/generators/#{name}
15
+ * #{Sprout::Sprout.sprout_cache}/generators/#{Sprout::ProjectModel.language}/#{name}
16
+ * All Rubygems with a name ending with '-bundle' and with contents that match '/lib/sprout/**/generators/[name]'
17
+
18
+ This means that when you have a new project and enter:
19
+ script/generate foo
20
+
21
+ We will first look in your project for, 'generators/foo', 'script/generators/foo' and 'vendor/generators/foo'.
22
+
23
+ Assuming no viable generator is found in your project, we will then look in your Sprout::Sprout sprout_cache for a folder named 'generators/foo'.
24
+
25
+ Assuming no viable generator is found in your system wide path, we will begin looking inside of installed Ruby Gems. The expected gem will have a file at:
26
+
27
+ lib/sprout/**/generators/foo/foo_generator.rb
28
+
29
+ If no named generator is found in any of these places an exception will be encountered.
30
+
31
+ Sprouts generators can be initiated from one of two places, either from a project directory with script/generate or directly from the Sprout gem.
32
+
33
+ When executing generators directly from the Sprout gem, you must send in a bundle base name and know that only 'project' generators found in that bundle will be executed.
34
+
35
+ When executing generators from a project, the Sprout::ProjectModel language parameter is used to determine the bundle (if necessary), and then the Generator name is used to execute any found generator.
data/doc/Library ADDED
@@ -0,0 +1,63 @@
1
+
2
+ A Library is simply shared code. Some libraries are distributed with only source, others are only pre-compiled binaries (SWC for ActionScript libraries), and still others are made available in both forms.
3
+
4
+ The Sprout::LibraryTask will download and copy a remote library sprout gem.
5
+ The remote archive can include (or reference) either source or a pre-compiled
6
+ file. For ActionScript libraries, this would be a SWC file.
7
+
8
+ This task is integrated with some of the compiler tasks in such
9
+ a way that if an Sprout::MXMLCTask has any number of library tasks in
10
+ it's prerequisites list, each of those libraries will be added
11
+ to the compiler directive appropriately.
12
+
13
+ Following is a simple example of a library task. Using only
14
+ this simple task definition, the Adobe corelib library sprout gem
15
+ will be downloaded, installed and copied to your Sprout::ProjectModel +lib_dir+.
16
+
17
+ library :corelib
18
+
19
+ By adding this named task as a prerequisite to your compilation task,
20
+ that SWC will also be added to the Sprout::MXMLCTask +library_path+ parameter.
21
+
22
+ mxmlc 'bin/SomeProject.swf' => :corelib
23
+
24
+ You can also specify a particular library gem version if the library
25
+ has changed since your project began.
26
+
27
+ library :asunit3 do |t|
28
+ t.version = '3.0.1'
29
+ end
30
+
31
+ This will ensure that only that particular library version is used for this project.
32
+
33
+ You may want to refer to a library using a particular task name, but have it
34
+ use a different library sprout gem. This can be done using the gem_name parameter
35
+ as follows:
36
+
37
+ library :asunit do |t|
38
+ t.gem_name = 'sprout-asunit3-library'
39
+ end
40
+
41
+ This may be useful because now the AsUnit[http://www.asunit.org] sources will be installed to:
42
+ lib/asunit
43
+ instead of:
44
+ lib/asunit3
45
+ and you can now depend on this library as simply +:asunit+ in your compiler tasks.
46
+
47
+ You can easily create your own library gems using the Sprout::GemWrapTask and then
48
+ refer to them by gem name.
49
+
50
+ In order to share your library tasks, you will need to
51
+ do one of the following:
52
+
53
+ * Tell interested developers to manually install your library gem
54
+ * Upload your gem to any Rubyforge[http://www.rubyforge.org] project file releases area.
55
+ If your gem name begins with 'sprout-' and ends with '-library', you (and others) can refer to it by only
56
+ the string in between that prefix and suffix. Otherwise, you (and others) will always have
57
+ to set the gem_name parameter to the full name of your custom library.
58
+ * Submit your library for inclusion from the ProjectSprouts[http://www.projectsprouts.org] project.
59
+ * Add your gem to your own custom gem_server[http://rambleon.org/2007/04/19/creating-your-own-gem-server/], and set up your rakefiles to pull from that server
60
+
61
+ You can search for all available libraries as follows:
62
+ gem search -r sprout-*library
63
+ Only results that begin with 'sprout-' are known, valid libraries.
data/doc/Task ADDED
@@ -0,0 +1,21 @@
1
+ In Sprouts, a Task is referring to a Rake[http://rake.rubyforge.org/] Task.
2
+
3
+ Rake is the automated build to written in Ruby. This tool is similar to Ant[http://ant.apache.org/] and Make[http://www.gnu.org/software/make/] if you're familiar with those technologies.
4
+
5
+ The main thing that differentiates Rake from it's competitors is the fact that Rake tasks are defined and configured in Ruby code rather than XML or C. This lets us more easily avoid repetition throughout a rakefile, and we gain the full power of the Ruby language to apply to our build scripts.
6
+
7
+ Essentially, Rake allows us to write and maintain much smaller, more digestible build scripts.
8
+
9
+ To learn more about Rake, check out Martin Fowler's seminal article[http://martinfowler.com/articles/rake.html] on the subject.
10
+
11
+ At the time of this writing, Sprouts makes the following Rake tasks available:
12
+ * Core Sprout::SFTPTask
13
+ * Core Sprout::ZipTask
14
+ * Core Sprout::LibraryTask
15
+ * As3Bundle Sprout::AsDocTask
16
+ * As3Bundle Sprout::AsUnitTask
17
+ * As3Bundle Sprout::COMPCTask
18
+ * As3Bundle Sprout::MXMLCTask
19
+ * As2Bundle Sprout::MTASCTask
20
+ * As2Bundle Sprout::SWFMillTask
21
+
data/doc/Tool ADDED
@@ -0,0 +1,20 @@
1
+
2
+ A Tool is a Ruby Gem that usually refers to an executable or binary application.
3
+ These applications are either natively cross platform, or the Ruby Gem should include a
4
+ YAML document that tells Sprouts where to go in order to get the appropriate binary for
5
+ which platform the user is currently running.
6
+
7
+ CLI Tools are usually referenced by subclasses of Sprout::ToolTask.
8
+
9
+ Once installed, many Tool Sprouts are made available from your path. For example
10
+ if you install the sprout-mtasc-tool gem, from that point forward you can execute mtasc
11
+ from the terminal as follows:
12
+
13
+ mtasc -help # Should throw an error
14
+ sudo gem install sprout-mtasc-tool
15
+ mtasc -help # Should download and execute mtasc
16
+
17
+ Using just Sprout tools by themselves, we now have have the ability to install and manage
18
+ requisite executables across platforms with zero configuration.
19
+
20
+ In reality, 'Tool Sprouts' are actually nothing more than a naming convention and expected gem configuration, but once those requirements are met, the core Sprout::Sprout can do some important work with them.
data/lib/platform.rb ADDED
@@ -0,0 +1,109 @@
1
+ #
2
+ # platform.rb: naive platform detection for Ruby
3
+ # author: Matt Mower
4
+ #
5
+ # == Platform
6
+ #
7
+ # Platform is a simple module which parses the Ruby constant
8
+ # RUBY_PLATFORM and works out the OS, it's implementation,
9
+ # and the architecture it's running on.
10
+ #
11
+ # The motivation for writing this was coming across a case where
12
+ #
13
+ # +if RUBY_PLATFORM =~ /win/+
14
+ #
15
+ # didn't behave as expected (i.e. on powerpc-darwin-8.1.0)
16
+ #
17
+ # It is hoped that providing a library for parsing the platform
18
+ # means that we can cover all the cases and have something which
19
+ # works reliably 99% of the time.
20
+ #
21
+ # Please report any anomalies or new combinations to the author(s).
22
+ #
23
+ # == Use
24
+ #
25
+ # require "platform"
26
+ #
27
+ # defines
28
+ #
29
+ # Platform::OS (:unix,:win32,:vms,:os2)
30
+ # Platform::impl (:macosx,:linux,:mswin)
31
+ # Platform::arch (:powerpc,:x86,:alpha)
32
+ #
33
+ # if an unknown configuration is encountered any (or all) of
34
+ # these constant may have the value :unknown.
35
+ #
36
+ # To display the combination for your setup run
37
+ #
38
+ # ruby platform.rb
39
+ #
40
+ module Platform #:nodoc:
41
+ os = nil
42
+ impl = nil
43
+ arch = nil
44
+
45
+ if RUBY_PLATFORM =~ /darwin/i
46
+ os = :unix
47
+ impl = :macosx
48
+ elsif RUBY_PLATFORM =~ /linux/i
49
+ os = :unix
50
+ impl = :linux
51
+ elsif RUBY_PLATFORM =~ /freebsd/i
52
+ os = :unix
53
+ impl = :freebsd
54
+ elsif RUBY_PLATFORM =~ /netbsd/i
55
+ os = :unix
56
+ impl = :netbsd
57
+ elsif RUBY_PLATFORM =~ /vista/i
58
+ os = :win32
59
+ impl = :vista
60
+ elsif RUBY_PLATFORM =~ /mswin/i
61
+ os = :win32
62
+ impl = :mswin
63
+ elsif RUBY_PLATFORM =~ /cygwin/i
64
+ os = :win32
65
+ impl = :cygwin
66
+ elsif RUBY_PLATFORM =~ /mingw/i
67
+ os = :win32
68
+ impl = :mingw
69
+ elsif RUBY_PLATFORM =~ /bccwin/i
70
+ os = :win32
71
+ impl = :bccwin
72
+ elsif RUBY_PLATFORM =~ /wince/i
73
+ os = :win32
74
+ impl = :wince
75
+ elsif RUBY_PLATFORM =~ /vms/i
76
+ os = :vms
77
+ impl = :vms
78
+ elsif RUBY_PLATFORM =~ /os2/i
79
+ os = :os2
80
+ impl = :os2 # maybe there is some better choice here?
81
+ else
82
+ os = :unknown
83
+ impl = :unknown
84
+ end
85
+
86
+ # whither AIX, SOLARIS, and the other unixen?
87
+
88
+ if RUBY_PLATFORM =~ /(i\d86)/i
89
+ arch = :x86
90
+ elsif RUBY_PLATFORM =~ /ia64/i
91
+ arch = :ia64
92
+ elsif RUBY_PLATFORM =~ /powerpc/i
93
+ arch = :powerpc
94
+ elsif RUBY_PLATFORM =~ /alpha/i
95
+ arch = :alpha
96
+ else
97
+ arch = :unknown
98
+ end
99
+
100
+ OS = os
101
+ IMPL = impl
102
+ ARCH = arch
103
+ # What about AMD, Turion, Motorola, etc..?
104
+
105
+ end
106
+
107
+ if __FILE__ == $0
108
+ puts "Platform OS=#{Platform::OS}, impl=#{Platform::IMPL}, arch=#{Platform::ARCH}"
109
+ end
@@ -0,0 +1,354 @@
1
+ #
2
+ # Ruby/ProgressBar - a text progress bar library
3
+ #
4
+ # Copyright (C) 2001-2005 Satoru Takabayashi <satoru@namazu.org>
5
+ # All rights reserved.
6
+ # This is free software with ABSOLUTELY NO WARRANTY.
7
+ #
8
+ # You can redistribute it and/or modify it under the terms
9
+ # of Ruby's license.
10
+ #
11
+ # Modified by Luke Bayes to support progress display on
12
+ # multiple simultaneous connections
13
+
14
+ require 'singleton'
15
+
16
+ class ProgressBar # :nodoc:[all]
17
+ VERSION = "0.9"
18
+ @@debug = false
19
+ @@outio = $stderr
20
+
21
+ def self.new(title, total)
22
+ return ProgressBarManager.instance.add(title, total)
23
+ end
24
+
25
+ def self.debug?
26
+ @@debug
27
+ end
28
+
29
+ def self.debug=(debug)
30
+ @@debug = debug
31
+ if(debug)
32
+ @@outio = StringIO.new
33
+ else
34
+ @@outio = $stderr
35
+ end
36
+ end
37
+
38
+ def self.outio
39
+ @@outio
40
+ end
41
+
42
+ end
43
+
44
+ class ProgressBarImpl # :nodoc:[all]
45
+
46
+ def initialize (title, total, out = STDERR)
47
+ @title = title
48
+ @total = total
49
+ @out = out
50
+ @terminal_width = 80
51
+ @bar_mark = "."
52
+ @current = 0
53
+ @previous = 0
54
+ @finished_p = false
55
+ @start_time = Time.now
56
+ @previous_time = @start_time
57
+ @title_width = 18
58
+ @format = "%-#{@title_width}s %3d%% %s %s"
59
+ @format_arguments = [:title, :percentage, :bar, :stat]
60
+ clear
61
+ show
62
+ end
63
+ attr_reader :title
64
+ attr_reader :current
65
+ attr_reader :total
66
+ attr_accessor :start_time,
67
+ :title_width,
68
+ :bar_mark
69
+
70
+ def fmt_bar
71
+ bar_width = do_percentage * @terminal_width / 100
72
+ sprintf("|%s%s|",
73
+ @bar_mark * bar_width,
74
+ " " * (@terminal_width - bar_width))
75
+ end
76
+
77
+ def fmt_percentage
78
+ do_percentage
79
+ end
80
+
81
+ def fmt_stat
82
+ if @finished_p then elapsed else eta end
83
+ end
84
+
85
+ def fmt_stat_for_file_transfer
86
+ if @finished_p then
87
+ sprintf("%s %s %s", bytes, transfer_rate, elapsed)
88
+ else
89
+ sprintf("%s %s %s", bytes, transfer_rate, eta)
90
+ end
91
+ end
92
+
93
+ def fmt_title
94
+ @title[0,(@title_width - 1)] + ":"
95
+ end
96
+
97
+ def convert_bytes (bytes)
98
+ if bytes < 1024
99
+ sprintf("%6dB", bytes)
100
+ elsif bytes < 1024 * 1000 # 1000kb
101
+ sprintf("%5.1fKB", bytes.to_f / 1024)
102
+ elsif bytes < 1024 * 1024 * 1000 # 1000mb
103
+ sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
104
+ else
105
+ sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
106
+ end
107
+ end
108
+
109
+ def transfer_rate
110
+ bytes_per_second = @current.to_f / (Time.now - @start_time)
111
+ sprintf("%s/s", convert_bytes(bytes_per_second))
112
+ end
113
+
114
+ def bytes
115
+ convert_bytes(@current)
116
+ end
117
+
118
+ def format_time (t)
119
+ t = t.to_i
120
+ sec = t % 60
121
+ min = (t / 60) % 60
122
+ hour = t / 3600
123
+ sprintf("%02d:%02d:%02d", hour, min, sec)
124
+ end
125
+
126
+ # ETA stands for Estimated Time of Arrival.
127
+ def eta
128
+ if @current == 0
129
+ "ETA: --:--:--"
130
+ else
131
+ elapsed_time = Time.now - @start_time
132
+ estimated_time = elapsed_time * @total / @current - elapsed_time
133
+ sprintf("ETA: %s", format_time(estimated_time))
134
+ end
135
+ end
136
+
137
+ def elapsed
138
+ elapsed_time = Time.now - @start_time
139
+ sprintf("Time: %s", format_time(elapsed_time))
140
+ end
141
+
142
+ def eol
143
+ if @finished_p then "\n" else "\r" end
144
+ end
145
+
146
+ def do_percentage
147
+ if @total.zero?
148
+ 100
149
+ else
150
+ @current * 100 / @total
151
+ end
152
+ end
153
+
154
+ def get_width
155
+ # return 80
156
+ # FIXME: I don't know how portable it is.
157
+ default_width = 80
158
+ begin
159
+ tiocgwinsz = 0x5413
160
+ data = [0, 0, 0, 0].pack("SSSS")
161
+ if @out.ioctl(tiocgwinsz, data) >= 0 then
162
+ unpacked = data.unpack("SSSS")
163
+ cols = unpacked[1]
164
+ # Commented this because Aptana was complaining about
165
+ # The unused variables
166
+ # rows, cols, xpixels, ypixels = data.unpack("SSSS")
167
+ if cols >= 0 then cols else default_width end
168
+ else
169
+ default_width
170
+ end
171
+ rescue Exception
172
+ default_width
173
+ end
174
+ end
175
+
176
+ def show
177
+ arguments = @format_arguments.map do |method|
178
+ method = sprintf("fmt_%s", method)
179
+ send(method)
180
+ end
181
+ line = sprintf(@format, *arguments)
182
+
183
+ width = get_width
184
+ if(line.length == width - 1)
185
+ @out.print(line + eol)
186
+ @out.flush
187
+ elsif(line.length >= width)
188
+ @terminal_width = [@terminal_width - (line.length - width + 1), 0].max
189
+ if @terminal_width == 0 then @out.print(line + eol) else show end
190
+ else # line.length < width - 1
191
+ @terminal_width += width - line.length + 1
192
+ show
193
+ end
194
+ @previous_time = Time.now
195
+ end
196
+
197
+ def show_if_needed
198
+ if @total.zero?
199
+ cur_percentage = 100
200
+ prev_percentage = 0
201
+ else
202
+ cur_percentage = (@current * 100 / @total).to_i
203
+ prev_percentage = (@previous * 100 / @total).to_i
204
+ end
205
+
206
+ # Use "!=" instead of ">" to support negative changes
207
+ if cur_percentage != prev_percentage ||
208
+ Time.now - @previous_time >= 1 || @finished_p
209
+ show
210
+ end
211
+ end
212
+
213
+ public
214
+ def clear
215
+ @out.print "\r"
216
+ @out.print(" " * (get_width - 1))
217
+ @out.print "\r"
218
+ end
219
+
220
+ def finish
221
+ @current = @total
222
+ @finished_p = true
223
+ show
224
+ end
225
+
226
+ def finished?
227
+ @finished_p
228
+ end
229
+
230
+ def file_transfer_mode
231
+ @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
232
+ end
233
+
234
+ def format= (format)
235
+ @format = format
236
+ end
237
+
238
+ def format_arguments= (arguments)
239
+ @format_arguments = arguments
240
+ end
241
+
242
+ def halt
243
+ @finished_p = true
244
+ show
245
+ end
246
+
247
+ def inc (step = 1)
248
+ @current += step
249
+ @current = @total if @current > @total
250
+ show_if_needed
251
+ @previous = @current
252
+ end
253
+
254
+ def set (count)
255
+ if count < 0 || count > @total
256
+ @total = count
257
+ end
258
+ @current = count
259
+ show_if_needed
260
+ @previous = @current
261
+ end
262
+
263
+ def inspect
264
+ "#<ProgressBar:#{@current}/#{@total}>"
265
+ end
266
+ end
267
+
268
+ # Used instead of $stderr when Log.debug == true
269
+ # This helps keep us from junking up unit test
270
+ # output with download status messages
271
+ class MockOutput # :nodoc:[all]
272
+ def print(str)
273
+ end
274
+
275
+ def puts(str)
276
+ end
277
+
278
+ def flush
279
+ end
280
+ end
281
+
282
+ class ReversedProgressBar < ProgressBar # :nodoc:[all]
283
+ def do_percentage
284
+ 100 - super
285
+ end
286
+ end
287
+
288
+ class ProgressBarOutputStream # :nodoc:[all]
289
+ attr_reader :title
290
+
291
+ def initialize(mgr)
292
+ @mgr = mgr
293
+ @msg = ''
294
+ end
295
+
296
+ def print(msg)
297
+ @msg = msg
298
+ end
299
+
300
+ def flush
301
+ @mgr.flush
302
+ end
303
+
304
+ def to_s
305
+ return @msg.clone.split("\n").join("").split("\r").join("")
306
+ end
307
+
308
+ end
309
+
310
+ class ProgressBarManager # :nodoc:[all]
311
+ include Singleton
312
+
313
+ def initialize
314
+ @finished = {}
315
+ @bars = {}
316
+ @outs = {}
317
+ end
318
+
319
+ def add(title, total1)
320
+ # if(@bars[title])
321
+ # raise StandardError.new
322
+ # end
323
+ @outs[title] = ProgressBarOutputStream.new(self)
324
+ @bars[title] = ProgressBarImpl.new(title, total1, @outs[title])
325
+ end
326
+
327
+ def print(title)
328
+ str = ''
329
+ str += @outs[title].to_s
330
+ str += "\r"
331
+ outio.print "\r"
332
+ outio.print str
333
+ end
334
+
335
+ def outio
336
+ ProgressBar.outio
337
+ end
338
+
339
+ def flush
340
+ @bars.keys.each do |title|
341
+ print(title)
342
+ end
343
+
344
+ @bars.values.each do |bar|
345
+ if(bar.finished?)
346
+ print(bar.title)
347
+ outio.print "\n"
348
+ @outs.delete(bar.title)
349
+ @bars.delete(bar.title)
350
+ end
351
+ end
352
+ end
353
+
354
+ end