Class: Terminal::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/terminal/renderer.rb

Constant Summary collapse

MEGABYTES =
1024 * 1024
ESCAPE_CONTROL_CHARACTERS =
"qQmKGgKAaBbCcDd".freeze
ESCAPE_CAPTURE_REGEX =
/\e\[(.*)([#{ESCAPE_CONTROL_CHARACTERS}])/
INTERESTING_PARTS_REGEX =
/[\n\r\b]|\e\[[\d;]*[#{ESCAPE_CONTROL_CHARACTERS}]|./

Instance Method Summary collapse

Constructor Details

#initialize(output, options = {}) ⇒ Renderer

Returns a new instance of Renderer.



15
16
17
18
19
# File 'lib/terminal/renderer.rb', line 15

def initialize(output, options = {})
  @output = output
  @options = options
  @screen = Screen.new
end

Instance Method Details

#renderObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/terminal/renderer.rb', line 21

def render
  return "" if @output.nil?

  output = @output.dup

  render_to_screen(output)

  # Convert the screen to a string
  output = convert_screen_to_string

  # Escape any HTML
  escaped_html = escape_html(output)

  # Now convert the colors to HTML
  convert_to_html!(escaped_html)

  escaped_html
end