Class: Bundler::Thor::Shell::Color
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Basic
|
|
Instance Chain:
self,
Basic
|
|
Inherits: |
Bundler::Thor::Shell::Basic
|
Defined in: | lib/bundler/vendor/thor/lib/thor/shell/color.rb |
Overview
Constant Summary
-
BLACK =
Set the terminal’s foreground ANSI color to black.
"\e[30m"
-
BLUE =
Set the terminal’s foreground ANSI color to blue.
"\e[34m"
-
BOLD =
The start of an ANSI bold sequence.
"\e[1m"
-
CLEAR =
Embed in a String to clear all previous ANSI sequences.
"\e[0m"
-
CYAN =
Set the terminal’s foreground ANSI color to cyan.
"\e[36m"
-
GREEN =
Set the terminal’s foreground ANSI color to green.
"\e[32m"
-
MAGENTA =
Set the terminal’s foreground ANSI color to magenta.
"\e[35m"
-
ON_BLACK =
Set the terminal’s background ANSI color to black.
"\e[40m"
-
ON_BLUE =
Set the terminal’s background ANSI color to blue.
"\e[44m"
-
ON_CYAN =
Set the terminal’s background ANSI color to cyan.
"\e[46m"
-
ON_GREEN =
Set the terminal’s background ANSI color to green.
"\e[42m"
-
ON_MAGENTA =
Set the terminal’s background ANSI color to magenta.
"\e[45m"
-
ON_RED =
Set the terminal’s background ANSI color to red.
"\e[41m"
-
ON_WHITE =
Set the terminal’s background ANSI color to white.
"\e[47m"
-
ON_YELLOW =
Set the terminal’s background ANSI color to yellow.
"\e[43m"
-
RED =
Set the terminal’s foreground ANSI color to red.
"\e[31m"
-
WHITE =
Set the terminal’s foreground ANSI color to white.
"\e[37m"
-
YELLOW =
Set the terminal’s foreground ANSI color to yellow.
"\e[33m"
Class Method Summary
Instance Attribute Summary
- #are_colors_disabled? ⇒ Boolean readonly protected
- #are_colors_supported? ⇒ Boolean readonly protected
- #can_display_colors? ⇒ Boolean readonly protected
Basic
- Inherited
Instance Method Summary
-
#set_color(string, *colors)
Set color by using a string or one of the defined constants.
Basic
- Inherited
#ask | Asks something to the user and receives a response. |
#error | Called if something goes wrong during the execution. |
#file_collision | Deals with file collision and returns true if the file should be overwritten and false otherwise. |
#indent | Sets the output padding while executing a block and resets it. |
#no? | Asks the user a question and returns true if the user replies “n” or “no”. |
#print_in_columns | Prints values in columns. |
#print_table | Prints a table. |
#print_wrapped | Prints a long string, word-wrapping the text to the current width of the terminal display. |
#say | Say (print) something to the user. |
#say_error | Say (print) an error to the user. |
#say_status | Say a status with the given color and appends the message. |
#yes? | Asks the user a question and returns true if the user replies “y” or “yes”. |
#answer_match, #ask_filtered, #ask_simply, #lookup_color, #prepare_message, #stderr, #stdout, | |
#set_color | Apply color to the given string with optional bold. |
#file_collision_help, #git_merge_tool, #is?, #merge, #merge_tool, #show_diff |
Constructor Details
This class inherits a constructor from Bundler::Thor::Shell::Basic
Instance Attribute Details
#are_colors_disabled? ⇒ Boolean
(readonly, protected)
[ GitHub ]
# File 'lib/bundler/vendor/thor/lib/thor/shell/color.rb', line 107
def are_colors_disabled? !ENV["NO_COLOR"].nil? && !ENV["NO_COLOR"].empty? end
#are_colors_supported? ⇒ Boolean
(readonly, protected)
[ GitHub ]
# File 'lib/bundler/vendor/thor/lib/thor/shell/color.rb', line 103
def are_colors_supported? stdout.tty? && ENV["TERM"] != "dumb" end
#can_display_colors? ⇒ Boolean
(readonly, protected)
[ GitHub ]
# File 'lib/bundler/vendor/thor/lib/thor/shell/color.rb', line 99
def can_display_colors? are_colors_supported? && !are_colors_disabled? end
Instance Method Details
#set_color(string, *colors)
Set color by using a string or one of the defined constants. If a third option is set to true, it also adds bold to the string. This is based on Highline implementation and it automatically appends CLEAR to the end of the returned String.
Pass foreground, background and bold options to this method as symbols.
Example:
set_color "Hi!", :red, :on_white, :bold
The available colors are:
:bold
:black
:red
:green
:yellow
:blue
:magenta
:cyan
:white
:on_black
:on_red
:on_green
:on_yellow
:on_blue
:on_magenta
:on_cyan
:on_white
# File 'lib/bundler/vendor/thor/lib/thor/shell/color.rb', line 79
def set_color(string, *colors) if colors.compact.empty? || !can_display_colors? string elsif colors.all? { |color| color.is_a?(Symbol) || color.is_a?(String) } ansi_colors = colors.map { |color| lookup_color(color) } "#{ansi_colors.join}#{string}#{CLEAR}" else # The old API was `set_color(color, bold=boolean)`. We # continue to support the old API because you should never # break old APIs unnecessarily :P foreground, bold = colors foreground = self.class.const_get(foreground.to_s.upcase) if foreground.is_a?(Symbol) bold = bold ? BOLD : "" "#{bold}#{foreground}#{string}#{CLEAR}" end end