Module: RicColorsObsolete
- Defined in:
- lib/ric_colors.rb
Overview
PLease forgive me this is going to be obsoleted soon
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
- #daltonic_terminal? ⇒ Boolean
- #flag(str, flag = '') ⇒ Object
- #flag2(str, left_color = 'brown', right_color = 'pink') ⇒ 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
/Class RicColor.
- #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:
153 154 155 |
# File 'lib/ric_colors.rb', line 153 def _flag_nations %w{ar cc it de ie fr es en goo br po pt }.sort end |
#bash_color(n, str) ⇒ Object
39 40 41 |
# File 'lib/ric_colors.rb', line 39 def bash_color(n, str ) "\033[#{n}m#{str}\033[0m" end |
#color_test(with_italian = false) ⇒ Object Also known as: colortest
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ric_colors.rb', line 72 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{|a,b| a.to_s.gsub(/[^a-z]/,'') <=> b.to_s.gsub(/[^a-z]/,'') }.join(' ')) # sort on a-z chars only (no color) _flag_nations.sort.each{|nation| puts "- Flag sample for #{nation}:\t" + flag("ThisIsAFlaggedPhraseBasedOnNation:#{nation}",nation) } end |
#colora(color_name = 'greenpurpureo', str = 'colora_test_str2', opts = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ric_colors.rb', line 56 def colora(color_name='greenpurpureo',str='colora_test_str2', opts={}) color_name = color_name.to_s str = $debug_pad_colors ? $debug_pad_colors.join(str) : str # Adding '(2πi)' 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
134 135 136 |
# File 'lib/ric_colors.rb', line 134 def colors_flag(nation = 'it') %w{ red white green } end |
#colors_off ⇒ Object
20 21 22 |
# File 'lib/ric_colors.rb', line 20 def colors_off set_color(false) end |
#colors_on ⇒ Object
17 18 19 |
# File 'lib/ric_colors.rb', line 17 def colors_on set_color :on #(true) end |
#daltonic_terminal? ⇒ Boolean
301 302 303 304 |
# File 'lib/ric_colors.rb', line 301 def daltonic_terminal?() #deb( "Terminal is: " + terminal ) return !! terminal.to_s.match( /Apple_Terminal/ ) end |
#flag(str, flag = '') ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/ric_colors.rb', line 156 def flag(str, flag = '') case flag.to_s when 'ar' return flag3(str, 'azure2', 'white', 'cyan') when 'br','pt' return flag3(str, 'dkgreen', 'gold', 'dkgreen') when 'cc' return flag3(str, 'red', 'white', 'red') # switzerland when 'de' return flag3(str, 'dkblack', 'red', 'gold') when 'ie','gd','ga' return flag3(str, 'dkgreen', '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, 'dkgreen', 'white', 'red') when 'po' return flag2(str, 'white', 'red') when '' return flag3(str + " (missing flag1, try 'it')") end return flag3(str + " (missing flag2, try 'it')") end |
#flag2(str, left_color = 'brown', right_color = 'pink') ⇒ Object
200 201 202 |
# File 'lib/ric_colors.rb', line 200 def flag2(str,left_color='brown',right_color='pink') flag_n(str, [left_color, right_color] ) 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
191 192 193 194 195 196 197 198 199 |
# File 'lib/ric_colors.rb', line 191 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
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/ric_colors.rb', line 204 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
128 129 130 131 132 |
# File 'lib/ric_colors.rb', line 128 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
43 44 45 46 47 48 49 |
# File 'lib/ric_colors.rb', line 43 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…
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ric_colors.rb', line 89 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”
140 141 142 143 144 145 |
# File 'lib/ric_colors.rb', line 140 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)
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ric_colors.rb', line 25 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}" if block_given? puts "TODO!!! scolara qui" yield puts "TODO ricolora qui" end $colors_active = bool end |
#terminal ⇒ Object
/Class RicColor
297 298 299 |
# File 'lib/ric_colors.rb', line 297 def terminal ENV['TERM_PROGRAM'] || 'suppongo_ssh' end |
#visible_color(s) ⇒ Object
51 52 53 |
# File 'lib/ric_colors.rb', line 51 def visible_color(s) !( s.match(/nero|black/) ) end |