progressbar 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - rbx-2.0
6
+ - jruby
7
+ - ruby-head
8
+ - ree
@@ -29,13 +29,15 @@ class ProgressBar
29
29
  clear
30
30
  show
31
31
  end
32
+
32
33
  attr_reader :title
33
34
  attr_reader :current
34
35
  attr_reader :total
35
36
  attr_accessor :start_time
36
37
  attr_writer :bar_mark
37
38
 
38
- private
39
+ private
40
+
39
41
  def fmt_bar
40
42
  bar_width = do_percentage * @terminal_width / 100
41
43
  sprintf("|%s%s|",
@@ -120,21 +122,23 @@ class ProgressBar
120
122
  end
121
123
  end
122
124
 
123
- def get_width
124
- # FIXME: I don't know how portable it is.
125
- default_width = 80
126
- begin
127
- tiocgwinsz = 0x5413
128
- data = [0, 0, 0, 0].pack("SSSS")
129
- if @out.ioctl(tiocgwinsz, data) >= 0 then
130
- rows, cols, xpixels, ypixels = data.unpack("SSSS")
131
- if cols >= 0 then cols else default_width end
132
- else
133
- default_width
134
- end
135
- rescue Exception
136
- default_width
125
+ DEFAULT_WIDTH = 80
126
+ def get_term_width
127
+ if ENV['COLUMNS'] =~ /^\d+$/
128
+ ENV['COLUMNS'].to_i
129
+ elsif (RUBY_PLATFORM =~ /java/ || (!STDIN.tty? && ENV['TERM'])) && shell_command_exists?('tput')
130
+ `tput cols`.to_i
131
+ elsif STDIN.tty? && shell_command_exists?('stty')
132
+ `stty size`.scan(/\d+/).map { |s| s.to_i }[1]
133
+ else
134
+ DEFAULT_WIDTH
137
135
  end
136
+ rescue
137
+ DEFAULT_WIDTH
138
+ end
139
+
140
+ def shell_command_exists?(command)
141
+ ENV['PATH'].split(File::PATH_SEPARATOR).any?{|d| File.exists? File.join(d, command) }
138
142
  end
139
143
 
140
144
  def show
@@ -144,7 +148,7 @@ class ProgressBar
144
148
  }
145
149
  line = sprintf(@format, *arguments)
146
150
 
147
- width = get_width
151
+ width = get_term_width
148
152
  if line.length == width - 1
149
153
  @out.print(line + eol)
150
154
  @out.flush
@@ -174,10 +178,11 @@ class ProgressBar
174
178
  end
175
179
  end
176
180
 
177
- public
181
+ public
182
+
178
183
  def clear
179
184
  @out.print "\r"
180
- @out.print(" " * (get_width - 1))
185
+ @out.print(" " * (get_term_width - 1))
181
186
  @out.print "\r"
182
187
  end
183
188
 
@@ -227,6 +232,7 @@ class ProgressBar
227
232
  def inspect
228
233
  "#<ProgressBar:#{@current}/#{@total}>"
229
234
  end
235
+
230
236
  end
231
237
 
232
238
  class ReversedProgressBar < ProgressBar
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "progressbar"
5
- s.version = "0.9.1"
5
+ s.version = "0.9.2"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Satoru Takabayashi", "Jose Peleteiro"]
8
8
  s.email = ["satoru@0xcc.net", "jose@peleteiro.net"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progressbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,12 +10,12 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-06-08 00:00:00.000000000 -07:00
13
+ date: 2011-11-22 00:00:00.000000000 -02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
18
- requirement: &2157497740 !ruby/object:Gem::Requirement
18
+ requirement: &70165027226020 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 1.0.0
24
24
  type: :development
25
25
  prerelease: false
26
- version_requirements: *2157497740
26
+ version_requirements: *70165027226020
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
- requirement: &2157497280 !ruby/object:Gem::Requirement
29
+ requirement: &70165027225560 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
- version_requirements: *2157497280
37
+ version_requirements: *70165027225560
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: yard
40
- requirement: &2157496820 !ruby/object:Gem::Requirement
40
+ requirement: &70165027225100 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '0'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *2157496820
48
+ version_requirements: *70165027225100
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rake
51
- requirement: &2157496360 !ruby/object:Gem::Requirement
51
+ requirement: &70165027256880 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0'
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *2157496360
59
+ version_requirements: *70165027256880
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: simplecov
62
- requirement: &2157495900 !ruby/object:Gem::Requirement
62
+ requirement: &70165027256420 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: 0.3.5
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *2157495900
70
+ version_requirements: *70165027256420
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: bluecloth
73
- requirement: &2157495440 !ruby/object:Gem::Requirement
73
+ requirement: &70165027255960 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ! '>='
@@ -78,7 +78,7 @@ dependencies:
78
78
  version: 0.3.5
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *2157495440
81
+ version_requirements: *70165027255960
82
82
  description: Ruby/ProgressBar is a text progress bar library for Ruby. It can indicate
83
83
  progress with percentage, a progress bar, and estimated remaining time.
84
84
  email:
@@ -90,13 +90,13 @@ extra_rdoc_files: []
90
90
  files:
91
91
  - .gitignore
92
92
  - .rvmrc
93
+ - .travis.yml
93
94
  - ChangeLog
94
95
  - Gemfile
95
96
  - Gemfile.lock
96
97
  - LICENSE
97
98
  - README.rd
98
99
  - Rakefile
99
- - VERSION
100
100
  - lib/progressbar.rb
101
101
  - progressbar.gemspec
102
102
  - test/test.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.9.0