Class: Bundler::Thor::Shell::HTML
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/html.rb |
Overview
Constant Summary
-
BLACK =
Set the terminal’s foreground
HTML
color to black."color: black"
-
BLUE =
Set the terminal’s foreground
HTML
color to blue."color: blue"
-
BOLD =
The start of an
HTML
bold sequence."font-weight: bold"
-
CYAN =
Set the terminal’s foreground
HTML
color to cyan."color: cyan"
-
GREEN =
Set the terminal’s foreground
HTML
color to green."color: green"
-
MAGENTA =
Set the terminal’s foreground
HTML
color to magenta."color: magenta"
-
ON_BLACK =
Set the terminal’s background
HTML
color to black."background-color: black"
-
ON_BLUE =
Set the terminal’s background
HTML
color to blue."background-color: blue"
-
ON_CYAN =
Set the terminal’s background
HTML
color to cyan."background-color: cyan"
-
ON_GREEN =
Set the terminal’s background
HTML
color to green."background-color: green"
-
ON_MAGENTA =
Set the terminal’s background
HTML
color to magenta."background-color: magenta"
-
ON_RED =
Set the terminal’s background
HTML
color to red."background-color: red"
-
ON_WHITE =
Set the terminal’s background
HTML
color to white."background-color: white"
-
ON_YELLOW =
Set the terminal’s background
HTML
color to yellow."background-color: yellow"
-
RED =
Set the terminal’s foreground
HTML
color to red."color: red"
-
WHITE =
Set the terminal’s foreground
HTML
color to white."color: white"
-
YELLOW =
Set the terminal’s foreground
HTML
color to yellow."color: yellow"
Class Method Summary
Instance Attribute Summary
- #can_display_colors? ⇒ Boolean readonly protected
-
#diff_lcs_loaded? ⇒ Boolean
readonly
protected
Internal use only
Check if
Diff::LCS
is loaded.
Basic
- Inherited
Instance Method Summary
-
#ask(statement, color = nil)
Ask something to the user and receives a response.
-
#set_color(string, *colors)
Set color by using a string or one of the defined constants.
- #output_diff_line(diff) protected Internal use only
-
#show_diff(destination, content)
protected
Internal use only
Overwrite show_diff to show diff with colors if
Diff::LCS
is available.
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? | Make a question the to user 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_status | Say a status with the given color and appends the message. |
#terminal_width | This code was copied from Rake, available under MIT-LICENSE Copyright © 2003, 2004 Jim Weirich. |
#yes? | Make a question the to user and returns true if the user replies “y” or “yes”. |
#as_unicode | See additional method definition at line 394. |
#ask_filtered, #ask_simply, | |
#dynamic_width | Calculate the dynamic width of the terminal. |
#dynamic_width_stty, #dynamic_width_tput, #lookup_color, #prepare_message, #stderr, #stdout, #truncate, | |
#set_color | Apply color to the given string with optional bold. |
#file_collision_help, #is?, #show_diff |
Constructor Details
This class inherits a constructor from Bundler::Thor::Shell::Basic
Instance Attribute Details
#can_display_colors? ⇒ Boolean
(readonly, protected)
[ GitHub ]
# File 'lib/bundler/vendor/thor/lib/thor/shell/html.rb', line 76
def can_display_colors? true end
#diff_lcs_loaded? ⇒ Boolean
(readonly, protected)
Check if Diff::LCS
is loaded. If it is, use it to create pretty output for diff.
# File 'lib/bundler/vendor/thor/lib/thor/shell/html.rb', line 113
def diff_lcs_loaded? #:nodoc: return true if defined?(Diff::LCS) return @diff_lcs_loaded unless @diff_lcs_loaded.nil? @diff_lcs_loaded = begin require "diff/lcs" true rescue LoadError false end end
Instance Method Details
#ask(statement, color = nil)
Ask something to the user and receives a response.
Example
ask(“What is your name?”)
TODO: Implement #ask
for HTML
# 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
#output_diff_line(diff) (protected)
# File 'lib/bundler/vendor/thor/lib/thor/shell/html.rb', line 96
def output_diff_line(diff) #:nodoc: case diff.action when "-" say "- #{diff.old_element.chomp}", :red, true when "+" say "+ #{diff.new_element.chomp}", :green, true when "!" say "- #{diff.old_element.chomp}", :red, true say "+ #{diff.new_element.chomp}", :green, true else say " #{diff.old_element.chomp}", nil, true end end
#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.
# 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('; ')};\">#{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
#show_diff(destination, content) (protected)
Overwrite show_diff to show diff with colors if Diff::LCS
is available.
# File 'lib/bundler/vendor/thor/lib/thor/shell/html.rb', line 83
def show_diff(destination, content) #:nodoc: if diff_lcs_loaded? && ENV["THOR_DIFF"].nil? && ENV["RAILS_DIFF"].nil? actual = File.binread(destination).to_s.split("\n") content = content.to_s.split("\n") Diff::LCS.sdiff(actual, content).each do |diff| output_diff_line(diff) end else super end end