Module: Ace::Support::Items::Atoms::AnsiColors
- Defined in:
- lib/ace/support/items/atoms/ansi_colors.rb
Overview
Simple ANSI color helpers for terminal output. Automatically skips color codes when stdout is not a TTY.
Constant Summary collapse
- RED =
"\e[31m"- GREEN =
"\e[32m"- YELLOW =
"\e[33m"- CYAN =
"\e[36m"- DIM =
"\e[2m"- BOLD =
"\e[1m"- RESET =
"\e[0m"
Class Method Summary collapse
-
.colorize(text, color_code) ⇒ String
Wrap text in ANSI color codes.
-
.tty? ⇒ Boolean
Whether stdout is a TTY.
Class Method Details
.colorize(text, color_code) ⇒ String
Wrap text in ANSI color codes. Returns plain text when stdout is not a TTY.
23 24 25 26 27 |
# File 'lib/ace/support/items/atoms/ansi_colors.rb', line 23 def self.colorize(text, color_code) return text unless tty? "#{color_code}#{text}#{RESET}" end |
.tty? ⇒ Boolean
Returns Whether stdout is a TTY.
30 31 32 |
# File 'lib/ace/support/items/atoms/ansi_colors.rb', line 30 def self.tty? $stdout.tty? end |