module Ougai::Formatters::Colors
List of useful ANSI escape sequences for terminal font formatting. Source is gist.github.com/chrisopedia/8754917.
Constants
- BG_BLACK
Background black color
- BG_BLUE
Background blue color
- BG_CYAN
Background cyan color
- BG_GREEN
Background green color
- BG_PURPLE
Background purple color
- BG_RED
Background red color
- BG_WHITE
Background white color
- BG_YELLOW
Background yellow color
- BLACK
Font black color
- BLUE
Font blue color
- BOLD_BLUE
Font bright/bold blue color
- BOLD_CYAN
Font bright/bold cyan color
- BOLD_GREEN
Font bright/bold green color
- BOLD_PURPLE
Font bright/bold purple color
- BOLD_RED
Font bright/bold red color
- BOLD_WHITE
Font bright/bold white color
- BOLD_YELLOW
Font bright/bold yellow color
- CYAN
Font cyan color
- GREEN
Font green color
- PURPLE
Font purple color
- RED
Font red color
- RESET
Reset formatting. To be appended after every formatted text
- WHITE
Font white color
- YELLOW
Font yello color
Public Class Methods
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.
@param [String] color color to prepend. Color can be from the list
above or have a complete custom String value depending on the terminal. If +nil+, text is not modified.
@param [String] text text to be colored @param [String] reset reset font styling escape sequence
@return [String] colored or uncolored text
# 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