miniric 0.6 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ric_colors.rb +301 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ced8aba060ec6f916a85a4dd5431065e922f1acbf5591a1ac5e6aa99f6ddc19f
|
4
|
+
data.tar.gz: dd16abeeb1793941f860096eb1f516bae0d163b380a82407eaec1c19ec5b476b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cfabdb51d020763ac8cd381a29df5154ca7ffc131bc24efe674bba482abb31af1b58543da03b5afbf8a8c1bf757848cea2dab502ad5036c1cac187d312ac43e
|
7
|
+
data.tar.gz: 145fb34ba36c6d02118f0d9f3cbdea50ace362c1e79ef9bd1458c531b3bd40408a796b938572650741e81310709690c09befc6feaceaee167d9a260c6a06b049
|
data/lib/ric_colors.rb
ADDED
@@ -0,0 +1,301 @@
|
|
1
|
+
# PLease forgive me this is going to be obsoleted soon
|
2
|
+
|
3
|
+
module MiniricColors
|
4
|
+
|
5
|
+
$debug_pad_colors = nil # [ '(',')']
|
6
|
+
$colors_active = false
|
7
|
+
|
8
|
+
$color_db = [
|
9
|
+
%w{ normal black2 black dkblack red green brown blue midngihtblue purple cyan lgray gray lred lgreen yellow lblue violet azure white orange orange2 orangey magenta lyellow pink dkpink gold dkgreen carminio vermiglio bordeaux kawasaki azure2 indigo } , # english word
|
10
|
+
%w{ normale nero2 nero nerone rosso verde marrone blu bluenotte porpora ciano grigino grigione rossino verdino giallo lblu viola azzurro bianco arancio arancio2 arancino magenta giallino rosa rosino oro verdone carminio vermiglio bordo kawasaki azzurro2 indaco } , # italian word
|
11
|
+
%w{ 0;37 0;30 38;5;233 38;5;236 0;31 1;32 38;5;94 0;34 38;5;17 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;166 38;5;222 0;35 38;5;229 38;5;204 38;5;203 38;5;214 38;5;28 38;5;196 38;5;125 38;5;89 38;5;119 38;5;45 38;5;57 } ,
|
12
|
+
%w{ 000 000 111 222 f00 0f0 00f 191970 ff0 0ff aaa 888 f00 afa ff0 eebb00 } # HEX RGB
|
13
|
+
]
|
14
|
+
|
15
|
+
def colors_on
|
16
|
+
set_color :on #(true)
|
17
|
+
end
|
18
|
+
def colors_off
|
19
|
+
set_color(false)
|
20
|
+
end
|
21
|
+
|
22
|
+
# TODO support a block (solo dentro l blocco fai il nocolor)
|
23
|
+
def set_color(bool)
|
24
|
+
b = bool ? true : false
|
25
|
+
deb "Setting color mode to: #{yellow bool} --> #{white b.to_s}"
|
26
|
+
b = false if bool.to_s.match( /(off|false)/ )
|
27
|
+
deb "Setting color mode to: #{yellow bool} --> #{white b.to_s}"
|
28
|
+
if block_given?
|
29
|
+
puts "TODO!!! scolara qui"
|
30
|
+
yield
|
31
|
+
puts "TODO ricolora qui"
|
32
|
+
end
|
33
|
+
$colors_active = bool
|
34
|
+
end
|
35
|
+
alias :set_colors :set_color
|
36
|
+
|
37
|
+
def bash_color(n, str )
|
38
|
+
"\033[#{n}m#{str}\033[0m"
|
39
|
+
end
|
40
|
+
|
41
|
+
def pcolor(color_name='red',str='COLOR: please define a string')
|
42
|
+
if $colors_active
|
43
|
+
puts colora(color_name,str)
|
44
|
+
else
|
45
|
+
puts str
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def visible_color(s)
|
50
|
+
!( s.match(/nero|black/) )
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def colora(color_name='greenpurpureo',str='colora_test_str2', opts={})
|
55
|
+
color_name = color_name.to_s
|
56
|
+
str = $debug_pad_colors ? $debug_pad_colors.join(str) : str # Adding '(2πi)'
|
57
|
+
return str unless $colors_active
|
58
|
+
return str if opts[:nocolor]
|
59
|
+
if ix = $color_db[0].index(color_name)
|
60
|
+
bash_color($color_db[2][ix],str)
|
61
|
+
elsif ix = $color_db[1].index(color_name)
|
62
|
+
bash_color($color_db[2][ix],str)
|
63
|
+
else
|
64
|
+
debug "Sorry, unknown color '#{color_name}'. Available ones are: #{$color_db[0].join(',') }"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
alias :p :puts
|
69
|
+
|
70
|
+
def color_test(with_italian = false)
|
71
|
+
i=0
|
72
|
+
palette = $color_db[0].map { |c|
|
73
|
+
#inglese = c
|
74
|
+
italiano = $color_db[1][i]
|
75
|
+
i = i+1
|
76
|
+
colora( c, with_italian ? [c,italiano].join(','): c )
|
77
|
+
}
|
78
|
+
puts( (1..257).map{|c| bash_color( "38;5;#{c}", c) }.join(', ') )
|
79
|
+
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)
|
80
|
+
_flag_nations.sort.each{|nation|
|
81
|
+
puts "- Flag sample for #{nation}:\t" + flag("ThisIsAFlaggedPhraseBasedOnNation:#{nation}",nation)
|
82
|
+
}
|
83
|
+
end
|
84
|
+
alias :colortest :color_test
|
85
|
+
|
86
|
+
# carattere per carattere...
|
87
|
+
def rainbow(str)
|
88
|
+
i=0
|
89
|
+
ret = ''
|
90
|
+
str=str.to_s
|
91
|
+
while(i < str.length)
|
92
|
+
#ch = str[i]
|
93
|
+
palette = $color_db[0][i % $color_db[0].length ]
|
94
|
+
ret << (colora(palette,str[i,1]))
|
95
|
+
i += 1
|
96
|
+
end
|
97
|
+
ret
|
98
|
+
end
|
99
|
+
alias :arcobaleno :rainbow
|
100
|
+
|
101
|
+
#assert(color_db[0].length == color_db[1].length,"English and italian colors must be the same cardinality!!!")
|
102
|
+
# TODO ripeti con , $color_db[1]
|
103
|
+
( $color_db[0] + $color_db[1] ).each { |colorname|
|
104
|
+
dyn_func = "
|
105
|
+
|
106
|
+
def get_#{colorname} (str='colors.rb: get_COLOR dynamically generated ENGLISH COLOR ')
|
107
|
+
return colora('#{colorname}',str)
|
108
|
+
end
|
109
|
+
|
110
|
+
def #{colorname} (str='colors.rb: COLOR dynamically generated ENGLISH COLOR TO BE COPIED TO GET')
|
111
|
+
return colora('#{colorname}',str) rescue
|
112
|
+
\"Errore #{colorname} con stringa '#"+"{str}' e classe #"+"{str.class} \"
|
113
|
+
end
|
114
|
+
|
115
|
+
def p#{colorname} (str='colors.rb: pCOLOR dynamically generated ENGLISH COLOR TO BE DESTROYED')
|
116
|
+
puts colora('#{colorname}',str)
|
117
|
+
end
|
118
|
+
"
|
119
|
+
eval dyn_func unless method_defined?( "get_#{colorname}".to_sym )
|
120
|
+
}
|
121
|
+
|
122
|
+
def okno(bool,str=nil)
|
123
|
+
str ||= bool
|
124
|
+
bool = (bool == 0 ) if (bool.class == Fixnum) # so 0 is green, others are red :)
|
125
|
+
return bool ? green(str) : red(str)
|
126
|
+
end
|
127
|
+
|
128
|
+
def colors_flag(nation = 'it')
|
129
|
+
%w{ red white green }
|
130
|
+
end
|
131
|
+
|
132
|
+
# "\e[0;31m42\e[0m" --> "42"
|
133
|
+
# \e[38;5;28mXXXX -> "XXX"
|
134
|
+
def scolora(str)
|
135
|
+
str.to_s.
|
136
|
+
gsub(/\e\[1;33m/,''). # colori 16
|
137
|
+
gsub(/\e\[0m/,''). # colori 64k
|
138
|
+
gsub(/\e\[38;\d+;\d+m/,'') # end color
|
139
|
+
end
|
140
|
+
alias :uncolor :scolora
|
141
|
+
|
142
|
+
# italia: green white red
|
143
|
+
# ireland: green white orange
|
144
|
+
# france: green white orange
|
145
|
+
# UK: blue white red white blue
|
146
|
+
# google:
|
147
|
+
# TODO: autolist wiht something like
|
148
|
+
# flag 'at', red white red
|
149
|
+
def _flag_nations
|
150
|
+
%w{ar at cc it de ie fr es en goo br po pt }.sort
|
151
|
+
end
|
152
|
+
def flag(str, flag = '')
|
153
|
+
case flag.to_s
|
154
|
+
when 'ar','argentina'
|
155
|
+
return flag3(str, 'azure2', 'white', 'cyan')
|
156
|
+
when 'at','austria'
|
157
|
+
return flag3(str, 'red', 'white', 'red')
|
158
|
+
when 'br','pt','brazil'
|
159
|
+
return flag3(str, 'dkgreen', 'gold', 'dkgreen')
|
160
|
+
when 'cc'
|
161
|
+
return flag3(str, 'red', 'white', 'red') # switzerland
|
162
|
+
when 'de'
|
163
|
+
return flag3(str, 'dkblack', 'red', 'gold')
|
164
|
+
when 'ie','gd','ga','ireland'
|
165
|
+
return flag3(str, 'dkgreen', 'white', 'orange')# non so la differenza, sembrano entrambi gaelici!
|
166
|
+
when 'en','uk'
|
167
|
+
return flag3(str, 'red', 'blue', 'red') # red white blue white red white blue white ... and again
|
168
|
+
when 'es'
|
169
|
+
return flag3(str, 'yellow', 'red', 'yellow')
|
170
|
+
when 'fr'
|
171
|
+
return flag3(str, 'blue', 'white', 'red')
|
172
|
+
when 'goo','google'
|
173
|
+
return flag_n(str, %w{ blue red yellow blue green red } )
|
174
|
+
when 'it'
|
175
|
+
return flag3(str, 'dkgreen', 'white', 'red')
|
176
|
+
when 'po'
|
177
|
+
return flag2(str, 'white', 'red')
|
178
|
+
when ''
|
179
|
+
return flag3(str + " (missing flag for empty string, try 'it')")
|
180
|
+
end
|
181
|
+
return flag3(str + " (missing flag for unrecognized symbol, try 'it')")
|
182
|
+
end
|
183
|
+
|
184
|
+
# for simmetry padding
|
185
|
+
# m = length / 3
|
186
|
+
# 6: 2 2 2 m m m REST 0
|
187
|
+
# 5: 2 1 2 m+1 m m+1 2
|
188
|
+
# 4: 1 2 1 m m+1 m 1
|
189
|
+
def flag3(str,left_color='brown',middle_color='pink',right_color='red')
|
190
|
+
m = str.length / 3
|
191
|
+
remainder = str.length % 3
|
192
|
+
central_length = remainder == 1 ? m+1 : m
|
193
|
+
lateral_length = remainder == 2 ? m+1 : m
|
194
|
+
colora( left_color, str[ 0 .. lateral_length-1] ) +
|
195
|
+
colora( middle_color, str[ lateral_length .. lateral_length+central_length-1] ) +
|
196
|
+
colora( right_color, str[ lateral_length+central_length .. str.length ] )
|
197
|
+
end
|
198
|
+
def flag2(str,left_color='brown',right_color='pink')
|
199
|
+
flag_n(str, [left_color, right_color] )
|
200
|
+
end
|
201
|
+
|
202
|
+
def flag_n(str,colors)
|
203
|
+
size = colors.size
|
204
|
+
ret = ""
|
205
|
+
m = str.length / size # chunk size
|
206
|
+
deb m
|
207
|
+
(0 .. size-1).each{|i|
|
208
|
+
chunk = str[m*(i),m*(i+1)]
|
209
|
+
ret += colora(colors[i], chunk )
|
210
|
+
}
|
211
|
+
|
212
|
+
return ret
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
###################################################################################################################
|
217
|
+
# COLORS LIBRARY
|
218
|
+
=begin
|
219
|
+
nero) shift; echo -en "\033[0;30m$*\033[0m\n" ;;
|
220
|
+
rossone) shift; echo -en "\033[0;31m$*\033[0m\n" ;;
|
221
|
+
verdone) shift; echo -en "\033[0;32m$*\033[0m\n" ;;
|
222
|
+
marrone) shift; echo -en "\033[0;33m$*\033[0m\n" ;;
|
223
|
+
bluino) shift; echo -en "\033[0;34m$*\033[0m\n" ;;
|
224
|
+
porpora) shift; echo -en "\033[0;35m$*\033[0m\n" ;;
|
225
|
+
ciano) shift; echo -en "\033[0;36m$*\033[0m\n" ;;
|
226
|
+
grigino) shift; echo -en "\033[0;37m$*\033[0m\n" ;;
|
227
|
+
|
228
|
+
grigione) shift; echo -en "\033[1;30m$*\033[0m\n" ;;
|
229
|
+
rosso) shift; echo -en "\033[1;31m$*\033[0m\n" ;;
|
230
|
+
verde) shift; echo -en "\033[1;32m$*\033[0m\n" ;;
|
231
|
+
giallo) shift; echo -en "\033[1;33m$*\033[0m\n" ;;
|
232
|
+
blu) shift; echo -en "\033[1;34m$*\033[0m\n" ;;
|
233
|
+
viola) shift; echo -en "\033[1;35m$*\033[0m\n" ;;
|
234
|
+
azzurro) shift; echo -en "\033[1;36m$*\033[0m\n" ;;
|
235
|
+
bianco) shift; echo -en "\033[1;37m$*\033[0m\n" ;;
|
236
|
+
|
237
|
+
arancio) shift; echo -en "\033[5;31m$*\033[0m\n" ;;
|
238
|
+
|
239
|
+
colour_codes = {
|
240
|
+
'black': '\033[0;30m',
|
241
|
+
'red': '\033[0;31m',
|
242
|
+
'green': '\033[0;32m',
|
243
|
+
'yellow': '\033[0;33m',
|
244
|
+
'blue': '\033[0;34m',
|
245
|
+
'magenta': '\033[0;35m',
|
246
|
+
'cyan': '\033[0;36m',
|
247
|
+
'white': '\033[0;37m',
|
248
|
+
'darkgray': '\033[1;30m',
|
249
|
+
'br-red': '\033[1;31m',
|
250
|
+
'br-green': '\033[1;32m',
|
251
|
+
'br-yellow': '\033[1;33m',
|
252
|
+
'br-blue': '\033[1;34m',
|
253
|
+
'br-magenta': '\033[1;35m',
|
254
|
+
'br-cyan': '\033[1;36m',
|
255
|
+
'br-white': '\033[1;37m',
|
256
|
+
'ul-black': '\033[4;30m',
|
257
|
+
'ul-red': '\033[4;31m',
|
258
|
+
'ul-green': '\033[4;32m',
|
259
|
+
'ul-yellow': '\033[4;33m',
|
260
|
+
'ul-blue': '\033[4;34m',
|
261
|
+
'ul-magenta': '\033[4;35m',
|
262
|
+
'ul-cyan': '\033[4;36m',
|
263
|
+
'ul-white': '\033[4;37m',
|
264
|
+
'default': '\033[0m'
|
265
|
+
}
|
266
|
+
=end
|
267
|
+
|
268
|
+
class RicColor < String
|
269
|
+
attr :color
|
270
|
+
|
271
|
+
def initialize(mycol)
|
272
|
+
super
|
273
|
+
@color = mycol
|
274
|
+
end
|
275
|
+
|
276
|
+
def to_s
|
277
|
+
'RicColor: ' + self.send(@color)
|
278
|
+
end
|
279
|
+
|
280
|
+
def to_html
|
281
|
+
"<font color=\"#{@color}\" >#{self}</font>"
|
282
|
+
end
|
283
|
+
end #/Class RicColor
|
284
|
+
|
285
|
+
def terminal
|
286
|
+
ENV['TERM_PROGRAM'] || 'suppongo_ssh'
|
287
|
+
end
|
288
|
+
|
289
|
+
def daltonic_terminal?()
|
290
|
+
#return !! terminal.to_s.match( /Apple_Terminal/ )
|
291
|
+
return true if Socket.gethostname == 'hansel' && terminal.to_s.match( /Apple_Terminal/ )
|
292
|
+
false # at Google, Mac OS X 10.7 the normal terminal is 64k color !!!
|
293
|
+
end
|
294
|
+
|
295
|
+
|
296
|
+
end # /module
|
297
|
+
|
298
|
+
|
299
|
+
include MiniricColors
|
300
|
+
$colors_active = ! RicColor.daltonic_terminal? # DEFAULT: active
|
301
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miniric
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.7'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Riccardo Carlesso
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "This is a simple hello world gem copied from https://guides.rubygems.org/make-your-own-gem/.\n
|
14
14
|
\ Since I've been using echoe a number of times, this time I want to be able\n
|
@@ -25,11 +25,12 @@ files:
|
|
25
25
|
- bin/camerlengo
|
26
26
|
- lib/hola.rb
|
27
27
|
- lib/miniric.rb
|
28
|
+
- lib/ric_colors.rb
|
28
29
|
homepage: https://rubygems.org/gems/miniric
|
29
30
|
licenses:
|
30
31
|
- MIT
|
31
32
|
metadata: {}
|
32
|
-
post_install_message:
|
33
|
+
post_install_message:
|
33
34
|
rdoc_options: []
|
34
35
|
require_paths:
|
35
36
|
- lib
|
@@ -45,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
46
|
version: '0'
|
46
47
|
requirements: []
|
47
48
|
rubygems_version: 3.1.4
|
48
|
-
signing_key:
|
49
|
+
signing_key:
|
49
50
|
specification_version: 4
|
50
51
|
summary: MiniRic - Colors as a Service!
|
51
52
|
test_files: []
|