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
:reek:Attribute.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#title ⇒ Object
:reek:Attribute.
Instance Method Summary collapse
- #add_header(key, value) ⇒ Object
-
#initialize(max_width: nil, width_func: nil) ⇒ TermPage
constructor
:reek:ControlParameter.
- #to_s ⇒ Object
Constructor Details
#initialize(max_width: nil, width_func: nil) ⇒ TermPage
:reek:ControlParameter
34 35 36 37 38 39 40 |
# File 'lib/codeless_code/renderers/term_page.rb', line 34 def initialize(max_width: nil, width_func: nil) @max_width = max_width @max_width ||= (width_func || TermWidth.new).call @headers = {} @key_width = 0 end |
Instance Attribute Details
#body ⇒ Object
:reek:Attribute
30 31 32 |
# File 'lib/codeless_code/renderers/term_page.rb', line 30 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
31 32 33 |
# File 'lib/codeless_code/renderers/term_page.rb', line 31 def headers @headers end |
#title ⇒ Object
:reek:Attribute
30 31 32 |
# File 'lib/codeless_code/renderers/term_page.rb', line 30 def title @title end |
Instance Method Details
#add_header(key, value) ⇒ Object
48 49 50 51 |
# File 'lib/codeless_code/renderers/term_page.rb', line 48 def add_header(key, value) @key_width = [@key_width, key.size].max @headers[key] = value end |
#to_s ⇒ Object
42 43 44 45 46 |
# File 'lib/codeless_code/renderers/term_page.rb', line 42 def to_s format(PAGER_FORMAT, title: title.center(width).rstrip, sep1: seperator('='), sep2: seperator('-'), headers: header_section, body: body) end |