Class: Terminal::Renderer

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

Constant Summary collapse

MEGABYTES =
1024 * 1024
EMOJI_UNICODE_REGEXP =
/[\u{1f600}-\u{1f64f}]|[\u{2702}-\u{27b0}]|[\u{1f680}-\u{1f6ff}]|[\u{24C2}-\u{1F251}]|[\u{1f300}-\u{1f5ff}]/
EMOJI_IGNORE =
[ "heavy_check_mark".freeze, "heavy_multiplication_x".freeze ]
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.



19
20
21
22
23
24
25
26
# File 'lib/terminal/renderer.rb', line 19

def initialize(output, options = {})
  @output = output

  @options = options
  @options[:emoji_asset_path] ||= "/assets/emojis"

  @screen = Screen.new
end

Instance Method Details

#renderObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/terminal/renderer.rb', line 28

def render
  return "" if @output.nil?

  # Don't allow parsing of outputs longer than 4 meg
  output = dup_check_and_chomp_length(@output)

  # Force encoding on the output first
  force_encoding!(output)

  # Now do the render the output to the screen
  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)

  # And emojify
  replace_unicode_with_emoji!(escaped_html)

  escaped_html
end