Class: Choosy::Printing::ManpagePrinter
- Inherits:
-
BasePrinter
- Object
- BasePrinter
- Choosy::Printing::ManpagePrinter
- Defined in:
- lib/choosy/printing/manpage_printer.rb
Constant Summary
Constants included from Terminal
Terminal::DEFAULT_COLUMN_COUNT, Terminal::DEFAULT_LINE_COUNT
Instance Attribute Summary collapse
-
#manpage ⇒ Object
readonly
Returns the value of attribute manpage.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#synopsis ⇒ Object
readonly
Returns the value of attribute synopsis.
Attributes inherited from BasePrinter
#formatting_options, #heading_styles, #indent, #offset, #option_styles
Attributes included from Terminal
Instance Method Summary collapse
- #format_command(command, formatted_command, indent) ⇒ Object
- #format_element(item) ⇒ Object
- #format_epilogue(command) ⇒ Object
- #format_name(command) ⇒ Object
- #format_option(option, formatted_option, indent) ⇒ Object
- #format_prologue(command) ⇒ Object
- #format_synopsis(command) ⇒ Object
-
#initialize(options = {}) ⇒ ManpagePrinter
constructor
A new instance of ManpagePrinter.
- #print!(command) ⇒ Object
Methods inherited from BasePrinter
#command_name, #format!, #line_count, #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 = {}) ⇒ ManpagePrinter
Returns a new instance of ManpagePrinter.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/choosy/printing/manpage_printer.rb', line 5 def initialize(={}) super() @name = [:name] || "NAME" @synopsis = [:synopsis] || 'SYNOPSIS' @manpage = Manpage.new @manpage.section = [:section] || 1 @manpage.date = [:date] @manpage.manual = [:manual] @manpage.version = [:version] end |
Instance Attribute Details
#manpage ⇒ Object (readonly)
Returns the value of attribute manpage.
3 4 5 |
# File 'lib/choosy/printing/manpage_printer.rb', line 3 def manpage @manpage end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/choosy/printing/manpage_printer.rb', line 3 def name @name end |
#synopsis ⇒ Object (readonly)
Returns the value of attribute synopsis.
3 4 5 |
# File 'lib/choosy/printing/manpage_printer.rb', line 3 def synopsis @synopsis end |
Instance Method Details
#format_command(command, formatted_command, indent) ⇒ Object
65 66 67 |
# File 'lib/choosy/printing/manpage_printer.rb', line 65 def format_command(command, formatted_command, indent) @manpage.term_paragraph(@manpage.format.italics(formatted_command), command.summary || "", indent.length) end |
#format_element(item) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/choosy/printing/manpage_printer.rb', line 69 def format_element(item) if item.header? @manpage.section_heading(item.value) else @manpage.paragraph(item.value) end end |
#format_epilogue(command) ⇒ Object
77 78 79 |
# File 'lib/choosy/printing/manpage_printer.rb', line 77 def format_epilogue(command) @manpage.to_s end |
#format_name(command) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/choosy/printing/manpage_printer.rb', line 45 def format_name(command) if command.summary @manpage.section_heading(@name) @manpage.text("#{command.name} - #{command.summary}") end end |
#format_option(option, formatted_option, indent) ⇒ Object
61 62 63 |
# File 'lib/choosy/printing/manpage_printer.rb', line 61 def format_option(option, formatted_option, indent) @manpage.term_paragraph(formatted_option, option.description, indent.length) end |
#format_prologue(command) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/choosy/printing/manpage_printer.rb', line 29 def format_prologue(command) @manpage.column_width = columns @manpage.name = command_name(command) version_option = command.option_builders[Choosy::DSL::OptionBuilder::VERSION] if version_option && @manpage.version.nil? begin version_option.entity.validation_step.call(nil, nil) rescue Choosy::VersionCalled => e @manpage.version = e. end end format_name(command) format_synopsis(command) end |
#format_synopsis(command) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/choosy/printing/manpage_printer.rb', line 52 def format_synopsis(command) @manpage.section_heading(@synopsis) @manpage.nofill do |man| usage_wrapped(command, '', columns).each do |line| man.text line end end end |
#print!(command) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/choosy/printing/manpage_printer.rb', line 18 def print!(command) if command_exists?('groff') && pager? fix_termcap page format!(command), 'groff -t -e -W all -Tutf8 -mandoc' else # Fall back to a help printer if there is no pager help = HelpPrinter.new() help.print!(command) end end |