thor 0.15.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,8 +62,8 @@ class Thor
62
62
  # Common methods that are delegated to the shell.
63
63
  SHELL_DELEGATED_METHODS.each do |method|
64
64
  module_eval <<-METHOD, __FILE__, __LINE__
65
- def #{method}(*args)
66
- shell.#{method}(*args)
65
+ def #{method}(*args,&block)
66
+ shell.#{method}(*args,&block)
67
67
  end
68
68
  METHOD
69
69
  end
@@ -125,10 +125,15 @@ class Thor
125
125
 
126
126
  maximas = []
127
127
 
128
- start.upto(colcount - 2) do |i|
128
+ start.upto(colcount - 1) do |i|
129
129
  maxima = table.map {|row| row[i] ? row[i].to_s.size : 0 }.max
130
130
  maximas << maxima
131
- formats << "%-#{maxima + 2}s"
131
+ if i == colcount -1
132
+ # Don't output 2 trailing spaces when printing the last column
133
+ formats << "%-s"
134
+ else
135
+ formats << "%-#{maxima + 2}s"
136
+ end
132
137
  end
133
138
 
134
139
  formats[0] = formats[0].insert(0, " " * indent)
@@ -141,7 +146,12 @@ class Thor
141
146
  maxima = maximas[i]
142
147
 
143
148
  if column.is_a?(Numeric)
144
- f = "%#{maxima}s "
149
+ if i == row.size - 1
150
+ # Don't output 2 trailing spaces when printing the last column
151
+ f = "%#{maxima}s"
152
+ else
153
+ f = "%#{maxima}s "
154
+ end
145
155
  else
146
156
  f = formats[i]
147
157
  end
@@ -316,10 +326,27 @@ HELP
316
326
  end
317
327
 
318
328
  def truncate(string, width)
319
- if string.length <= width
320
- string
321
- else
322
- ( string[0, width-3] || "" ) + "..."
329
+ as_unicode do
330
+ chars = string.chars.to_a
331
+
332
+ if chars.length <= width
333
+ chars.join
334
+ else
335
+ ( chars[0, width-3].join ) + "..."
336
+ end
337
+ end
338
+ end
339
+
340
+ if "".respond_to?(:encode)
341
+ def as_unicode
342
+ yield
343
+ end
344
+ else
345
+ def as_unicode
346
+ old, $KCODE = $KCODE, "U"
347
+ yield
348
+ ensure
349
+ $KCODE = old
323
350
  end
324
351
  end
325
352
 
@@ -1,3 +1,3 @@
1
1
  class Thor
2
- VERSION = "0.15.0"
2
+ VERSION = "0.15.1"
3
3
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
4
 
3
5
  describe Thor::Shell::Basic do
@@ -145,12 +147,16 @@ TABLE
145
147
  end
146
148
 
147
149
  it "uses maximum terminal width" do
150
+ @table << ["def", "#456", "Lançam foo bar"]
151
+ @table << ["ghi", "#789", "بالله عليكم"]
148
152
  shell.should_receive(:terminal_width).and_return(20)
149
153
  content = capture(:stdout){ shell.print_table(@table, :indent => 2, :truncate => true) }
150
154
  content.should == <<-TABLE
151
155
  abc #123 firs...
152
156
  #0 empty
153
157
  xyz #786 last...
158
+ def #456 Lanç...
159
+ ghi #789 بالل...
154
160
  TABLE
155
161
  end
156
162
 
@@ -173,7 +179,7 @@ xyz #786 last three
173
179
  TABLE
174
180
  end
175
181
 
176
- it "prints a table with small numbers, and right-aligns them" do
182
+ it "prints a table with small numbers and right-aligns them" do
177
183
  table = [
178
184
  ["Name", "Number", "Color"],
179
185
  ["Erik", 1, "green"]
@@ -185,6 +191,18 @@ Erik 1 green
185
191
  TABLE
186
192
  end
187
193
 
194
+ it "doesn't output extra spaces for right-aligned columns in the last column" do
195
+ table = [
196
+ ["Name", "Number"],
197
+ ["Erik", 1]
198
+ ]
199
+ content = capture(:stdout){ shell.print_table(table) }
200
+ content.should == <<-TABLE
201
+ Name Number
202
+ Erik 1
203
+ TABLE
204
+ end
205
+
188
206
  it "prints a table with big numbers" do
189
207
  table = [
190
208
  ["Name", "Number", "Color"],
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.15.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-29 00:00:00.000000000 Z
13
+ date: 2012-05-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler