Class: Thor::Shell::Basic

Inherits:
Object
  • Object
show all
Defined in:
lib/hodor/cli.rb

Overview

rubocop:disable ClassLength

Instance Method Summary collapse

Instance Method Details



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/hodor/cli.rb', line 122

def print_wrapped(message, options = {})
  indent = options[:indent] || 0
  width = terminal_width - indent - 5
  paras = message.split("\n\n")

  paras.map! do |unwrapped|
    unwrapped.strip.gsub(/\n([^\s\-\005])/, ' \1').gsub(/.{1,#{width}}(?:\s|\Z)/) {
      ($& + 5.chr).gsub(/\n\005/, "\n").gsub(/\005/, "\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