Module: Nanoc::CLI::ANSIStringColorizer

Defined in:
lib/nanoc/cli/ansi_string_colorizer.rb

Overview

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

Constant Summary

MAPPING =

TODO complete mapping

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

Class Method Summary (collapse)

Class Method Details

+ (String) c(s, *as)

Returns A string colorized using the given attributes

Parameters:

  • s (String)

    The string to colorize

  • as (Array)

    An array of attributes from MAPPING to colorize the string with

Returns:

  • (String)

    A string colorized using the given attributes



24
25
26
# File 'lib/nanoc/cli/ansi_string_colorizer.rb', line 24

def self.c(s, *as)
  as.map { |a| MAPPING[a] }.join('') + s + "\e[0m"
end