Module: Clack::Colors

Defined in:
lib/clack/colors.rb

Overview

ANSI color codes for terminal output styling.

Colors are enabled when Environment.colors_supported? says so: on a TTY that is not TERM=dumb, or anywhere when FORCE_COLOR is set to a non-empty value other than 0 / false. A non-empty NO_COLOR or FORCE_COLOR=0 disables them everywhere. When disabled every method returns the plain text unchanged.

Foreground Colors (standard) collapse

Text Styles collapse

Bright Foreground Colors (high contrast) collapse

Class Method Summary collapse

Class Method Details

.blue(text) ⇒ String

Apply blue foreground color (ANSI 34).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



48
# File 'lib/clack/colors.rb', line 48

def blue(text) = wrap(text, "34")

.bold(text) ⇒ String

Apply bold style (ANSI 1).

Parameters:

  • text (#to_s)

    text to style

Returns:

  • (String)

    ANSI-wrapped text



72
# File 'lib/clack/colors.rb', line 72

def bold(text) = wrap(text, "1")

.bright_blue(text) ⇒ String

Apply bright blue foreground color (ANSI 94).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



126
# File 'lib/clack/colors.rb', line 126

def bright_blue(text) = wrap(text, "94")

.bright_cyan(text) ⇒ String

Apply bright cyan foreground color (ANSI 96).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



106
# File 'lib/clack/colors.rb', line 106

def bright_cyan(text) = wrap(text, "96")

.bright_green(text) ⇒ String

Apply bright green foreground color (ANSI 92).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



111
# File 'lib/clack/colors.rb', line 111

def bright_green(text) = wrap(text, "92")

.bright_magenta(text) ⇒ String

Apply bright magenta foreground color (ANSI 95).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



131
# File 'lib/clack/colors.rb', line 131

def bright_magenta(text) = wrap(text, "95")

.bright_red(text) ⇒ String

Apply bright red foreground color (ANSI 91).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



121
# File 'lib/clack/colors.rb', line 121

def bright_red(text) = wrap(text, "91")

.bright_white(text) ⇒ String

Apply bright white foreground color (ANSI 97).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



136
# File 'lib/clack/colors.rb', line 136

def bright_white(text) = wrap(text, "97")

.bright_yellow(text) ⇒ String

Apply bright yellow foreground color (ANSI 93).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



116
# File 'lib/clack/colors.rb', line 116

def bright_yellow(text) = wrap(text, "93")

.cyan(text) ⇒ String

Apply cyan foreground color (ANSI 36).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



28
# File 'lib/clack/colors.rb', line 28

def cyan(text) = wrap(text, "36")

.dim(text) ⇒ String

Apply dim/faint style (ANSI 2).

Parameters:

  • text (#to_s)

    text to style

Returns:

  • (String)

    ANSI-wrapped text



67
# File 'lib/clack/colors.rb', line 67

def dim(text) = wrap(text, "2")

.enabled?Boolean

Whether ANSI styling is currently active for $stdout. Delegates to Environment.colors_supported? on every call.

Returns:

  • (Boolean)


16
# File 'lib/clack/colors.rb', line 16

def enabled? = Environment.colors_supported?

.gray(text) ⇒ String

Apply gray foreground color (ANSI 90).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



23
# File 'lib/clack/colors.rb', line 23

def gray(text) = wrap(text, "90")

.green(text) ⇒ String

Apply green foreground color (ANSI 32).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



33
# File 'lib/clack/colors.rb', line 33

def green(text) = wrap(text, "32")

.hidden(text) ⇒ String

Apply hidden/invisible style (ANSI 8).

Parameters:

  • text (#to_s)

    text to style

Returns:

  • (String)

    ANSI-wrapped text



97
# File 'lib/clack/colors.rb', line 97

def hidden(text) = wrap(text, "8")

.inverse(text) ⇒ String

Apply inverse/reverse video style (ANSI 7).

Parameters:

  • text (#to_s)

    text to style

Returns:

  • (String)

    ANSI-wrapped text



87
# File 'lib/clack/colors.rb', line 87

def inverse(text) = wrap(text, "7")

.italic(text) ⇒ String

Apply italic style (ANSI 3).

Parameters:

  • text (#to_s)

    text to style

Returns:

  • (String)

    ANSI-wrapped text



77
# File 'lib/clack/colors.rb', line 77

def italic(text) = wrap(text, "3")

.magenta(text) ⇒ String

Apply magenta foreground color (ANSI 35).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



53
# File 'lib/clack/colors.rb', line 53

def magenta(text) = wrap(text, "35")

.red(text) ⇒ String

Apply red foreground color (ANSI 31).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



43
# File 'lib/clack/colors.rb', line 43

def red(text) = wrap(text, "31")

.strikethrough(text) ⇒ String

Apply strikethrough style (ANSI 9).

Parameters:

  • text (#to_s)

    text to style

Returns:

  • (String)

    ANSI-wrapped text



92
# File 'lib/clack/colors.rb', line 92

def strikethrough(text) = wrap(text, "9")

.underline(text) ⇒ String

Apply underline style (ANSI 4).

Parameters:

  • text (#to_s)

    text to style

Returns:

  • (String)

    ANSI-wrapped text



82
# File 'lib/clack/colors.rb', line 82

def underline(text) = wrap(text, "4")

.white(text) ⇒ String

Apply white foreground color (ANSI 37).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



58
# File 'lib/clack/colors.rb', line 58

def white(text) = wrap(text, "37")

.yellow(text) ⇒ String

Apply yellow foreground color (ANSI 33).

Parameters:

  • text (#to_s)

    text to colorize

Returns:

  • (String)

    ANSI-wrapped text



38
# File 'lib/clack/colors.rb', line 38

def yellow(text) = wrap(text, "33")