Class: Thor::Shell::HTML

Inherits:
Basic
  • Object
show all
Defined in:
lib/bundler/vendor/thor/shell/html.rb

Overview

Inherit from Thor::Shell::Basic and add set_color behavior. Check Thor::Shell::Basic to see all available methods.

Constant Summary

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'

Instance Attribute Summary

Attributes inherited from Basic

#base, #padding

Instance Method Summary (collapse)

Methods inherited from Basic

#error, #file_collision, #initialize, #mute, #mute?, #no?, #print_in_columns, #print_table, #print_wrapped, #say, #say_status, #terminal_width, #yes?

Constructor Details

This class inherits a constructor from Thor::Shell::Basic

Instance Method Details

- (Object) ask(statement, color = nil)

Ask something to the user and receives a response.

Example

ask(“What is your name?”)

TODO: Implement #ask for Thor::Shell::HTML



70
71
72
# File 'lib/bundler/vendor/thor/shell/html.rb', line 70

def ask(statement, color = nil)
  fail NotImplementedError, 'Implement #ask for Thor::Shell::HTML'
end

- (Object) 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.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bundler/vendor/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("; ")};\">#{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("; ")};\">#{string}</span>"
  end
end