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
-
.blue(text) ⇒ String
Apply blue foreground color (ANSI 34).
-
.cyan(text) ⇒ String
Apply cyan foreground color (ANSI 36).
-
.gray(text) ⇒ String
Apply gray foreground color (ANSI 90).
-
.green(text) ⇒ String
Apply green foreground color (ANSI 32).
-
.magenta(text) ⇒ String
Apply magenta foreground color (ANSI 35).
-
.red(text) ⇒ String
Apply red foreground color (ANSI 31).
-
.white(text) ⇒ String
Apply white foreground color (ANSI 37).
-
.yellow(text) ⇒ String
Apply yellow foreground color (ANSI 33).
Text Styles collapse
-
.bold(text) ⇒ String
Apply bold style (ANSI 1).
-
.dim(text) ⇒ String
Apply dim/faint style (ANSI 2).
-
.hidden(text) ⇒ String
Apply hidden/invisible style (ANSI 8).
-
.inverse(text) ⇒ String
Apply inverse/reverse video style (ANSI 7).
-
.italic(text) ⇒ String
Apply italic style (ANSI 3).
-
.strikethrough(text) ⇒ String
Apply strikethrough style (ANSI 9).
-
.underline(text) ⇒ String
Apply underline style (ANSI 4).
Bright Foreground Colors (high contrast) collapse
-
.bright_blue(text) ⇒ String
Apply bright blue foreground color (ANSI 94).
-
.bright_cyan(text) ⇒ String
Apply bright cyan foreground color (ANSI 96).
-
.bright_green(text) ⇒ String
Apply bright green foreground color (ANSI 92).
-
.bright_magenta(text) ⇒ String
Apply bright magenta foreground color (ANSI 95).
-
.bright_red(text) ⇒ String
Apply bright red foreground color (ANSI 91).
-
.bright_white(text) ⇒ String
Apply bright white foreground color (ANSI 97).
-
.bright_yellow(text) ⇒ String
Apply bright yellow foreground color (ANSI 93).
Class Method Summary collapse
-
.enabled? ⇒ Boolean
Whether ANSI styling is currently active for
$stdout.
Class Method Details
.blue(text) ⇒ String
Apply blue foreground color (ANSI 34).
48 |
# File 'lib/clack/colors.rb', line 48 def blue(text) = wrap(text, "34") |
.bold(text) ⇒ String
Apply bold style (ANSI 1).
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).
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).
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).
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).
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).
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).
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).
116 |
# File 'lib/clack/colors.rb', line 116 def bright_yellow(text) = wrap(text, "93") |
.cyan(text) ⇒ String
Apply cyan foreground color (ANSI 36).
28 |
# File 'lib/clack/colors.rb', line 28 def cyan(text) = wrap(text, "36") |
.dim(text) ⇒ String
Apply dim/faint style (ANSI 2).
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.
16 |
# File 'lib/clack/colors.rb', line 16 def enabled? = Environment.colors_supported? |
.gray(text) ⇒ String
Apply gray foreground color (ANSI 90).
23 |
# File 'lib/clack/colors.rb', line 23 def gray(text) = wrap(text, "90") |
.green(text) ⇒ String
Apply green foreground color (ANSI 32).
33 |
# File 'lib/clack/colors.rb', line 33 def green(text) = wrap(text, "32") |
.hidden(text) ⇒ String
Apply hidden/invisible style (ANSI 8).
97 |
# File 'lib/clack/colors.rb', line 97 def hidden(text) = wrap(text, "8") |
.inverse(text) ⇒ String
Apply inverse/reverse video style (ANSI 7).
87 |
# File 'lib/clack/colors.rb', line 87 def inverse(text) = wrap(text, "7") |
.italic(text) ⇒ String
Apply italic style (ANSI 3).
77 |
# File 'lib/clack/colors.rb', line 77 def italic(text) = wrap(text, "3") |
.magenta(text) ⇒ String
Apply magenta foreground color (ANSI 35).
53 |
# File 'lib/clack/colors.rb', line 53 def magenta(text) = wrap(text, "35") |
.red(text) ⇒ String
Apply red foreground color (ANSI 31).
43 |
# File 'lib/clack/colors.rb', line 43 def red(text) = wrap(text, "31") |
.strikethrough(text) ⇒ String
Apply strikethrough style (ANSI 9).
92 |
# File 'lib/clack/colors.rb', line 92 def strikethrough(text) = wrap(text, "9") |
.underline(text) ⇒ String
Apply underline style (ANSI 4).
82 |
# File 'lib/clack/colors.rb', line 82 def underline(text) = wrap(text, "4") |
.white(text) ⇒ String
Apply white foreground color (ANSI 37).
58 |
# File 'lib/clack/colors.rb', line 58 def white(text) = wrap(text, "37") |
.yellow(text) ⇒ String
Apply yellow foreground color (ANSI 33).
38 |
# File 'lib/clack/colors.rb', line 38 def yellow(text) = wrap(text, "33") |