Skip to content

Commit 856ff52

Browse files
committed
Fix print_wrapped to properly parse "\x5" newline character
1 parent dd45079 commit 856ff52

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/thor/shell/basic.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,20 @@ def print_wrapped(message, options = {})
230230
paras = message.split("\n\n")
231231

232232
paras.map! do |unwrapped|
233-
unwrapped.strip.tr("\n", " ").squeeze(" ").gsub(/.{1,#{width}}(?:\s|\Z)/) { ($& + 5.chr).gsub(/\n\005/, "\n").gsub(/\005/, "\n") }
234-
end
233+
counter = 0
234+
unwrapped.split(" ").inject do |memo, word|
235+
word = word.gsub(/\n\005/, "\n").gsub(/\005/, "\n")
236+
counter = 0 if word.include? "\n"
237+
if (counter + word.length + indent) < width
238+
memo = "#{memo} #{word}"
239+
counter += word.length+indent
240+
else
241+
memo = "#{memo}\n#{word}"
242+
counter = word.length
243+
end
244+
memo
245+
end
246+
end.compact!
235247

236248
paras.each do |para|
237249
para.split("\n").each do |line|

lib/thor/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class Thor
2-
VERSION = "0.20.0"
2+
VERSION = "0.20.1"
33
end

0 commit comments

Comments
 (0)