Class: Vedeu::Renderers::Escape
- Includes:
- Options
- Defined in:
- lib/vedeu/renderers/escape.rb
Overview
Converts a grid of Cells objects or Cells::Char objects into a stream of characters without escape sequences.
Instance Attribute Summary
Attributes included from Options
Instance Method Summary collapse
- #buffer ⇒ Array<String> private
-
#clear ⇒ String
Render a cleared output.
-
#content ⇒ String
private
Combine all characters in a row to produce a line, then all lines should be terminated with ‘n`.
- #escapable?(char) ⇒ Boolean private
- #renderable?(char) ⇒ Boolean private
- #renderables ⇒ Array<Class> private
Methods included from Options
#compression, #compression?, #default_template, #defaults, #end_row_tag, #end_tag, #filename, #initialize, #output, #output?, #render, #start_row_tag, #start_tag, #template, #timestamp, #timestamp?, #write, #write_file, #write_file?
Methods included from Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
Methods inherited from File
Instance Method Details
#buffer ⇒ Array<String> (private)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vedeu/renderers/escape.rb', line 37 def buffer empty = Array.new(Vedeu.height) { Array.new(Vedeu.width) { '[:cell]' } } output.each do |row| row.each do |char| next unless renderable?(char) && positionable?(char) && escapable?(char) empty[char.position.y - 1][char.position.x - 1] = char.to_ast end end empty end |
#clear ⇒ String
Render a cleared output.
18 19 20 |
# File 'lib/vedeu/renderers/escape.rb', line 18 def clear render('[[:clear]]') end |
#content ⇒ String (private)
Combine all characters in a row to produce a line, then all lines should be terminated with ‘n`. Convert to an array of UTF8 codepoints, and any codepoint above 255 should be converted to a space.
30 31 32 33 34 |
# File 'lib/vedeu/renderers/escape.rb', line 30 def content return '[[:empty]]' if string?(output) || absent?(output) buffer.map { |row| row.join("\n") }.join("\n\n") end |
#escapable?(char) ⇒ Boolean (private)
82 83 84 |
# File 'lib/vedeu/renderers/escape.rb', line 82 def escapable?(char) char.respond_to?(:to_ast) end |
#renderable?(char) ⇒ Boolean (private)
77 78 79 |
# File 'lib/vedeu/renderers/escape.rb', line 77 def renderable?(char) renderables.include?(char.class) end |
#renderables ⇒ Array<Class> (private)
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vedeu/renderers/escape.rb', line 54 def renderables [ Vedeu::Cells::Border, Vedeu::Cells::BottomHorizontal, Vedeu::Cells::BottomLeft, Vedeu::Cells::BottomRight, Vedeu::Cells::Corner, Vedeu::Cells::Char, Vedeu::Cells::Clear, Vedeu::Cells::Cursor, Vedeu::Cells::Empty, Vedeu::Cells::Escape, Vedeu::Cells::Horizontal, Vedeu::Cells::LeftVertical, Vedeu::Cells::RightVertical, Vedeu::Cells::TopHorizontal, Vedeu::Cells::TopLeft, Vedeu::Cells::TopRight, Vedeu::Cells::Vertical, ] end |