Class: Bundler::Thor::Shell::HTML
- Defined in:
- lib/bundler/vendor/thor/lib/thor/shell/html.rb
Overview
Inherit from Bundler::Thor::Shell::Basic and add set_color behavior. Check Bundler::Thor::Shell::Basic to see all available methods.
Constant Summary collapse
- BOLD =
The start of an HTML bold sequence.
"font-weight: bold"
- BLACK =
Set the terminal’s foreground HTML color to black.
"color: black"
- RED =
Set the terminal’s foreground HTML color to red.
"color: red"
- GREEN =
Set the terminal’s foreground HTML color to green.
"color: green"
- YELLOW =
Set the terminal’s foreground HTML color to yellow.
"color: yellow"
- BLUE =
Set the terminal’s foreground HTML color to blue.
"color: blue"
- MAGENTA =
Set the terminal’s foreground HTML color to magenta.
"color: magenta"
- CYAN =
Set the terminal’s foreground HTML color to cyan.
"color: cyan"
- WHITE =
Set the terminal’s foreground HTML color to white.
"color: white"
- ON_BLACK =
Set the terminal’s background HTML color to black.
"background-color: black"
- ON_RED =
Set the terminal’s background HTML color to red.
"background-color: red"
- ON_GREEN =
Set the terminal’s background HTML color to green.
"background-color: green"
- ON_YELLOW =
Set the terminal’s background HTML color to yellow.
"background-color: yellow"
- ON_BLUE =
Set the terminal’s background HTML color to blue.
"background-color: blue"
- ON_MAGENTA =
Set the terminal’s background HTML color to magenta.
"background-color: magenta"
- ON_CYAN =
Set the terminal’s background HTML color to cyan.
"background-color: cyan"
- ON_WHITE =
Set the terminal’s background HTML color to white.
"background-color: white"
Constants inherited from Basic
Instance Attribute Summary
Attributes inherited from Basic
Instance Method Summary collapse
-
#ask(statement, color = nil) ⇒ Object
Ask something to the user and receives a response.
-
#set_color(string, *colors) ⇒ Object
Set color by using a string or one of the defined constants.
Methods inherited from Basic
#error, #file_collision, #indent, #initialize, #mute, #mute?, #no?, #print_in_columns, #print_table, #print_wrapped, #say, #say_error, #say_status, #terminal_width, #yes?
Constructor Details
This class inherits a constructor from Bundler::Thor::Shell::Basic
Instance Method Details
#ask(statement, color = nil) ⇒ Object
Ask something to the user and receives a response.
Example
ask(“What is your name?”)
TODO: Implement #ask for Bundler::Thor::Shell::HTML
70 71 72 |
# File 'lib/bundler/vendor/thor/lib/thor/shell/html.rb', line 70 def ask(statement, color = nil) raise NotImplementedError, "Implement #ask for Bundler::Thor::Shell::HTML" end |
#set_color(string, *colors) ⇒ Object
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.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bundler/vendor/thor/lib/thor/shell/html.rb', line 51 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('; ')};\">#{Bundler::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('; ')};\">#{Bundler::Thor::Util.escape_html(string)}</span>" end end |