lib/thor/shell/basic.rb in thor-0.19.4 vs lib/thor/shell/basic.rb in thor-0.20.0
- old
+ new
@@ -1,8 +1,5 @@
-require "tempfile"
-require "io/console" if RUBY_VERSION > "1.9.2"
-
class Thor
module Shell
class Basic
attr_accessor :base
attr_reader :padding
@@ -108,11 +105,11 @@
status = status.to_s.rjust(12)
status = set_color status, color, true if color
buffer = "#{status}#{spaces}#{message}"
- buffer << "\n" unless buffer.end_with?("\n")
+ buffer = "#{buffer}\n" unless buffer.end_with?("\n")
stdout.print(buffer)
stdout.flush
end
@@ -163,11 +160,11 @@
formats = []
indent = options[:indent].to_i
colwidth = options[:colwidth]
options[:truncate] = terminal_width if options[:truncate] == true
- formats << "%-#{colwidth + 2}s" if colwidth
+ formats << "%-#{colwidth + 2}s".dup if colwidth
start = colwidth ? 1 : 0
colcount = array.max { |a, b| a.size <=> b.size }.size
maximas = []
@@ -175,21 +172,21 @@
start.upto(colcount - 1) do |index|
maxima = array.map { |row| row[index] ? row[index].to_s.size : 0 }.max
maximas << maxima
formats << if index == colcount - 1
# Don't output 2 trailing spaces when printing the last column
- "%-s"
+ "%-s".dup
else
- "%-#{maxima + 2}s"
+ "%-#{maxima + 2}s".dup
end
end
formats[0] = formats[0].insert(0, " " * indent)
formats << "%s"
array.each do |row|
- sentence = ""
+ sentence = "".dup
row.each_with_index do |column, index|
maxima = maximas[index]
f = if column.is_a?(Numeric)
@@ -253,10 +250,13 @@
%[Overwrite #{destination}? (enter "h" for help) #{options}],
:add_to_history => false
)
case answer
+ when nil
+ say ""
+ return true
when is?(:yes), is?(:force), ""
return true
when is?(:no), is?(:skip)
return false
when is?(:always)
@@ -348,10 +348,11 @@
end
def show_diff(destination, content) #:nodoc:
diff_cmd = ENV["THOR_DIFF"] || ENV["RAILS_DIFF"] || "diff -u"
+ require "tempfile"
Tempfile.open(File.basename(destination), File.dirname(destination)) do |temp|
temp.write content
temp.rewind
system %(#{diff_cmd} "#{destination}" "#{temp.path}")
end
@@ -409,10 +410,10 @@
message = prepare_message(message, *color)
result = Thor::LineEditor.readline(message, options)
return unless result
- result.strip!
+ result = result.strip
if default && result == ""
default
else
result