class Rouge::Formatters::TerminalTruecolor::TruecolorEscapeSequence

Public Instance Methods

get_rgb(color) click to toggle source
# File lib/rouge/formatters/terminal_truecolor.rb, line 18
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_string() click to toggle source
# File lib/rouge/formatters/terminal_truecolor.rb, line 8
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