Class: Rouge::Formatters::TerminalTruecolor::TruecolorEscapeSequence

Inherits:
Rouge::Formatters::Terminal256::EscapeSequence show all
Defined in:
lib/rouge/formatters/terminal_truecolor.rb

Instance Attribute Summary

Attributes inherited from Rouge::Formatters::Terminal256::EscapeSequence

#style

Instance Method Summary collapse

Methods inherited from Rouge::Formatters::Terminal256::EscapeSequence

#bg, #fg, #initialize, #reset_string, #stream_value, xterm_colors

Constructor Details

This class inherits a constructor from Rouge::Formatters::Terminal256::EscapeSequence

Instance Method Details

#get_rgb(color) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/rouge/formatters/terminal_truecolor.rb', line 19

def get_rgb(color)
  color = $1 if color =~ /#(\h+)/

  case color.size
  when 3 then color.chars.map { |c| c.to_i(16) * 2 }
  when 6 then color.scan(/../).map { |cc| cc.to_i(16) }
  else
    raise "invalid color: #{color.inspect}"
  end
end

#style_stringObject



9
10
11
12
13
14
15
16
17
# File 'lib/rouge/formatters/terminal_truecolor.rb', line 9

def style_string
  @style_string ||= begin
    out = String.new('')
    out << escape(['48', '2', *get_rgb(style.bg)]) if style.bg
    out << escape(['38', '2', *get_rgb(style.fg)]) if style.fg
    out << escape(['1']) if style[:bold] || style[:italic]
    out
  end
end