class Bundler::Thor::Shell::Color
Inherit from Bundler::Thor::Shell::Basic and add set_color behavior. Check Bundler::Thor::Shell::Basic to see all available methods.
Constants
- BLACK
-
Setthe terminal's foreground ANSI color to black. - BLUE
-
Setthe terminal's foreground ANSI color to blue. - BOLD
-
The start of an ANSI bold sequence.
- CLEAR
-
Embed in a
Stringto clear all previous ANSI sequences. - CYAN
-
Setthe terminal's foreground ANSI color to cyan. - GREEN
-
Setthe terminal's foreground ANSI color to green. - MAGENTA
-
Setthe terminal's foreground ANSI color to magenta. - ON_BLACK
-
Setthe terminal's background ANSI color to black. - ON_BLUE
-
Setthe terminal's background ANSI color to blue. - ON_CYAN
-
Setthe terminal's background ANSI color to cyan. - ON_GREEN
-
Setthe terminal's background ANSI color to green. - ON_MAGENTA
-
Setthe terminal's background ANSI color to magenta. - ON_RED
-
Setthe terminal's background ANSI color to red. - ON_WHITE
-
Setthe terminal's background ANSI color to white. - ON_YELLOW
-
Setthe terminal's background ANSI color to yellow. - RED
-
Setthe terminal's foreground ANSI color to red. - WHITE
-
Setthe terminal's foreground ANSI color to white. - YELLOW
-
Setthe terminal's foreground ANSI color to yellow.
Public Instance Methods
# 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 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
Protected Instance Methods
# File lib/bundler/vendor/thor/lib/thor/shell/color.rb, line 99 def can_display_colors? stdout.tty? end
Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.