lib/thor/shell/basic.rb in thor-0.15.0 vs lib/thor/shell/basic.rb in thor-0.15.1
- old
+ new
@@ -123,14 +123,19 @@
colcount = table.max{|a,b| a.size <=> b.size }.size
maximas = []
- start.upto(colcount - 2) do |i|
+ start.upto(colcount - 1) do |i|
maxima = table.map {|row| row[i] ? row[i].to_s.size : 0 }.max
maximas << maxima
- formats << "%-#{maxima + 2}s"
+ if i == colcount -1
+ # Don't output 2 trailing spaces when printing the last column
+ formats << "%-s"
+ else
+ formats << "%-#{maxima + 2}s"
+ end
end
formats[0] = formats[0].insert(0, " " * indent)
formats << "%s"
@@ -139,11 +144,16 @@
row.each_with_index do |column, i|
maxima = maximas[i]
if column.is_a?(Numeric)
- f = "%#{maxima}s "
+ if i == row.size - 1
+ # Don't output 2 trailing spaces when printing the last column
+ f = "%#{maxima}s"
+ else
+ f = "%#{maxima}s "
+ end
else
f = formats[i]
end
sentence << f % column.to_s
end
@@ -314,13 +324,30 @@
def unix?
RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
end
def truncate(string, width)
- if string.length <= width
- string
- else
- ( string[0, width-3] || "" ) + "..."
+ as_unicode do
+ chars = string.chars.to_a
+
+ if chars.length <= width
+ chars.join
+ else
+ ( chars[0, width-3].join ) + "..."
+ end
+ end
+ end
+
+ if "".respond_to?(:encode)
+ def as_unicode
+ yield
+ end
+ else
+ def as_unicode
+ old, $KCODE = $KCODE, "U"
+ yield
+ ensure
+ $KCODE = old
end
end
def ask_simply(statement, color = nil)
say("#{statement} ", color)