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

Version Path
rouge-4.5.1 lib/rouge/formatters/terminal_truecolor.rb
rouge-4.5.0 lib/rouge/formatters/terminal_truecolor.rb
rouge-4.4.0 lib/rouge/formatters/terminal_truecolor.rb
rouge-4.3.0 lib/rouge/formatters/terminal_truecolor.rb
rouge-4.2.1 lib/rouge/formatters/terminal_truecolor.rb
rouge-4.2.0 lib/rouge/formatters/terminal_truecolor.rb
rouge-4.1.3 lib/rouge/formatters/terminal_truecolor.rb
rouge-4.1.2 lib/rouge/formatters/terminal_truecolor.rb
rouge-4.1.1 lib/rouge/formatters/terminal_truecolor.rb
mumukit-content-type-1.12.1 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/formatters/terminal_truecolor.rb
mumukit-content-type-1.12.0 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/formatters/terminal_truecolor.rb
rouge-4.1.0 lib/rouge/formatters/terminal_truecolor.rb
rouge-4.0.1 lib/rouge/formatters/terminal_truecolor.rb
rouge-4.0.0 lib/rouge/formatters/terminal_truecolor.rb
rouge-3.30.0 lib/rouge/formatters/terminal_truecolor.rb
rouge-3.29.0 lib/rouge/formatters/terminal_truecolor.rb
rouge-3.28.0 lib/rouge/formatters/terminal_truecolor.rb
rouge-3.27.0 lib/rouge/formatters/terminal_truecolor.rb
rouge-3.26.1 lib/rouge/formatters/terminal_truecolor.rb
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/formatters/terminal_truecolor.rb