Module: TTY::Option::UsageWrapper
- Included in:
- AggregateErrors, Formatter
- Defined in:
- lib/tty/option/usage_wrapper.rb
Class Method Summary collapse
-
.wrap(text, width: 80, indent: 2, indent_first: false) ⇒ Object
Wrap a string to a maximum width with indentation.
Class Method Details
.wrap(text, width: 80, indent: 2, indent_first: false) ⇒ Object
Wrap a string to a maximum width with indentation
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tty/option/usage_wrapper.rb', line 14 def wrap(text, width: 80, indent: 2, indent_first: false) wrap = width - indent lines = [] indentation = " " * indent line, rest = *next_line(text, wrap: wrap) lines << (indent_first ? indentation : "") + line while !rest.nil? line, rest = *next_line(rest, wrap: wrap) lines << indentation + line.strip end lines.join("\n") end |