Sha256: 0915cd5abae4e060e8e4c1158509a9b18e96ad68b174184a83e42c5d9e41fc62
Contents?: true
Size: 1 KB
Versions: 31
Compression:
Stored size: 1 KB
Contents
# -*- coding: utf-8 -*- # # frozen_string_literal: true module Rouge module Formatters class TerminalTruecolor < Terminal256 tag 'terminal_truecolor' class TruecolorEscapeSequence < Terminal256::EscapeSequence 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 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 end # @override def make_escape_sequence(style) TruecolorEscapeSequence.new(style) end end end end
Version data entries
31 entries across 31 versions & 2 rubygems