Class: Clamp::Help::Builder

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

Overview

Hack to make clamp usage less of a pain to get long lines to fit within a standard terminal width

Instance Method Summary collapse

Instance Method Details

#stringObject



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/simplygenius/atmos/cli.rb', line 245

def string
  line_width = 79
  indent_size = 4
  indent = " " * indent_size
  StringIO.new.tap do |out|
    lines.each do |line|
      case line
      when Array
        out << indent
        out.puts(line[0])
        formatted_line = line[1].gsub(/\((default|required)/, "\n\\0")
        word_wrap(formatted_line, line_width: (line_width - indent_size * 2)).each do |l|
          out << (indent * 2)
          out.puts(l)
        end
      else
        out.puts(line)
      end
    end
  end.string
end

#word_wrap(text, line_width:) ⇒ Object



239
240
241
242
243
# File 'lib/simplygenius/atmos/cli.rb', line 239

def word_wrap(text, line_width:)
  text.split("\n").collect do |line|
    line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip.split("\n") : line
  end.flatten
end