Sha256: ea7042802ffcd326c94a7d4ff14c8bbe314cf4083396890ab924a16c96b0bee6

Contents?: true

Size: 682 Bytes

Versions: 48

Compression:

Stored size: 682 Bytes

Contents

module Nanoc::CLI
  # A simple ANSI colorizer for strings. When given a string and a list of
  # attributes, it returns a colorized string.
  #
  # @api private
  module ANSIStringColorizer
    # TODO: complete mapping
    MAPPING = {
      bold: "\e[1m",
      red: "\e[31m",
      green: "\e[32m",
      yellow: "\e[33m",
      blue: "\e[34m",
    }.freeze

    # @param [String] s The string to colorize
    #
    # @param [Array] as An array of attributes from `MAPPING` to colorize the
    #   string with
    #
    # @return [String] A string colorized using the given attributes
    def self.c(s, *as)
      as.map { |a| MAPPING[a] }.join('') + s + "\e[0m"
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
nanoc-4.7.9 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.7.8 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.7.7 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.7.6 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.7.5 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.7.4 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.7.3 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.7.2 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.7.1 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.7.0 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.6.4 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.6.3 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.6.2 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.6.1 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.6.0 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.5.4 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.5.3 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.5.2 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.5.1 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-4.5.0 lib/nanoc/cli/ansi_string_colorizer.rb