Module: Hanami::Utils::ShellColor

Defined in:
gems/gems/hanami-utils-1.2.0/lib/hanami/utils/shell_color.rb,
gems/gems/hanami-utils-1.3.6/lib/hanami/utils/shell_color.rb

Overview

Shell helper for colorizing STDOUT

It doesn't check if you're writing to a file or anything, so you have to check that yourself before using this module.

Since:

  • 1.2.0

Defined Under Namespace

Classes: UnknownColorCodeError

Class Method Summary collapse

Class Method Details

.call(input, color:) ⇒ String

Colorizes output 8 colors available: black, red, green, yellow, blue, magenta, cyan, and gray

Parameters:

  • input (#to_s)

    the string to colorize

  • color (Symbol)

    the color

Returns:

  • (String)

    the colorized string

Raises:

  • (Hanami::Utils::ShellColor::UnknownColorError)

    if the color code is unknown

Since:

  • 1.2.0

def self.call(input, color:)
  "\e[#{color_code(color)}m#{input}\e[0m"
end