print_wrapped(message, options = {})
public
Prints a long string, word-wrapping the text to the current width of the
terminal display. Ideal for printing heredocs.
String
indent |
Indent each line of the printed paragraph by indent value.
|
# File lib/bundler/vendor/thor/lib/thor/shell/basic.rb, line 219
def print_wrapped(message, options = {})
indent = options[:indent] || 0
width = terminal_width - indent
paras = message.split("\n\n")
paras.map! do |unwrapped|
unwrapped.strip.tr("\n", " ").squeeze(" ").gsub(/.{1,#{width}}(?:\s|\Z)/) { ($& + 5.chr).gsub(/\n\0005/, "\n").gsub(/\0005/, "\n") }
end
paras.each do |para|
para.split("\n").each do |line|
stdout.puts line.insert(0, " " * indent)
end
stdout.puts unless para == paras.last
end
end