class Thor::Shell::HTML
Inherit from Thor::Shell::Basic
and add set_color
behavior. Check Thor::Shell::Basic
to see all available methods.
Constants
- BLACK
-
Set the terminal’s foreground
HTML
color to black. - BLUE
-
Set the terminal’s foreground
HTML
color to blue. - BOLD
-
The start of an
HTML
bold sequence. - CYAN
-
Set the terminal’s foreground
HTML
color to cyan. - GREEN
-
Set the terminal’s foreground
HTML
color to green. - MAGENTA
-
Set the terminal’s foreground
HTML
color to magenta. - ON_BLACK
-
Set the terminal’s background
HTML
color to black. - ON_BLUE
-
Set the terminal’s background
HTML
color to blue. - ON_CYAN
-
Set the terminal’s background
HTML
color to cyan. - ON_GREEN
-
Set the terminal’s background
HTML
color to green. - ON_MAGENTA
-
Set the terminal’s background
HTML
color to magenta. - ON_RED
-
Set the terminal’s background
HTML
color to red. - ON_WHITE
-
Set the terminal’s background
HTML
color to white. - ON_YELLOW
-
Set the terminal’s background
HTML
color to yellow. - RED
-
Set the terminal’s foreground
HTML
color to red. - WHITE
-
Set the terminal’s foreground
HTML
color to white. - YELLOW
-
Set the terminal’s foreground
HTML
color to yellow.
Public Instance Methods
Ask something to the user and receives a response.
Example¶ ↑
ask("What is your name?")
TODO: Implement ask
for Thor::Shell::HTML
# File lib/thor/shell/html.rb, line 73 def ask(statement, color = nil) raise NotImplementedError, "Implement #ask for Thor::Shell::HTML" 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.
# File lib/thor/shell/html.rb, line 54 def set_color(string, *colors) if colors.all? { |color| color.is_a?(Symbol) || color.is_a?(String) } html_colors = colors.map { |color| lookup_color(color) } "<span style=\"#{html_colors.join('; ')};\">#{Thor::Util.escape_html(string)}</span>" else color, bold = colors html_color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol) styles = [html_color] styles << BOLD if bold "<span style=\"#{styles.join('; ')};\">#{Thor::Util.escape_html(string)}</span>" end end
Protected Instance Methods
# File lib/thor/shell/html.rb, line 79 def can_display_colors? true end