Sha256: 42f14ae109d4f7c1b9057ed49a2b101dbebc0b12a87346c9b52e057e088f5dc8

Contents?: true

Size: 1.54 KB

Versions: 16

Compression:

Stored size: 1.54 KB

Contents

# Frozen-string-literal: true
# Copyright: 2015 Jekyll - MIT License
# Encoding: utf-8

module Jekyll
  module Utils
    module Ansi
      extend self

      ESCAPE = format("%c", 27)
      MATCH = /#{ESCAPE}\[(?:\d+)(?:;\d+)*(j|k|m|s|u|A|B|G)|\e\(B\e\[m/ix.freeze
      COLORS = {
        :red => 31,
        :green => 32,
        :black => 30,
        :magenta => 35,
        :yellow => 33,
        :white => 37,
        :blue => 34,
        :cyan => 36
      }

      # Strip ANSI from the current string.  It also strips cursor stuff,
      # well some of it, and it also strips some other stuff that a lot of
      # the other ANSI strippers don't.

      def strip(str)
        str.gsub MATCH, ""
      end

      #

      def has?(str)
        !!(str =~ MATCH)
      end

      # Reset the color back to the default color so that you do not leak any
      # colors when you move onto the next line. This is probably normally
      # used as part of a wrapper so that we don't leak colors.

      def reset(str = "")
        @ansi_reset ||= format("%c[0m", 27)
        "#{@ansi_reset}#{str}"
      end

      # SEE: `self::COLORS` for a list of methods.  They are mostly
      # standard base colors supported by pretty much any xterm-color, we do
      # not need more than the base colors so we do not include them.
      # Actually... if I'm honest we don't even need most of the
      # base colors.

      COLORS.each do |color, num|
        define_method color do |str|
          "#{format("%c", 27)}[#{num}m#{str}#{reset}"
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
blackboard-3.1.9 lib/jekyll/utils/ansi.rb
blackboard-3.1.8 lib/jekyll/utils/ansi.rb
blackboard-3.1.7 lib/jekyll/utils/ansi.rb
jekyll-3.2.0.pre.beta1 lib/jekyll/utils/ansi.rb
jekyll-3.1.6 lib/jekyll/utils/ansi.rb
jekyll-3.1.5 lib/jekyll/utils/ansi.rb
jekyll-3.1.4 lib/jekyll/utils/ansi.rb
jekyll-3.1.3 lib/jekyll/utils/ansi.rb
jekyll-3.1.2 lib/jekyll/utils/ansi.rb
jekyllplusadmin-1.1.0 lib/jekyll/utils/ansi.rb
jekyllplusadmin-1.0.0 lib/jekyll/utils/ansi.rb
jekyll-3.1.1 lib/jekyll/utils/ansi.rb
jekyll-3.1.0 lib/jekyll/utils/ansi.rb
jekyll-3.1.0.pre.rc3 lib/jekyll/utils/ansi.rb
jekyll-3.1.0.pre.rc2 lib/jekyll/utils/ansi.rb
jekyll-3.1.0.pre.rc1 lib/jekyll/utils/ansi.rb