Module: Ric::Colors
- Defined in:
- lib/ric/colors.rb
Defined Under Namespace
Classes: RicColor
Instance Method Summary collapse
-
#_flag_nations ⇒ Object
italia: green white red ireland: green white orange france: green white orange UK: blue white red white blue google:.
- #bash_color(n, str) ⇒ Object
- #color_test(with_italian = false) ⇒ Object (also: #colortest)
- #colora(color_name = 'greenpurpureo', str = 'colora_test_str2', opts = {}) ⇒ Object
- #colors_flag(nation = 'it') ⇒ Object
- #colors_off ⇒ Object
-
#colors_on ⇒ Object
alias viola = fuxia.
- #daltonic_terminal? ⇒ Boolean
- #flag(str, flag = '') ⇒ Object
-
#flag3(str, left_color = 'brown', middle_color = 'pink', right_color = 'red') ⇒ Object
for simmetry padding m = length / 3 6: 2 2 2 m m m REST 0 5: 2 1 2 m+1 m m+1 2 4: 1 2 1 m m+1 m 1.
- #flag_n(str, colors) ⇒ Object
- #okno(bool, str = nil) ⇒ Object
- #pcolor(color_name = 'red', str = 'COLOR: please define a string') ⇒ Object
-
#rainbow(str) ⇒ Object
(also: #arcobaleno)
carattere per carattere…
-
#scolora(str) ⇒ Object
(also: #uncolor)
“e[0;31m42e[0m” –> “42” e[38;5;28mXXXX -> “XXX”.
-
#set_color(bool) ⇒ Object
(also: #set_colors)
TODO support a block (solo dentro l blocco fai il nocolor).
- #terminal ⇒ Object
- #visible_color(s) ⇒ Object
Instance Method Details
#_flag_nations ⇒ Object
italia: green white red ireland: green white orange france: green white orange UK: blue white red white blue google:
186 187 188 |
# File 'lib/ric/colors.rb', line 186 def _flag_nations %w{cc it de ie fr es en goo br pt} end |
#bash_color(n, str) ⇒ Object
75 76 77 |
# File 'lib/ric/colors.rb', line 75 def bash_color(n, str ) "\033[#{n}m#{str}\033[0m" end |
#color_test(with_italian = false) ⇒ Object Also known as: colortest
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ric/colors.rb', line 106 def color_test(with_italian = false) i=0 palette = $color_db[0].map { |c| inglese = c italiano = $color_db[1][i] i = i+1 colora( c, with_italian ? [c,italiano].join(','): c ) } puts( (1..257).map{|c| bash_color( "38;5;#{c}", c) }.join(', ') ) puts( palette.sort.join(' ')) _flag_nations.each{|nation| puts "- Flag sample: " + flag("ThisIsAFlaggedPhraseBasedOnNation:#{nation}",nation) } end |
#colora(color_name = 'greenpurpureo', str = 'colora_test_str2', opts = {}) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ric/colors.rb', line 91 def colora(color_name='greenpurpureo',str='colora_test_str2', opts={}) color_name = color_name.to_s return str unless $colors_active return str if opts[:nocolor] if ix = $color_db[0].index(color_name) bash_color($color_db[2][ix],str) elsif ix = $color_db[1].index(color_name) bash_color($color_db[2][ix],str) else debug "Sorry, unknown color '#{color_name}'. Available ones are: #{$color_db[0].join(',') }" end end |
#colors_flag(nation = 'it') ⇒ Object
167 168 169 |
# File 'lib/ric/colors.rb', line 167 def colors_flag(nation = 'it') %w{ red white green } end |
#colors_off ⇒ Object
61 62 63 |
# File 'lib/ric/colors.rb', line 61 def colors_off set_color(false) end |
#colors_on ⇒ Object
alias viola = fuxia
58 59 60 |
# File 'lib/ric/colors.rb', line 58 def colors_on set_color :on #(true) end |
#daltonic_terminal? ⇒ Boolean
279 280 281 282 |
# File 'lib/ric/colors.rb', line 279 def daltonic_terminal?() deb( "Terminal is: " + terminal ) return !! terminal.to_s.match( /Apple_Terminal/ ) end |
#flag(str, flag = '') ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/ric/colors.rb', line 189 def flag(str, flag = '') case flag.to_s when 'br','pt' return flag3(str, 'green', 'gold', 'green') when 'cc' return flag3(str, 'red', 'white', 'red') # switzerland when 'de' return flag3(str, 'dkblack', 'red', 'gold') when 'ie','gd','ga' return flag3(str, 'green', 'white', 'orange')# non so la differenza, sembrano entrambi gaelici! when 'en' return flag3(str, 'red', 'blue', 'red') # red white blue white red white blue white ... and again when 'es' return flag3(str, 'yellow', 'red', 'yellow') when 'fr' return flag3(str, 'blue', 'white', 'red') when 'goo','google' return flag_n(str, %w{ blue red yellow blue green red } ) when 'it' return flag3(str, 'green', 'white', 'red') when '' return flag3(str + " (missing flag1, try 'it')") end return flag3(str + " (missing flag2, try 'it')") end |
#flag3(str, left_color = 'brown', middle_color = 'pink', right_color = 'red') ⇒ Object
for simmetry padding m = length / 3 6: 2 2 2 m m m REST 0 5: 2 1 2 m+1 m m+1 2 4: 1 2 1 m m+1 m 1
220 221 222 223 224 225 226 227 228 |
# File 'lib/ric/colors.rb', line 220 def flag3(str,left_color='brown',middle_color='pink',right_color='red') m = str.length / 3 remainder = str.length % 3 central_length = remainder == 1 ? m+1 : m lateral_length = remainder == 2 ? m+1 : m colora( left_color, str[ 0 .. lateral_length-1] ) + colora( middle_color, str[ lateral_length .. lateral_length+central_length-1] ) + colora( right_color, str[ lateral_length+central_length .. str.length ] ) end |
#flag_n(str, colors) ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/ric/colors.rb', line 230 def flag_n(str,colors) size = colors.size #debug_on :flag6 ret = "" m = str.length / size # chunk size deb m (0 .. size-1).each{|i| #deb "Passo #{i}" chunk = str[m*(i),m*(i+1)] #deb chunk ret += colora(colors[i], chunk ) } #deb str.split(/....../) #remainder = str.length % 6 return ret + " (bacatino)" # central_length = remainder == 1 ? m+1 : m # lateral_length = remainder == 2 ? m+1 : m # colora( left_color, str[ 0 .. lateral_length-1] ) + # colora( middle_color, str[ lateral_length .. lateral_length+central_length-1] ) + # colora( right_color, str[ lateral_length+central_length .. str.length ] ) # return ret end |
#okno(bool, str = nil) ⇒ Object
161 162 163 164 165 |
# File 'lib/ric/colors.rb', line 161 def okno(bool,str=nil) str ||= bool bool = (bool == 0 ) if (bool.class == Fixnum) # so 0 is green, others are red :) return bool ? green(str) : red(str) end |
#pcolor(color_name = 'red', str = 'COLOR: please define a string') ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/ric/colors.rb', line 79 def pcolor(color_name='red',str='COLOR: please define a string') if $colors_active puts colora(color_name,str) else puts str end end |
#rainbow(str) ⇒ Object Also known as: arcobaleno
carattere per carattere…
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ric/colors.rb', line 123 def rainbow(str) i=0 ret = '' str=str.to_s while(i < str.length) ch = str[i] palette = $color_db[0][i % $color_db[0].length ] ret << (colora(palette,str[i,1])) i += 1 end ret end |
#scolora(str) ⇒ Object Also known as: uncolor
“e[0;31m42e[0m” –> “42” e[38;5;28mXXXX -> “XXX”
173 174 175 176 177 178 |
# File 'lib/ric/colors.rb', line 173 def scolora(str) str.to_s. gsub(/\e\[1;33m/,''). # colori 16 gsub(/\e\[0m/,''). # colori 64k gsub(/\e\[38;\d+;\d+m/,'') # end color end |
#set_color(bool) ⇒ Object Also known as: set_colors
TODO support a block (solo dentro l blocco fai il nocolor)
66 67 68 69 70 71 72 |
# File 'lib/ric/colors.rb', line 66 def set_color(bool) b = bool ? true : false deb "Setting color mode to: #{yellow bool} --> #{white b.to_s}" b = false if bool.to_s.match( /(off|false)/ ) deb "Setting color mode to: #{yellow bool} --> #{white b.to_s}" $colors_active = bool end |
#terminal ⇒ Object
275 276 277 |
# File 'lib/ric/colors.rb', line 275 def terminal ENV['TERM_PROGRAM'] || 'suppongo_ssh' end |
#visible_color(s) ⇒ Object
87 88 89 |
# File 'lib/ric/colors.rb', line 87 def visible_color(s) !( s.match(/nero|black/) ) end |