module Colours::HtmlColours
Public Class Methods
[]( which_colour_to_use, optional_text_to_display = '' )
click to toggle source
#¶ ↑
Colours::HtmlColours
[]¶ ↑
Usage examples:
Colours::HtmlColours['slateblue','Hello World!'] # works as Example 1 Colours::HtmlColours['slateblue'] Colours::HtmlColours['lightgreen','Hello World!'] Colours::HtmlColours[:random] e Colours::HtmlColours[:random, 'yo there']
#¶ ↑
# File lib/colours/html_colours/html_colours.rb, line 177 def self.[]( which_colour_to_use, optional_text_to_display = '' ) case which_colour_to_use when :random which_colour_to_use = random_html_colour end if ::Colours.use_html_colours? ::Colours::SupportForHTMLColours.send( which_colour_to_use, optional_text_to_display ) else # else return it unmodified. optional_text_to_display end end
available_html_colours?()
click to toggle source
colour_to_rgb(long_name = :slateblue)
click to toggle source
#¶ ↑
Colours::HtmlColours.colour_to_rgb
(‘royalblue’)¶ ↑
This method will convert the long colour name to an Array with R,G,B values.
Usage examples:
Colours::HtmlColours.colour_to_rgb('whitesmoke') # => [245, 245, 245] Colours::HtmlColours.colour_to_rgb('slateblue') # => [106, 90, 205] Colours::HtmlColours.colour_to_rgb(:royalblue) # => [65, 105, 225]
#¶ ↑
# File lib/colours/html_colours/html_colours.rb, line 236 def self.colour_to_rgb(long_name = :slateblue) pointer = @hash_html_colours[long_name.to_s] # This will be an Array. return [pointer[0], pointer[1], pointer[2]] end
does_include?(i = :slateblue)
click to toggle source
#¶ ↑
Colours::HtmlColours.does_include?
¶ ↑
This method will return true if the given input is included in the HTML colours.
Usage examples:
Colours::HtmlColours.does_include? 'slateblue' # => true Colours::HtmlColours.is_this_html_colour_included? 'royalblue' # => true Colours::HtmlColours.is_this_html_colour_included? 'megawhite' # => false
#¶ ↑
# File lib/colours/html_colours/html_colours.rb, line 112 def self.does_include?(i = :slateblue) return true if @hash_html_colours.has_key?(i.to_s) false # else return false. end
e(i = '')
click to toggle source
hash_html_colours?()
click to toggle source
html_colourize(i)
click to toggle source
#¶ ↑
Colours::HtmlColours.html_colourize
¶ ↑
#¶ ↑
# File lib/colours/html_colours/html_colours.rb, line 196 def self.html_colourize(i) if i.is_a? Array i = i.join(' ') end if i if File.file?(i) i = File.read(i) elsif i.respond_to? :read i = i.read end end if i.is_a? String # ===================================================================== # # Find all HTML colours next in that String: # ===================================================================== # splitted = i.split("\n") splitted.map! {|entry| if ::Colours.does_this_line_include_a_html_colour?(entry) entry = ::Colours.replace_all_raw_html_colours_in_this_line(entry) end entry } i = splitted.join("\n") end e i end
random_colour?()
click to toggle source
rev()
click to toggle source
show_html_colours()
click to toggle source
#¶ ↑
Colours::HtmlColours.show_html_colours
¶ ↑
This can be used to output the colours. It requires the method html_colours().
To invoke this method from the commandline, try:
colours --show_html_colours
#¶ ↑
# File lib/colours/html_colours/html_colours.rb, line 70 def self.show_html_colours require 'colours/rgb/rgb.rb' lpad = 22 show_this_standard_sentence = 'This is a longer test-sentence in that colour.' print ' '; e '=' * 100 html_colours.each {|this_html_colour| result = "#{::Colours.rgb_as_string(this_html_colour)} #{this_html_colour.to_s.ljust(22)}" # ===================================================================== # # Next, show that particular colour. # ===================================================================== # string = ::Colours.rgb_as_string(this_html_colour).strip ansi_escape_code = string.tr("\e","\\e") display_this_line = " | #{(this_html_colour+': ').ljust(lpad)}| "\ "#{result}#{::Colours.rev} | #{::Colours.rgb_as_string(this_html_colour)}#{show_this_standard_sentence}#{rev} |\n".dup # rev() is needed to restore the old default. display_this_line << ' | | ' display_this_line << ''.ljust(22) echo_string = " | echo -e \""+string+"\\"+ansi_escape_code+"xyz#{rev}"+'"' padded_echo_string = (echo_string.rstrip).ljust(72) display_this_line << "#{padded_echo_string}|" e display_this_line } print ' '; e '=' * 100 end
Public Instance Methods
all_html_colours()
click to toggle source
#¶ ↑
all_html_colours
¶ ↑
This method will feedback all html colours known.
#¶ ↑
# File lib/colours/html_colours/html_colours.rb, line 155 def all_html_colours ::Colours::HtmlColours.available_html_colours? end
Also aliased as: html_colours?, all_colours