Class: Choosy::Printing::HelpPrinter
- Inherits:
-
BasePrinter
- Object
- BasePrinter
- Choosy::Printing::HelpPrinter
- Defined in:
- lib/choosy/printing/help_printer.rb
Direct Known Subclasses
Constant Summary
Constants included from Terminal
Terminal::DEFAULT_COLUMN_COUNT, Terminal::DEFAULT_LINE_COUNT
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#line_count ⇒ Object
readonly
Returns the value of attribute line_count.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Attributes inherited from BasePrinter
#formatting_options, #heading_styles, #indent, #offset, #option_styles
Attributes included from Terminal
Instance Method Summary collapse
- #format_command(command, formatted_prefix, cmd_indent) ⇒ Object
- #format_element(element) ⇒ Object
- #format_epilogue(command) ⇒ Object
- #format_header(str, styles = nil) ⇒ Object
- #format_option(option, formatted_prefix, opt_indent) ⇒ Object
- #format_prologue(command) ⇒ Object
-
#initialize(options) ⇒ HelpPrinter
constructor
A new instance of HelpPrinter.
- #print!(command) ⇒ Object
Methods inherited from BasePrinter
#command_name, #format!, #regular_option, #usage_option, #usage_wrapped
Methods included from Terminal
#color, #command_exists?, die, #die, #page, #pager, #pager?, #pipe_in, #pipe_out, #stdin?, #unformatted
Constructor Details
#initialize(options) ⇒ HelpPrinter
Returns a new instance of HelpPrinter.
5 6 7 8 9 10 11 12 |
# File 'lib/choosy/printing/help_printer.rb', line 5 def initialize() super() @buffer = [:buffer] || "" @usage = [:usage] || 'Usage:' @line_count = 0 end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
3 4 5 |
# File 'lib/choosy/printing/help_printer.rb', line 3 def buffer @buffer end |
#line_count ⇒ Object (readonly)
Returns the value of attribute line_count.
3 4 5 |
# File 'lib/choosy/printing/help_printer.rb', line 3 def line_count @line_count end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
3 4 5 |
# File 'lib/choosy/printing/help_printer.rb', line 3 def usage @usage end |
Instance Method Details
#format_command(command, formatted_prefix, cmd_indent) ⇒ Object
58 59 60 61 |
# File 'lib/choosy/printing/help_printer.rb', line 58 def format_command(command, formatted_prefix, cmd_indent) write_prefix(formatted_prefix, cmd_indent) write_lines(command.summary, cmd_indent, false) end |
#format_element(element) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/choosy/printing/help_printer.rb', line 39 def format_element(element) if element.value.nil? nl elsif element.header? nl if @buffer[-2,1] != "\n" format_header(element.value, element.styles) nl nl else write_lines(element.value, indent, true) nl end end |
#format_epilogue(command) ⇒ Object
34 35 36 37 |
# File 'lib/choosy/printing/help_printer.rb', line 34 def format_epilogue(command) nl @buffer end |
#format_header(str, styles = nil) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/choosy/printing/help_printer.rb', line 63 def format_header(str, styles=nil) return if str.nil? if styles && !styles.empty? @buffer << color.multiple(str, styles) else @buffer << color.multiple(str, heading_styles) end end |
#format_option(option, formatted_prefix, opt_indent) ⇒ Object
53 54 55 56 |
# File 'lib/choosy/printing/help_printer.rb', line 53 def format_option(option, formatted_prefix, opt_indent) write_prefix(formatted_prefix, opt_indent) write_lines(option.description, opt_indent, false) end |
#format_prologue(command) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/choosy/printing/help_printer.rb', line 23 def format_prologue(command) format_header(@usage) @buffer << ' ' indent = ' ' * (@usage.length + 1) usage_wrapped(command, indent, columns).each do |line| @buffer << line nl end nl end |
#print!(command) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/choosy/printing/help_printer.rb', line 14 def print!(command) format!(command) if @line_count > lines page(@buffer) else puts @buffer end end |