ric 0.9.5 → 0.9.6file
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.yml +7 -0
- data/Manifest +5 -2
- data/Rakefile +3 -1
- data/VERSION +1 -0
- data/bin/itunes +9 -0
- data/bin/ric +6 -2
- data/bin/riclib-test +49 -0
- data/init.rb +3 -2
- data/lib/ric.rb +13 -2
- data/lib/ric_colors.rb +299 -0
- data/ric.gemspec +4 -5
- metadata +16 -7
- data/lib/ric/colors.rb +0 -299
data/HISTORY.yml
ADDED
data/Manifest
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
HISTORY.yml
|
1
2
|
Manifest
|
2
3
|
README.md
|
3
4
|
Rakefile
|
4
5
|
TODO
|
6
|
+
VERSION
|
7
|
+
bin/itunes
|
5
8
|
bin/ric
|
9
|
+
bin/riclib-test
|
6
10
|
init.rb
|
7
11
|
lib/helpers/rails_helper.rb
|
8
12
|
lib/ric.rb
|
9
|
-
lib/ric/colors.rb
|
10
13
|
lib/ric/html.rb
|
14
|
+
lib/ric_colors.rb
|
11
15
|
lib/uniquify.rb
|
12
|
-
ric.gemspec
|
13
16
|
var/www/index.html
|
data/Rakefile
CHANGED
@@ -2,7 +2,9 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
|
5
|
+
version = File.read( 'VERSION' ) rescue "0.0.42_bugged"
|
6
|
+
|
7
|
+
Echoe.new('ric', version ) do |p|
|
6
8
|
p.description = "My first gem with various utilities (colors and tests now).
|
7
9
|
My name is Riccardo, hence 'ric' (ok I admit it, this was just ot prove Im able to build a sentence
|
8
10
|
with hence!)"
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.9.6file
|
data/bin/itunes
ADDED
data/bin/ric
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
require 'rubygems'
|
4
|
+
require 'ric'
|
4
5
|
|
5
|
-
puts "Welcome to ric, the swiss-army knife tool from Riccardo, included in riclib gem (v#{version})"
|
6
|
+
puts "Welcome to ric, the swiss-army knife tool from Riccardo, included in riclib gem (v#{Ric.version})"
|
7
|
+
|
8
|
+
#include RicColors
|
9
|
+
#Colors.pyellow 'ciao'
|
data/bin/riclib-test
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
|
3
|
+
############################################################
|
4
|
+
# $Id: script.rb 5267 2010-11-22 14:43:50Z rcarlesso $
|
5
|
+
############################################################
|
6
|
+
# @author Riccardo Carlesso
|
7
|
+
# @email riccardo.carlesso@heanet.ie
|
8
|
+
# @tags development, test, REMOVEME
|
9
|
+
# @maturity development
|
10
|
+
# @language Ruby
|
11
|
+
############################################################
|
12
|
+
|
13
|
+
# When this works, just remove it!
|
14
|
+
#require 'ric'
|
15
|
+
|
16
|
+
def richiedi(str)
|
17
|
+
avail = `gem list #{str}`.split("\n").select{|line| line.match( /#{str} /) }.join('')
|
18
|
+
ret = "Requiring: require '#{str}' [#{avail}].. "
|
19
|
+
ret += require( str.to_s ).to_s
|
20
|
+
ret
|
21
|
+
end
|
22
|
+
|
23
|
+
def n
|
24
|
+
$count ||= -1
|
25
|
+
$count += 1
|
26
|
+
end
|
27
|
+
|
28
|
+
def nputs(s)
|
29
|
+
puts "#{n} #{Time.now}: #{s}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def main()
|
33
|
+
begin
|
34
|
+
nputs "RicLib Test (you should see something green): '#{ $0 }'"
|
35
|
+
nputs "#{richiedi(:rubygems)}"
|
36
|
+
nputs "#{richiedi(:riclib)}"
|
37
|
+
nputs "#{richiedi(:ric)}"
|
38
|
+
require 'ric'
|
39
|
+
Ric.say_hello
|
40
|
+
nputs Ric.version
|
41
|
+
nputs "Now invoking: #{white 'Ric.ric_help' }"
|
42
|
+
Ric.ric_help #rescue "ERRORS on inviking: Ric.help()"
|
43
|
+
nputs "If you seen green, then everything is #{ green('fine') rescue "some ERROR: #{$!}"}"
|
44
|
+
rescue
|
45
|
+
puts "E. Some exception: #{$!}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
main
|
data/init.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
#require 'lib/ric/color'
|
2
2
|
require 'ric'
|
3
|
-
require '
|
3
|
+
require 'ric_colors'
|
4
4
|
require 'ric/html'
|
5
5
|
require 'uniquify'
|
6
|
+
|
6
7
|
#include Ric
|
7
8
|
#include Ric::Html
|
8
|
-
#include Ric
|
9
|
+
#include Ric Colors
|
9
10
|
|
10
11
|
#require 'rails_stuff'
|
11
12
|
#require 'doesnt_exist'
|
data/lib/ric.rb
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
# RICLIB!
|
3
3
|
module Ric
|
4
4
|
|
5
|
+
def self.version
|
6
|
+
#File.read( 'VERSION' ) rescue "0.0.42_bugged"
|
7
|
+
'(Wet) 0.9.6' # its NOT dry (yet)! Someone help with Gem version!
|
8
|
+
"Wet-0.9.6 (See file in '#{gempwd}')"
|
9
|
+
end
|
10
|
+
|
5
11
|
def self.say_hello
|
6
12
|
puts "Ric: Hello world by #{yellow 'Riccardo Carlesso' rescue 'Riccardo Carlesso Error'}"
|
7
13
|
end
|
@@ -15,6 +21,7 @@ module Ric
|
|
15
21
|
pred 'This is in red'
|
16
22
|
pyellow 'This is yellow instead'
|
17
23
|
|
24
|
+
gem_basedir: #{ gem_basedir }
|
18
25
|
HTML
|
19
26
|
puts( ret )
|
20
27
|
ret
|
@@ -22,9 +29,11 @@ module Ric
|
|
22
29
|
#alias :help :ric_help
|
23
30
|
#alias :about :ric_help
|
24
31
|
|
25
|
-
def
|
26
|
-
|
32
|
+
def gem_basedir
|
33
|
+
File.dir(__FILE__)
|
27
34
|
end
|
35
|
+
alias :gempwd :gem_basedir
|
36
|
+
|
28
37
|
|
29
38
|
# you can require more than one gem and a symbol as well :)
|
30
39
|
def self.richiedi(gems)
|
@@ -39,4 +48,6 @@ module Ric
|
|
39
48
|
end
|
40
49
|
end
|
41
50
|
|
51
|
+
|
52
|
+
|
42
53
|
end
|
data/lib/ric_colors.rb
ADDED
@@ -0,0 +1,299 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# $Id: ric_colors.rb 5438 2010-12-16 15:06:29Z rcarlesso $
|
4
|
+
|
5
|
+
module RicColors
|
6
|
+
|
7
|
+
$colors_active = true # DEFAULT: active
|
8
|
+
$color_db = [
|
9
|
+
%w{ normal black dkblack red green brown blue purple cyan lgray gray lred lgreen yellow lblue violet azure white orange orangey magenta lyellow pink gold } , # english word
|
10
|
+
%w{ normale nero nerone rosso verde marrone blu porpora ciano grigino grigione rossino verdino giallo lblu viola azzurro bianco arancio arancino magenta giallino rosa oro } , # italian word
|
11
|
+
%w{ 0;37 0;30 38;5;236 0;31 1;32 38;5;94 0;34 1;35 0;36 0;37 1;30 1;31 1;32 1;33 1;34 1;35 1;36 1;37 38;5;208 38;5;222 0;35 38;5;229 38;5;203 38;5;214 } ,
|
12
|
+
%w{ 000 000 222 f00 0f0 00f ff0 0ff aaa 888 f00 afa ff0 eebb00 } # HEX RGB
|
13
|
+
]
|
14
|
+
# rifallo, e' piu' manutenibile...
|
15
|
+
$color_db2 = [
|
16
|
+
# [ ARR_COLORS , ]
|
17
|
+
%w{ black nero 0;30 000 },
|
18
|
+
%w{ dkblack nerone 38;5;236 222 },
|
19
|
+
]
|
20
|
+
|
21
|
+
# alias viola = fuxia
|
22
|
+
|
23
|
+
def colors_on
|
24
|
+
set_color :on #(true)
|
25
|
+
end
|
26
|
+
def colors_off
|
27
|
+
set_color :off #(false)
|
28
|
+
end
|
29
|
+
|
30
|
+
# TODO support a block (solo dentro l blocco fai il nocolor)
|
31
|
+
def set_color(bool)
|
32
|
+
b = bool ? true : false
|
33
|
+
deb "Setting color mode to: #{yellow bool} --> #{white b.to_s}"
|
34
|
+
b = false if bool.to_s.match( /(off|false)/ )
|
35
|
+
deb "Setting color mode to: #{yellow bool} --> #{white b.to_s}"
|
36
|
+
$colors_active = bool
|
37
|
+
end
|
38
|
+
alias :set_colors :set_color
|
39
|
+
|
40
|
+
def bash_color(n, str )
|
41
|
+
"\033[#{n}m#{str}\033[0m"
|
42
|
+
end
|
43
|
+
|
44
|
+
def pcolor(color_name='red',str='COLOR: please define a string')
|
45
|
+
if $colors_active
|
46
|
+
puts colora(color_name,str)
|
47
|
+
else
|
48
|
+
puts str
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def visible_color(s)
|
53
|
+
!( s.match(/nero|black/) )
|
54
|
+
end
|
55
|
+
|
56
|
+
def colora(color_name='greenpurpureo',str='colora_test_str2', opts={})
|
57
|
+
color_name = color_name.to_s
|
58
|
+
return str unless $colors_active
|
59
|
+
return str if opts[:nocolor]
|
60
|
+
if ix = $color_db[0].index(color_name)
|
61
|
+
bash_color($color_db[2][ix],str)
|
62
|
+
elsif ix = $color_db[1].index(color_name)
|
63
|
+
bash_color($color_db[2][ix],str)
|
64
|
+
else
|
65
|
+
debug "Sorry, unknown color '#{color_name}'. Available ones are: #{$color_db[0].join(',') }"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
alias :p :puts
|
70
|
+
|
71
|
+
def color_test(with_italian = false)
|
72
|
+
i=0
|
73
|
+
palette = $color_db[0].map { |c|
|
74
|
+
inglese = c
|
75
|
+
italiano = $color_db[1][i]
|
76
|
+
i = i+1
|
77
|
+
colora( c, with_italian ? [c,italiano].join(','): c )
|
78
|
+
}
|
79
|
+
puts( (1..257).map{|c| bash_color( "38;5;#{c}", c) }.join(', ') )
|
80
|
+
puts( palette.sort.join(' '))
|
81
|
+
_flag_nations.each{|nation|
|
82
|
+
puts "- Flag sample: " + flag("ThisIsAFlaggedPhraseBasedOnNation:#{nation}",nation)
|
83
|
+
}
|
84
|
+
end
|
85
|
+
alias :colortest :color_test
|
86
|
+
|
87
|
+
# carattere per carattere...
|
88
|
+
def rainbow(str)
|
89
|
+
i=0
|
90
|
+
ret = ''
|
91
|
+
str=str.to_s
|
92
|
+
while(i < str.length)
|
93
|
+
ch = str[i]
|
94
|
+
palette = $color_db[0][i % $color_db[0].length ]
|
95
|
+
ret << (colora(palette,str[i,1]))
|
96
|
+
i += 1
|
97
|
+
end
|
98
|
+
ret
|
99
|
+
end
|
100
|
+
alias :arcobaleno :rainbow
|
101
|
+
|
102
|
+
#assert(color_db[0].length == color_db[1].length,"English and italian colors must be the same cardinality!!!")
|
103
|
+
# TODO ripeti con , $color_db[1]
|
104
|
+
( $color_db[0] + $color_db[1] ).each { |colorname|
|
105
|
+
dyn_func = "
|
106
|
+
|
107
|
+
def get_#{colorname} (str='colors.rb: get_COLOR dynamically generated ENGLISH COLOR ')
|
108
|
+
return colora('#{colorname}',str)
|
109
|
+
end
|
110
|
+
|
111
|
+
def #{colorname} (str='colors.rb: COLOR dynamically generated ENGLISH COLOR TO BE COPIED TO GET')
|
112
|
+
return colora('#{colorname}',str) rescue
|
113
|
+
\"Errore #{colorname} con stringa '#"+"{str}' e classe #"+"{str.class} \"
|
114
|
+
end
|
115
|
+
|
116
|
+
def p#{colorname} (str='colors.rb: pCOLOR dynamically generated ENGLISH COLOR TO BE DESTROYED')
|
117
|
+
puts colora('#{colorname}',str)
|
118
|
+
end
|
119
|
+
|
120
|
+
"
|
121
|
+
#debug dyn_func
|
122
|
+
eval dyn_func unless method_defined?( "get_#{colorname}".to_sym )
|
123
|
+
#remove_method
|
124
|
+
}
|
125
|
+
|
126
|
+
def okno(bool,str=nil)
|
127
|
+
str ||= bool
|
128
|
+
bool = (bool == 0 ) if (bool.class == Fixnum) # so 0 is green, others are red :)
|
129
|
+
return bool ? green(str) : red(str)
|
130
|
+
end
|
131
|
+
|
132
|
+
def colors_flag(nation = 'it')
|
133
|
+
%w{ red white green }
|
134
|
+
end
|
135
|
+
|
136
|
+
# "\e[0;31m42\e[0m" --> "42"
|
137
|
+
# \e[38;5;28mXXXX -> "XXX"
|
138
|
+
def scolora(str)
|
139
|
+
str.to_s.
|
140
|
+
gsub(/\e\[1;33m/,''). # colori 16
|
141
|
+
gsub(/\e\[0m/,''). # colori 64k
|
142
|
+
gsub(/\e\[38;\d+;\d+m/,'') # end color
|
143
|
+
end
|
144
|
+
alias :uncolor :scolora
|
145
|
+
|
146
|
+
# italia: green white red
|
147
|
+
# ireland: green white orange
|
148
|
+
# france: green white orange
|
149
|
+
# UK: blue white red white blue
|
150
|
+
# google:
|
151
|
+
def _flag_nations
|
152
|
+
%w{cc it de ie fr es en goo br pt}
|
153
|
+
end
|
154
|
+
def flag(str, flag = '')
|
155
|
+
case flag.to_s
|
156
|
+
when 'br','pt'
|
157
|
+
return flag3(str, 'green', 'gold', 'green')
|
158
|
+
when 'cc'
|
159
|
+
return flag3(str, 'red', 'white', 'red') # switzerland
|
160
|
+
when 'de'
|
161
|
+
return flag3(str, 'dkblack', 'red', 'gold')
|
162
|
+
when 'ie','gd','ga'
|
163
|
+
return flag3(str, 'green', 'white', 'orange')# non so la differenza, sembrano entrambi gaelici!
|
164
|
+
when 'en'
|
165
|
+
return flag3(str, 'red', 'blue', 'red') # red white blue white red white blue white ... and again
|
166
|
+
when 'es'
|
167
|
+
return flag3(str, 'yellow', 'red', 'yellow')
|
168
|
+
when 'fr'
|
169
|
+
return flag3(str, 'blue', 'white', 'red')
|
170
|
+
when 'goo','google'
|
171
|
+
return flag_n(str, %w{ blue red yellow blue green red } )
|
172
|
+
when 'it'
|
173
|
+
return flag3(str, 'green', 'white', 'red')
|
174
|
+
when ''
|
175
|
+
return flag3(str + " (missing flag1, try 'it')")
|
176
|
+
end
|
177
|
+
return flag3(str + " (missing flag2, try 'it')")
|
178
|
+
end
|
179
|
+
|
180
|
+
# for simmetry padding
|
181
|
+
# m = length / 3
|
182
|
+
# 6: 2 2 2 m m m REST 0
|
183
|
+
# 5: 2 1 2 m+1 m m+1 2
|
184
|
+
# 4: 1 2 1 m m+1 m 1
|
185
|
+
def flag3(str,left_color='brown',middle_color='pink',right_color='red')
|
186
|
+
m = str.length / 3
|
187
|
+
remainder = str.length % 3
|
188
|
+
central_length = remainder == 1 ? m+1 : m
|
189
|
+
lateral_length = remainder == 2 ? m+1 : m
|
190
|
+
colora( left_color, str[ 0 .. lateral_length-1] ) +
|
191
|
+
colora( middle_color, str[ lateral_length .. lateral_length+central_length-1] ) +
|
192
|
+
colora( right_color, str[ lateral_length+central_length .. str.length ] )
|
193
|
+
end
|
194
|
+
|
195
|
+
def flag_n(str,colors)
|
196
|
+
size = colors.size
|
197
|
+
#debug_on :flag6
|
198
|
+
ret = ""
|
199
|
+
m = str.length / size # chunk size
|
200
|
+
deb m
|
201
|
+
(0 .. size-1).each{|i|
|
202
|
+
#deb "Passo #{i}"
|
203
|
+
chunk = str[m*(i),m*(i+1)]
|
204
|
+
#deb chunk
|
205
|
+
ret += colora(colors[i], chunk )
|
206
|
+
}
|
207
|
+
#deb str.split(/....../)
|
208
|
+
#remainder = str.length % 6
|
209
|
+
return ret + " (bacatino)"
|
210
|
+
# central_length = remainder == 1 ? m+1 : m
|
211
|
+
# lateral_length = remainder == 2 ? m+1 : m
|
212
|
+
# colora( left_color, str[ 0 .. lateral_length-1] ) +
|
213
|
+
# colora( middle_color, str[ lateral_length .. lateral_length+central_length-1] ) +
|
214
|
+
# colora( right_color, str[ lateral_length+central_length .. str.length ] )
|
215
|
+
# return ret
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
###################################################################################################################
|
220
|
+
# COLORS LIBRARY
|
221
|
+
=begin
|
222
|
+
nero) shift; echo -en "\033[0;30m$*\033[0m\n" ;;
|
223
|
+
rossone) shift; echo -en "\033[0;31m$*\033[0m\n" ;;
|
224
|
+
verdone) shift; echo -en "\033[0;32m$*\033[0m\n" ;;
|
225
|
+
marrone) shift; echo -en "\033[0;33m$*\033[0m\n" ;;
|
226
|
+
bluino) shift; echo -en "\033[0;34m$*\033[0m\n" ;;
|
227
|
+
porpora) shift; echo -en "\033[0;35m$*\033[0m\n" ;;
|
228
|
+
ciano) shift; echo -en "\033[0;36m$*\033[0m\n" ;;
|
229
|
+
grigino) shift; echo -en "\033[0;37m$*\033[0m\n" ;;
|
230
|
+
|
231
|
+
grigione) shift; echo -en "\033[1;30m$*\033[0m\n" ;;
|
232
|
+
rosso) shift; echo -en "\033[1;31m$*\033[0m\n" ;;
|
233
|
+
verde) shift; echo -en "\033[1;32m$*\033[0m\n" ;;
|
234
|
+
giallo) shift; echo -en "\033[1;33m$*\033[0m\n" ;;
|
235
|
+
blu) shift; echo -en "\033[1;34m$*\033[0m\n" ;;
|
236
|
+
viola) shift; echo -en "\033[1;35m$*\033[0m\n" ;;
|
237
|
+
azzurro) shift; echo -en "\033[1;36m$*\033[0m\n" ;;
|
238
|
+
bianco) shift; echo -en "\033[1;37m$*\033[0m\n" ;;
|
239
|
+
|
240
|
+
arancio) shift; echo -en "\033[5;31m$*\033[0m\n" ;;
|
241
|
+
|
242
|
+
colour_codes = {
|
243
|
+
'black': '\033[0;30m',
|
244
|
+
'red': '\033[0;31m',
|
245
|
+
'green': '\033[0;32m',
|
246
|
+
'yellow': '\033[0;33m',
|
247
|
+
'blue': '\033[0;34m',
|
248
|
+
'magenta': '\033[0;35m',
|
249
|
+
'cyan': '\033[0;36m',
|
250
|
+
'white': '\033[0;37m',
|
251
|
+
'darkgray': '\033[1;30m',
|
252
|
+
'br-red': '\033[1;31m',
|
253
|
+
'br-green': '\033[1;32m',
|
254
|
+
'br-yellow': '\033[1;33m',
|
255
|
+
'br-blue': '\033[1;34m',
|
256
|
+
'br-magenta': '\033[1;35m',
|
257
|
+
'br-cyan': '\033[1;36m',
|
258
|
+
'br-white': '\033[1;37m',
|
259
|
+
'ul-black': '\033[4;30m',
|
260
|
+
'ul-red': '\033[4;31m',
|
261
|
+
'ul-green': '\033[4;32m',
|
262
|
+
'ul-yellow': '\033[4;33m',
|
263
|
+
'ul-blue': '\033[4;34m',
|
264
|
+
'ul-magenta': '\033[4;35m',
|
265
|
+
'ul-cyan': '\033[4;36m',
|
266
|
+
'ul-white': '\033[4;37m',
|
267
|
+
'default': '\033[0m'
|
268
|
+
}
|
269
|
+
=end
|
270
|
+
|
271
|
+
class RicColor < String
|
272
|
+
attr :color
|
273
|
+
|
274
|
+
def initialize(mycol)
|
275
|
+
super
|
276
|
+
@color = mycol
|
277
|
+
end
|
278
|
+
|
279
|
+
def to_s
|
280
|
+
'RicColor: ' + self.send(@color)
|
281
|
+
end
|
282
|
+
|
283
|
+
def to_html
|
284
|
+
"<font color=\"#{@color}\" >#{self}</font>"
|
285
|
+
end
|
286
|
+
end #/Class RicColor
|
287
|
+
|
288
|
+
def terminal
|
289
|
+
ENV['TERM_PROGRAM'] || 'suppongo_ssh'
|
290
|
+
end
|
291
|
+
|
292
|
+
def daltonic_terminal?()
|
293
|
+
deb( "Terminal is: " + terminal )
|
294
|
+
return !! terminal.to_s.match( /Apple_Terminal/ )
|
295
|
+
end
|
296
|
+
|
297
|
+
end # /module
|
298
|
+
|
299
|
+
#$colors_active = ! RicColor.daltonic_terminal? # DEFAULT: active
|
data/ric.gemspec
CHANGED
@@ -2,19 +2,18 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{ric}
|
5
|
-
s.version = "0.9.
|
5
|
+
s.version = "0.9.6file"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Riccardo Carlesso"]
|
9
9
|
s.date = %q{2011-01-16}
|
10
|
-
s.default_executable = %q{ric}
|
11
10
|
s.description = %q{My first gem with various utilities (colors and tests now).
|
12
11
|
My name is Riccardo, hence 'ric' (ok I admit it, this was just ot prove Im able to build a sentence
|
13
12
|
with hence!)}
|
14
13
|
s.email = %q{['p','ll','diusbonton].join('a') @ gmail.com}
|
15
|
-
s.executables = ["ric"]
|
16
|
-
s.extra_rdoc_files = ["README.md", "TODO", "bin/ric", "lib/helpers/rails_helper.rb", "lib/ric.rb", "lib/ric/
|
17
|
-
s.files = ["Manifest", "README.md", "Rakefile", "TODO", "bin/ric", "init.rb", "lib/helpers/rails_helper.rb", "lib/ric.rb", "lib/ric/
|
14
|
+
s.executables = ["itunes", "ric", "riclib-test"]
|
15
|
+
s.extra_rdoc_files = ["README.md", "TODO", "bin/itunes", "bin/ric", "bin/riclib-test", "lib/helpers/rails_helper.rb", "lib/ric.rb", "lib/ric/html.rb", "lib/ric_colors.rb", "lib/uniquify.rb"]
|
16
|
+
s.files = ["HISTORY.yml", "Manifest", "README.md", "Rakefile", "TODO", "VERSION", "bin/itunes", "bin/ric", "bin/riclib-test", "init.rb", "lib/helpers/rails_helper.rb", "lib/ric.rb", "lib/ric/html.rb", "lib/ric_colors.rb", "lib/uniquify.rb", "var/www/index.html", "ric.gemspec"]
|
18
17
|
s.homepage = %q{http://github.com/palladius/riclib}
|
19
18
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ric", "--main", "README.md"]
|
20
19
|
s.require_paths = ["lib"]
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ric
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: -1144627187
|
5
|
+
prerelease: 5
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
|
9
|
+
- 6
|
10
|
+
- file
|
11
|
+
version: 0.9.6file
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Riccardo Carlesso
|
@@ -25,32 +26,40 @@ description: |-
|
|
25
26
|
with hence!)
|
26
27
|
email: "['p','ll','diusbonton].join('a') @ gmail.com"
|
27
28
|
executables:
|
29
|
+
- itunes
|
28
30
|
- ric
|
31
|
+
- riclib-test
|
29
32
|
extensions: []
|
30
33
|
|
31
34
|
extra_rdoc_files:
|
32
35
|
- README.md
|
33
36
|
- TODO
|
37
|
+
- bin/itunes
|
34
38
|
- bin/ric
|
39
|
+
- bin/riclib-test
|
35
40
|
- lib/helpers/rails_helper.rb
|
36
41
|
- lib/ric.rb
|
37
|
-
- lib/ric/colors.rb
|
38
42
|
- lib/ric/html.rb
|
43
|
+
- lib/ric_colors.rb
|
39
44
|
- lib/uniquify.rb
|
40
45
|
files:
|
46
|
+
- HISTORY.yml
|
41
47
|
- Manifest
|
42
48
|
- README.md
|
43
49
|
- Rakefile
|
44
50
|
- TODO
|
51
|
+
- VERSION
|
52
|
+
- bin/itunes
|
45
53
|
- bin/ric
|
54
|
+
- bin/riclib-test
|
46
55
|
- init.rb
|
47
56
|
- lib/helpers/rails_helper.rb
|
48
57
|
- lib/ric.rb
|
49
|
-
- lib/ric/colors.rb
|
50
58
|
- lib/ric/html.rb
|
59
|
+
- lib/ric_colors.rb
|
51
60
|
- lib/uniquify.rb
|
52
|
-
- ric.gemspec
|
53
61
|
- var/www/index.html
|
62
|
+
- ric.gemspec
|
54
63
|
has_rdoc: true
|
55
64
|
homepage: http://github.com/palladius/riclib
|
56
65
|
licenses: []
|
data/lib/ric/colors.rb
DELETED
@@ -1,299 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# $Id: ric_colors.rb 5438 2010-12-16 15:06:29Z rcarlesso $
|
4
|
-
|
5
|
-
module Ric::Colors
|
6
|
-
|
7
|
-
$colors_active = true # DEFAULT: active
|
8
|
-
$color_db = [
|
9
|
-
%w{ normal black dkblack red green brown blue purple cyan lgray gray lred lgreen yellow lblue violet azure white orange orangey magenta lyellow pink gold } , # english word
|
10
|
-
%w{ normale nero nerone rosso verde marrone blu porpora ciano grigino grigione rossino verdino giallo lblu viola azzurro bianco arancio arancino magenta giallino rosa oro } , # italian word
|
11
|
-
%w{ 0;37 0;30 38;5;236 0;31 1;32 38;5;94 0;34 1;35 0;36 0;37 1;30 1;31 1;32 1;33 1;34 1;35 1;36 1;37 38;5;208 38;5;222 0;35 38;5;229 38;5;203 38;5;214 } ,
|
12
|
-
%w{ 000 000 222 f00 0f0 00f ff0 0ff aaa 888 f00 afa ff0 eebb00 } # HEX RGB
|
13
|
-
]
|
14
|
-
# rifallo, e' piu' manutenibile...
|
15
|
-
$color_db2 = [
|
16
|
-
# [ ARR_COLORS , ]
|
17
|
-
%w{ black nero 0;30 000 },
|
18
|
-
%w{ dkblack nerone 38;5;236 222 },
|
19
|
-
]
|
20
|
-
|
21
|
-
# alias viola = fuxia
|
22
|
-
|
23
|
-
def colors_on
|
24
|
-
set_color :on #(true)
|
25
|
-
end
|
26
|
-
def colors_off
|
27
|
-
set_color :off #(false)
|
28
|
-
end
|
29
|
-
|
30
|
-
# TODO support a block (solo dentro l blocco fai il nocolor)
|
31
|
-
def set_color(bool)
|
32
|
-
b = bool ? true : false
|
33
|
-
deb "Setting color mode to: #{yellow bool} --> #{white b.to_s}"
|
34
|
-
b = false if bool.to_s.match( /(off|false)/ )
|
35
|
-
deb "Setting color mode to: #{yellow bool} --> #{white b.to_s}"
|
36
|
-
$colors_active = bool
|
37
|
-
end
|
38
|
-
alias :set_colors :set_color
|
39
|
-
|
40
|
-
def bash_color(n, str )
|
41
|
-
"\033[#{n}m#{str}\033[0m"
|
42
|
-
end
|
43
|
-
|
44
|
-
def pcolor(color_name='red',str='COLOR: please define a string')
|
45
|
-
if $colors_active
|
46
|
-
puts colora(color_name,str)
|
47
|
-
else
|
48
|
-
puts str
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def visible_color(s)
|
53
|
-
!( s.match(/nero|black/) )
|
54
|
-
end
|
55
|
-
|
56
|
-
def colora(color_name='greenpurpureo',str='colora_test_str2', opts={})
|
57
|
-
color_name = color_name.to_s
|
58
|
-
return str unless $colors_active
|
59
|
-
return str if opts[:nocolor]
|
60
|
-
if ix = $color_db[0].index(color_name)
|
61
|
-
bash_color($color_db[2][ix],str)
|
62
|
-
elsif ix = $color_db[1].index(color_name)
|
63
|
-
bash_color($color_db[2][ix],str)
|
64
|
-
else
|
65
|
-
debug "Sorry, unknown color '#{color_name}'. Available ones are: #{$color_db[0].join(',') }"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
alias :p :puts
|
70
|
-
|
71
|
-
def color_test(with_italian = false)
|
72
|
-
i=0
|
73
|
-
palette = $color_db[0].map { |c|
|
74
|
-
inglese = c
|
75
|
-
italiano = $color_db[1][i]
|
76
|
-
i = i+1
|
77
|
-
colora( c, with_italian ? [c,italiano].join(','): c )
|
78
|
-
}
|
79
|
-
puts( (1..257).map{|c| bash_color( "38;5;#{c}", c) }.join(', ') )
|
80
|
-
puts( palette.sort.join(' '))
|
81
|
-
_flag_nations.each{|nation|
|
82
|
-
puts "- Flag sample: " + flag("ThisIsAFlaggedPhraseBasedOnNation:#{nation}",nation)
|
83
|
-
}
|
84
|
-
end
|
85
|
-
alias :colortest :color_test
|
86
|
-
|
87
|
-
# carattere per carattere...
|
88
|
-
def rainbow(str)
|
89
|
-
i=0
|
90
|
-
ret = ''
|
91
|
-
str=str.to_s
|
92
|
-
while(i < str.length)
|
93
|
-
ch = str[i]
|
94
|
-
palette = $color_db[0][i % $color_db[0].length ]
|
95
|
-
ret << (colora(palette,str[i,1]))
|
96
|
-
i += 1
|
97
|
-
end
|
98
|
-
ret
|
99
|
-
end
|
100
|
-
alias :arcobaleno :rainbow
|
101
|
-
|
102
|
-
#assert(color_db[0].length == color_db[1].length,"English and italian colors must be the same cardinality!!!")
|
103
|
-
# TODO ripeti con , $color_db[1]
|
104
|
-
( $color_db[0] + $color_db[1] ).each { |colorname|
|
105
|
-
dyn_func = "
|
106
|
-
|
107
|
-
def get_#{colorname} (str='colors.rb: get_COLOR dynamically generated ENGLISH COLOR ')
|
108
|
-
return colora('#{colorname}',str)
|
109
|
-
end
|
110
|
-
|
111
|
-
def #{colorname} (str='colors.rb: COLOR dynamically generated ENGLISH COLOR TO BE COPIED TO GET')
|
112
|
-
return colora('#{colorname}',str) rescue
|
113
|
-
\"Errore #{colorname} con stringa '#"+"{str}' e classe #"+"{str.class} \"
|
114
|
-
end
|
115
|
-
|
116
|
-
def p#{colorname} (str='colors.rb: pCOLOR dynamically generated ENGLISH COLOR TO BE DESTROYED')
|
117
|
-
puts colora('#{colorname}',str)
|
118
|
-
end
|
119
|
-
|
120
|
-
"
|
121
|
-
#debug dyn_func
|
122
|
-
eval dyn_func unless method_defined?( "get_#{colorname}".to_sym )
|
123
|
-
#remove_method
|
124
|
-
}
|
125
|
-
|
126
|
-
def okno(bool,str=nil)
|
127
|
-
str ||= bool
|
128
|
-
bool = (bool == 0 ) if (bool.class == Fixnum) # so 0 is green, others are red :)
|
129
|
-
return bool ? green(str) : red(str)
|
130
|
-
end
|
131
|
-
|
132
|
-
def colors_flag(nation = 'it')
|
133
|
-
%w{ red white green }
|
134
|
-
end
|
135
|
-
|
136
|
-
# "\e[0;31m42\e[0m" --> "42"
|
137
|
-
# \e[38;5;28mXXXX -> "XXX"
|
138
|
-
def scolora(str)
|
139
|
-
str.to_s.
|
140
|
-
gsub(/\e\[1;33m/,''). # colori 16
|
141
|
-
gsub(/\e\[0m/,''). # colori 64k
|
142
|
-
gsub(/\e\[38;\d+;\d+m/,'') # end color
|
143
|
-
end
|
144
|
-
alias :uncolor :scolora
|
145
|
-
|
146
|
-
# italia: green white red
|
147
|
-
# ireland: green white orange
|
148
|
-
# france: green white orange
|
149
|
-
# UK: blue white red white blue
|
150
|
-
# google:
|
151
|
-
def _flag_nations
|
152
|
-
%w{cc it de ie fr es en goo br pt}
|
153
|
-
end
|
154
|
-
def flag(str, flag = '')
|
155
|
-
case flag.to_s
|
156
|
-
when 'br','pt'
|
157
|
-
return flag3(str, 'green', 'gold', 'green')
|
158
|
-
when 'cc'
|
159
|
-
return flag3(str, 'red', 'white', 'red') # switzerland
|
160
|
-
when 'de'
|
161
|
-
return flag3(str, 'dkblack', 'red', 'gold')
|
162
|
-
when 'ie','gd','ga'
|
163
|
-
return flag3(str, 'green', 'white', 'orange')# non so la differenza, sembrano entrambi gaelici!
|
164
|
-
when 'en'
|
165
|
-
return flag3(str, 'red', 'blue', 'red') # red white blue white red white blue white ... and again
|
166
|
-
when 'es'
|
167
|
-
return flag3(str, 'yellow', 'red', 'yellow')
|
168
|
-
when 'fr'
|
169
|
-
return flag3(str, 'blue', 'white', 'red')
|
170
|
-
when 'goo','google'
|
171
|
-
return flag_n(str, %w{ blue red yellow blue green red } )
|
172
|
-
when 'it'
|
173
|
-
return flag3(str, 'green', 'white', 'red')
|
174
|
-
when ''
|
175
|
-
return flag3(str + " (missing flag1, try 'it')")
|
176
|
-
end
|
177
|
-
return flag3(str + " (missing flag2, try 'it')")
|
178
|
-
end
|
179
|
-
|
180
|
-
# for simmetry padding
|
181
|
-
# m = length / 3
|
182
|
-
# 6: 2 2 2 m m m REST 0
|
183
|
-
# 5: 2 1 2 m+1 m m+1 2
|
184
|
-
# 4: 1 2 1 m m+1 m 1
|
185
|
-
def flag3(str,left_color='brown',middle_color='pink',right_color='red')
|
186
|
-
m = str.length / 3
|
187
|
-
remainder = str.length % 3
|
188
|
-
central_length = remainder == 1 ? m+1 : m
|
189
|
-
lateral_length = remainder == 2 ? m+1 : m
|
190
|
-
colora( left_color, str[ 0 .. lateral_length-1] ) +
|
191
|
-
colora( middle_color, str[ lateral_length .. lateral_length+central_length-1] ) +
|
192
|
-
colora( right_color, str[ lateral_length+central_length .. str.length ] )
|
193
|
-
end
|
194
|
-
|
195
|
-
def flag_n(str,colors)
|
196
|
-
size = colors.size
|
197
|
-
#debug_on :flag6
|
198
|
-
ret = ""
|
199
|
-
m = str.length / size # chunk size
|
200
|
-
deb m
|
201
|
-
(0 .. size-1).each{|i|
|
202
|
-
#deb "Passo #{i}"
|
203
|
-
chunk = str[m*(i),m*(i+1)]
|
204
|
-
#deb chunk
|
205
|
-
ret += colora(colors[i], chunk )
|
206
|
-
}
|
207
|
-
#deb str.split(/....../)
|
208
|
-
#remainder = str.length % 6
|
209
|
-
return ret + " (bacatino)"
|
210
|
-
# central_length = remainder == 1 ? m+1 : m
|
211
|
-
# lateral_length = remainder == 2 ? m+1 : m
|
212
|
-
# colora( left_color, str[ 0 .. lateral_length-1] ) +
|
213
|
-
# colora( middle_color, str[ lateral_length .. lateral_length+central_length-1] ) +
|
214
|
-
# colora( right_color, str[ lateral_length+central_length .. str.length ] )
|
215
|
-
# return ret
|
216
|
-
end
|
217
|
-
|
218
|
-
|
219
|
-
###################################################################################################################
|
220
|
-
# COLORS LIBRARY
|
221
|
-
=begin
|
222
|
-
nero) shift; echo -en "\033[0;30m$*\033[0m\n" ;;
|
223
|
-
rossone) shift; echo -en "\033[0;31m$*\033[0m\n" ;;
|
224
|
-
verdone) shift; echo -en "\033[0;32m$*\033[0m\n" ;;
|
225
|
-
marrone) shift; echo -en "\033[0;33m$*\033[0m\n" ;;
|
226
|
-
bluino) shift; echo -en "\033[0;34m$*\033[0m\n" ;;
|
227
|
-
porpora) shift; echo -en "\033[0;35m$*\033[0m\n" ;;
|
228
|
-
ciano) shift; echo -en "\033[0;36m$*\033[0m\n" ;;
|
229
|
-
grigino) shift; echo -en "\033[0;37m$*\033[0m\n" ;;
|
230
|
-
|
231
|
-
grigione) shift; echo -en "\033[1;30m$*\033[0m\n" ;;
|
232
|
-
rosso) shift; echo -en "\033[1;31m$*\033[0m\n" ;;
|
233
|
-
verde) shift; echo -en "\033[1;32m$*\033[0m\n" ;;
|
234
|
-
giallo) shift; echo -en "\033[1;33m$*\033[0m\n" ;;
|
235
|
-
blu) shift; echo -en "\033[1;34m$*\033[0m\n" ;;
|
236
|
-
viola) shift; echo -en "\033[1;35m$*\033[0m\n" ;;
|
237
|
-
azzurro) shift; echo -en "\033[1;36m$*\033[0m\n" ;;
|
238
|
-
bianco) shift; echo -en "\033[1;37m$*\033[0m\n" ;;
|
239
|
-
|
240
|
-
arancio) shift; echo -en "\033[5;31m$*\033[0m\n" ;;
|
241
|
-
|
242
|
-
colour_codes = {
|
243
|
-
'black': '\033[0;30m',
|
244
|
-
'red': '\033[0;31m',
|
245
|
-
'green': '\033[0;32m',
|
246
|
-
'yellow': '\033[0;33m',
|
247
|
-
'blue': '\033[0;34m',
|
248
|
-
'magenta': '\033[0;35m',
|
249
|
-
'cyan': '\033[0;36m',
|
250
|
-
'white': '\033[0;37m',
|
251
|
-
'darkgray': '\033[1;30m',
|
252
|
-
'br-red': '\033[1;31m',
|
253
|
-
'br-green': '\033[1;32m',
|
254
|
-
'br-yellow': '\033[1;33m',
|
255
|
-
'br-blue': '\033[1;34m',
|
256
|
-
'br-magenta': '\033[1;35m',
|
257
|
-
'br-cyan': '\033[1;36m',
|
258
|
-
'br-white': '\033[1;37m',
|
259
|
-
'ul-black': '\033[4;30m',
|
260
|
-
'ul-red': '\033[4;31m',
|
261
|
-
'ul-green': '\033[4;32m',
|
262
|
-
'ul-yellow': '\033[4;33m',
|
263
|
-
'ul-blue': '\033[4;34m',
|
264
|
-
'ul-magenta': '\033[4;35m',
|
265
|
-
'ul-cyan': '\033[4;36m',
|
266
|
-
'ul-white': '\033[4;37m',
|
267
|
-
'default': '\033[0m'
|
268
|
-
}
|
269
|
-
=end
|
270
|
-
|
271
|
-
class RicColor < String
|
272
|
-
attr :color
|
273
|
-
|
274
|
-
def initialize(mycol)
|
275
|
-
super
|
276
|
-
@color = mycol
|
277
|
-
end
|
278
|
-
|
279
|
-
def to_s
|
280
|
-
'RicColor: ' + self.send(@color)
|
281
|
-
end
|
282
|
-
|
283
|
-
def to_html
|
284
|
-
"<font color=\"#{@color}\" >#{self}</font>"
|
285
|
-
end
|
286
|
-
end #/Class RicColor
|
287
|
-
|
288
|
-
def terminal
|
289
|
-
ENV['TERM_PROGRAM'] || 'suppongo_ssh'
|
290
|
-
end
|
291
|
-
|
292
|
-
def daltonic_terminal?()
|
293
|
-
deb( "Terminal is: " + terminal )
|
294
|
-
return !! terminal.to_s.match( /Apple_Terminal/ )
|
295
|
-
end
|
296
|
-
|
297
|
-
end # /module
|
298
|
-
|
299
|
-
#$colors_active = ! RicColor.daltonic_terminal? # DEFAULT: active
|