Class: CodelessCode::Renderers::TermPage
- Inherits:
-
Object
- Object
- CodelessCode::Renderers::TermPage
- Defined in:
- lib/codeless_code/renderers/term_page.rb
Overview
Attempts to format the output for the PAGER such that it fits within the bounds of the terminal window.
Constant Summary collapse
- PAGER_FORMAT =
[ '%<title>s', '%<sep1>s', '%<headers>s', '%<sep2>s', '', '%<body>s' ].join("\n").freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #add_header(key, value) ⇒ Object
-
#initialize(max_width: nil) ⇒ TermPage
constructor
A new instance of TermPage.
- #to_s ⇒ Object
Constructor Details
#initialize(max_width: nil) ⇒ TermPage
Returns a new instance of TermPage.
29 30 31 32 33 |
# File 'lib/codeless_code/renderers/term_page.rb', line 29 def initialize(max_width: nil) @max_width = max_width || term_width @headers = {} @key_width = 0 end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
27 28 29 |
# File 'lib/codeless_code/renderers/term_page.rb', line 27 def body @body end |
#title ⇒ Object
Returns the value of attribute title.
27 28 29 |
# File 'lib/codeless_code/renderers/term_page.rb', line 27 def title @title end |
Instance Method Details
#add_header(key, value) ⇒ Object
41 42 43 44 |
# File 'lib/codeless_code/renderers/term_page.rb', line 41 def add_header(key, value) @key_width = [@key_width, key.size].max @headers[key] = value end |
#to_s ⇒ Object
35 36 37 38 39 |
# File 'lib/codeless_code/renderers/term_page.rb', line 35 def to_s format(PAGER_FORMAT, title: title.center(width), sep1: seperator('='), sep2: seperator('-'), headers: header_section, body: body) end |