Module: Ougai::Formatters::Colors
- Defined in:
- lib/ougai/formatters/colors.rb,
lib/ougai/formatters/colors/configuration.rb
Overview
List of useful ANSI escape sequences for terminal font formatting. Source is gist.github.com/chrisopedia/8754917.
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- RESET =
Reset formatting. To be appended after every formatted text
"\e[0m"
- BLACK =
Font black color
"\e[30m"
- RED =
Font red color
"\e[31m"
- GREEN =
Font green color
"\e[32m"
- YELLOW =
Font yello color
"\e[33m"
- BLUE =
Font blue color
"\e[34m"
- PURPLE =
Font purple color
"\e[35m"
- CYAN =
Font cyan color
"\e[36m"
- WHITE =
Font white color
"\e[37m"
- BOLD_RED =
Font bright/bold red color
"\e[1;31m"
- BOLD_GREEN =
Font bright/bold green color
"\e[1;32m"
- BOLD_YELLOW =
Font bright/bold yellow color
"\e[1;33m"
- BOLD_BLUE =
Font bright/bold blue color
"\e[1;34m"
- BOLD_PURPLE =
Font bright/bold purple color
"\e[1;35m"
- BOLD_CYAN =
Font bright/bold cyan color
"\e[1;36m"
- BOLD_WHITE =
Font bright/bold white color
"\e[1;37m"
- BG_BLACK =
Background black color
"\e[40m"
- BG_RED =
Background red color
"\e[41m"
- BG_GREEN =
Background green color
"\e[42m"
- BG_YELLOW =
Background yellow color
"\e[43m"
- BG_BLUE =
Background blue color
"\e[44m"
- BG_PURPLE =
Background purple color
"\e[45m"
- BG_CYAN =
Background cyan color
"\e[46m"
- BG_WHITE =
Background white color
"\e[47m"
Class Method Summary collapse
-
.color_text(color, text, reset = Ougai::Formatters::Colors::RESET) ⇒ String
Color a text by prepending a font styling escape sequence and appending a reset sequence.
Class Method Details
.color_text(color, text, reset = Ougai::Formatters::Colors::RESET) ⇒ String
Color a text by prepending a font styling escape sequence and appending a reset sequence. This method does a pure String concatenation and does not check the values are properly escaped. This allows customization, depending on user’s terminal, to use custom escape sequences.
80 81 82 83 84 85 86 |
# File 'lib/ougai/formatters/colors.rb', line 80 def color_text(color, text, reset = Ougai::Formatters::Colors::RESET) return text if color.nil? # .concat is preferred in Ruby: # https://coderwall.com/p/ac5j9g/or-concat-what-is-faster-for-appending-string-in-ruby ''.dup.concat(color).concat(text).concat(reset) end |