module Ric::Colors

Public Instance Methods

_flag_nations() click to toggle source

italia: green white red ireland: green white orange france: green white orange UK: blue white red white blue google:

    # File lib/ric/colors.rb
186 def _flag_nations
187   %w{cc it de ie fr es en goo br pt}
188 end
arcobaleno(str)
Alias for: rainbow
bash_color(n, str ) click to toggle source
   # File lib/ric/colors.rb
75 def bash_color(n, str  )
76   "\033[#{n}m#{str}\033[0m"
77 end
color_test(with_italian = false) click to toggle source
    # File lib/ric/colors.rb
106 def color_test(with_italian = false)
107   i=0
108   palette = $color_db[0].map { |c|
109     inglese  = c
110     italiano = $color_db[1][i]
111     i = i+1
112     colora( c, with_italian ? [c,italiano].join(','): c )
113   }
114   puts( (1..257).map{|c| bash_color( "38;5;#{c}", c) }.join(', ') )
115   puts( palette.sort.join(' '))
116   _flag_nations.each{|nation|
117     puts "- Flag sample: " + flag("ThisIsAFlaggedPhraseBasedOnNation:#{nation}",nation)
118   }
119 end
Also aliased as: colortest
colora(color_name='greenpurpureo',str='colora_test_str2', opts={}) click to toggle source
    # File lib/ric/colors.rb
 91 def colora(color_name='greenpurpureo',str='colora_test_str2', opts={})
 92   color_name = color_name.to_s
 93   return str unless $colors_active
 94   return str if opts[:nocolor]
 95   if ix = $color_db[0].index(color_name) 
 96     bash_color($color_db[2][ix],str)
 97   elsif ix = $color_db[1].index(color_name)
 98     bash_color($color_db[2][ix],str)
 99   else
100     debug "Sorry, unknown color '#{color_name}'. Available ones are: #{$color_db[0].join(',') }"
101   end
102 end
colors_flag(nation = 'it') click to toggle source
    # File lib/ric/colors.rb
167 def colors_flag(nation = 'it')
168   %w{ red white green }
169 end
colors_off() click to toggle source
   # File lib/ric/colors.rb
61 def colors_off
62   set_color(false)
63 end
colors_on() click to toggle source

alias viola = fuxia

   # File lib/ric/colors.rb
58 def colors_on
59   set_color :on #(true)
60 end
colortest(with_italian = false)
Alias for: color_test
daltonic_terminal?() click to toggle source
    # File lib/ric/colors.rb
279 def daltonic_terminal?()
280   deb( "Terminal is: " + terminal )
281   return !! terminal.to_s.match( /Apple_Terminal/ )
282 end
flag(str, flag = '') click to toggle source
    # File lib/ric/colors.rb
189 def flag(str, flag = '')
190   case flag.to_s
191     when 'br','pt'
192             return flag3(str, 'green', 'gold', 'green') 
193     when 'cc'
194                  return flag3(str, 'red', 'white', 'red')  # switzerland
195     when 'de'
196                  return flag3(str, 'dkblack', 'red',   'gold')
197     when 'ie','gd','ga'
198        return flag3(str, 'green', 'white', 'orange')# non so la differenza, sembrano entrambi gaelici!
199     when 'en'
200                  return flag3(str, 'red', 'blue', 'red') # red white blue white red white blue white ... and again
201     when 'es'
202                  return flag3(str, 'yellow', 'red', 'yellow') 
203     when 'fr'
204                  return flag3(str, 'blue', 'white', 'red') 
205     when 'goo','google'
206        return flag_n(str, %w{ blue red yellow blue green red } ) 
207     when 'it'
208            return flag3(str, 'green', 'white', 'red')
209     when ''
210              return flag3(str + " (missing flag1, try 'it')")
211   end
212    return flag3(str + " (missing flag2, try 'it')")
213 end
flag3(str,left_color='brown',middle_color='pink',right_color='red') click to toggle source

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

    # File lib/ric/colors.rb
220 def flag3(str,left_color='brown',middle_color='pink',right_color='red')
221   m = str.length / 3
222   remainder = str.length % 3
223   central_length = remainder == 1 ? m+1 : m 
224   lateral_length = remainder == 2 ? m+1 : m 
225   colora(  left_color,    str[ 0 .. lateral_length-1] ) + 
226     colora( middle_color, str[ lateral_length .. lateral_length+central_length-1] ) + 
227     colora( right_color, str[ lateral_length+central_length .. str.length ] )  
228 end
flag_n(str,colors) click to toggle source
    # File lib/ric/colors.rb
230 def flag_n(str,colors)
231   size = colors.size
232   #debug_on :flag6
233   ret = ""
234   m = str.length / size # chunk size
235   deb m
236   (0 .. size-1).each{|i|
237     #deb "Passo #{i}"
238     chunk = str[m*(i),m*(i+1)]
239     #deb chunk
240     ret += colora(colors[i], chunk )
241   }
242   #deb str.split(/....../)
243   #remainder = str.length % 6
244   return ret + " (bacatino)"
245   # central_length = remainder == 1 ? m+1 : m
246   # lateral_length = remainder == 2 ? m+1 : m
247   # colora(  left_color,    str[ 0 .. lateral_length-1] ) +
248   #   colora( middle_color, str[ lateral_length .. lateral_length+central_length-1] ) +
249   #   colora( right_color, str[ lateral_length+central_length .. str.length ] )
250   # return ret
251 end
okno(bool,str=nil) click to toggle source
    # File lib/ric/colors.rb
161 def okno(bool,str=nil)
162   str ||= bool
163   bool = (bool == 0 ) if (bool.class == Fixnum) # so 0 is green, others are red :)
164   return bool ? green(str) : red(str)
165 end
pcolor(color_name='red',str='COLOR: please define a string') click to toggle source
   # File lib/ric/colors.rb
79 def pcolor(color_name='red',str='COLOR: please define a string')
80   if $colors_active
81     puts colora(color_name,str)
82   else
83     puts str
84   end
85 end
rainbow(str) click to toggle source

carattere per carattere…

    # File lib/ric/colors.rb
123 def rainbow(str)
124   i=0
125   ret = '' 
126   str=str.to_s
127   while(i < str.length)
128     ch = str[i]
129     palette = $color_db[0][i % $color_db[0].length ]
130     ret << (colora(palette,str[i,1]))
131     i += 1
132   end
133   ret
134 end
Also aliased as: arcobaleno
scolora(str) click to toggle source

“e[0;31m42e[0m” –> “42” e[38;5;28mXXXX -> “XXX”

    # File lib/ric/colors.rb
173 def scolora(str)
174   str.to_s.
175     gsub(/\e\[1;33m/,''). # colori 16
176     gsub(/\e\[0m/,''). # colori 64k
177     gsub(/\e\[38;\d+;\d+m/,'') # end color
178 end
Also aliased as: uncolor
set_color(bool) click to toggle source

TODO support a block (solo dentro l blocco fai il nocolor)

   # File lib/ric/colors.rb
66 def set_color(bool)
67   b = bool ? true : false
68   deb "Setting color mode to: #{yellow bool} --> #{white b.to_s}"
69   b = false if bool.to_s.match( /(off|false)/ )
70   deb "Setting color mode to: #{yellow bool} --> #{white b.to_s}"
71   $colors_active = bool
72 end
Also aliased as: set_colors
set_colors(bool)
Alias for: set_color
terminal() click to toggle source
    # File lib/ric/colors.rb
275 def terminal
276   ENV['TERM_PROGRAM'] || 'suppongo_ssh'
277 end
uncolor(str)
Alias for: scolora
visible_color(s) click to toggle source
   # File lib/ric/colors.rb
87 def visible_color(s)
88   !( s.match(/nero|black/) )
89 end