Skip to content

Commit

Permalink
Merge pull request rails#616 from Choms/master
Browse files Browse the repository at this point in the history
Fix print_wrapped to properly parse "\x5" newline character
  • Loading branch information
rafaelfranca authored Sep 20, 2018
2 parents 7a36534 + f08570e commit 57fe753
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/thor/shell/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,20 @@ def print_wrapped(message, options = {})
paras = message.split("\n\n")

paras.map! do |unwrapped|
unwrapped.strip.tr("\n", " ").squeeze(" ").gsub(/.{1,#{width}}(?:\s|\Z)/) { ($& + 5.chr).gsub(/\n\005/, "\n").gsub(/\005/, "\n") }
end
counter = 0
unwrapped.split(" ").inject do |memo, word|
word = word.gsub(/\n\005/, "\n").gsub(/\005/, "\n")
counter = 0 if word.include? "\n"
if (counter + word.length + 1) < width
memo = "#{memo} #{word}"
counter += (word.length + 1)
else
memo = "#{memo}\n#{word}"
counter = word.length
end
memo
end
end.compact!

paras.each do |para|
para.split("\n").each do |line|
Expand Down

0 comments on commit 57fe753

Please sign in to comment.