Module: ActiveTracker::OutputHelper

Defined in:
app/helpers/active_tracker/output_helper.rb

Instance Method Summary collapse

Instance Method Details

#escape_ansi(data) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/active_tracker/output_helper.rb', line 3

def escape_ansi(data)
  { 1 => :nothing,
    2 => :nothing,
    4 => :nothing,
    5 => :nothing,
    7 => :nothing,
    30 => :black,
    31 => :red,
    32 => :green,
    33 => :yellow,
    34 => :blue,
    35 => :magenta,
    36 => :cyan,
    37 => :white,
    40 => :nothing,
    41 => :nothing,
    43 => :nothing,
    44 => :nothing,
    45 => :nothing,
    46 => :nothing,
    47 => :nothing,
  }.each do |key, value|
    if value != :nothing
      data.gsub!(/\e\[#{key}m/,"<span style=\"color:#{value}\">")
    else
      data.gsub!(/\e\[#{key}m/,"<span>")
    end
  end
  data.gsub!(/\e\[0m/,'</span>')
  return sanitize(data, tags: %w{span}, attributes: %w{style}).html_safe
end