Sha256: 074affb6c499134fee34f7a51d4c47d9de51b10038c6df5e145366032773adc9

Contents?: true

Size: 698 Bytes

Versions: 24

Compression:

Stored size: 698 Bytes

Contents

# encoding: utf-8

module Nanoc::CLI

  # A simple ANSI colorizer for strings. When given a string and a list of
  # attributes, it returns a colorized string.
  module ANSIStringColorizer

    # TODO complete mapping
    MAPPING = {
      :bold   => "\e[1m",
      :red    => "\e[31m",
      :green  => "\e[32m",
      :yellow => "\e[33m",
      :blue   => "\e[34m"
    }

    # @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

24 entries across 24 versions & 1 rubygems

Version Path
nanoc-3.4.3 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-3.4.2 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-3.4.1 lib/nanoc/cli/ansi_string_colorizer.rb
nanoc-3.4.0 lib/nanoc/cli/ansi_string_colorizer.rb