rmthemegen 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rmthemegen/geany_fix.rb +233 -0
- data/rmthemegen.gemspec +1 -1
- metadata +2 -2
- data/lib/rmt_remote_rock.xml +0 -2088
@@ -0,0 +1,233 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'xmlsimple'
|
3
|
+
require 'color'
|
4
|
+
require File.dirname(__FILE__)+"/token_list"
|
5
|
+
require File.dirname(__FILE__)+'/rgb_contrast_methods'
|
6
|
+
|
7
|
+
module RMThemeGen
|
8
|
+
class GeanyFixer < RMThemeParent
|
9
|
+
|
10
|
+
attr_reader :xmlout #a huge structure of xml that can be given to XmlSimple.xml_out() to create that actual color theme file
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@rand = Random.new
|
14
|
+
@iterations = 0
|
15
|
+
@iterations = ARGV[0].to_s.to_i
|
16
|
+
|
17
|
+
puts "geany_fix - puts a new (random) color theme into your geany directory"
|
18
|
+
puts " David Heitzman 2011 "
|
19
|
+
puts " Note: if you want to put back your old Geany colors, go to ~/.config/geany/filedefs/ and"
|
20
|
+
puts " copy the corresponding _old_xxx file back onto filetypes.xyz, eg. filetypes.html, etc. "
|
21
|
+
|
22
|
+
begin
|
23
|
+
@dir = (File.expand_path "~/.config/geany/filedefs/")+"/"
|
24
|
+
@filelist = Dir.glob(@dir+"filetypes.*")
|
25
|
+
# puts @dir+"filetypes.*"
|
26
|
+
# puts @filelist.inspect
|
27
|
+
t =Time.now
|
28
|
+
@extstring = t.year.to_s+t.month.to_s+t.day.to_s+t.sec.to_s
|
29
|
+
# rescue
|
30
|
+
# raise "Sorry. There was trouble accessing the files in " + @dir
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
@italic_candidates = ["STRING", "SYMBOL", "REQUIRE"]
|
35
|
+
|
36
|
+
@bold_candidates = ["KEYWORD","RUBY_SPECIFIC_CALL", "CONSTANT", "COMMA", "PAREN","RUBY_ATTR_ACCESSOR_CALL", "RUBY_ATTR_READER_CALL" ,"RUBY_ATTR_WRITER_CALL", "IDENTIFIER"]
|
37
|
+
# with code inspections we don't color the text, we just put a line or something under it .
|
38
|
+
@code_inspections = ["ERROR","WARNING_ATTRIBUTES","DEPRECATED", "TYPO","WARNING_ATTRIBUTES", "BAD_CHARACTER",
|
39
|
+
"CUSTOM_INVALID_STRING_ESCAPE_ATTRIBUTES","ERRORS_ATTRIBUTES", "MATCHED_BRACE_ATTRIBUTES"]
|
40
|
+
@cross_out = ["DEPRECATED_ATTRIBUTES" ]
|
41
|
+
|
42
|
+
@unders = %w(-1 0 1 2 5 )
|
43
|
+
@underline_candidates = ["STRING"]
|
44
|
+
@italic_chance = 0.2
|
45
|
+
@bold_chance = 0.4
|
46
|
+
@underline_chance = 0.3
|
47
|
+
@bright_median = 0.85
|
48
|
+
@min_bright = @bright_median * 0.65
|
49
|
+
@max_bright = [@bright_median * 1.35,1.0].max
|
50
|
+
|
51
|
+
@min_bright = 0.0
|
52
|
+
@max_bright = 1.0
|
53
|
+
|
54
|
+
# if we avoid any notion of "brightness", which is an absolute quality, then we
|
55
|
+
# can make our background any color we want !
|
56
|
+
|
57
|
+
#tighter contrast spec
|
58
|
+
@cont_median = 0.85
|
59
|
+
@min_cont = @cont_median * 0.65
|
60
|
+
@max_cont = [@cont_median * 1.35,1.0].max
|
61
|
+
|
62
|
+
#broad contrast spec
|
63
|
+
@min_cont = 0.32
|
64
|
+
@max_cont = 1.0
|
65
|
+
|
66
|
+
@schemeversion = 1
|
67
|
+
@background_max_brightness = 0.12
|
68
|
+
@background_grey = true #if false, allows background to be any color, as long as it meets brightness parameter
|
69
|
+
# @foreground_min_brightness = 0.4
|
70
|
+
|
71
|
+
|
72
|
+
@backgroundcolor= randcolor( :shade_of_grey=>@background_grey, :max_bright=>@background_max_brightness)# "0"
|
73
|
+
|
74
|
+
end #initialize
|
75
|
+
|
76
|
+
def randthemename
|
77
|
+
out = " "
|
78
|
+
while out.include? " " do
|
79
|
+
out = @@adjectives[@rand.rand * @@adjectives.size]+"_"+@@nouns[@rand.rand * @@nouns.size]
|
80
|
+
|
81
|
+
end
|
82
|
+
return out
|
83
|
+
end
|
84
|
+
|
85
|
+
def randfilename(existing = "")
|
86
|
+
if existing != "" then
|
87
|
+
out=existing
|
88
|
+
else
|
89
|
+
ar=["a","b","f","h","z","1","5"]
|
90
|
+
ar.shuffle!
|
91
|
+
out =""
|
92
|
+
ar.each { |n|
|
93
|
+
out << n
|
94
|
+
}
|
95
|
+
end
|
96
|
+
return "rmt_"+out+".xml"
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def randcolor(opts={})
|
101
|
+
|
102
|
+
df= { :r=>nil, :g=>nil, :b=>nil, #these are the usual 0..255
|
103
|
+
:bg_rgb => nil,
|
104
|
+
:min_cont => @min_cont, #if a backrgb (background color) is supplied this will be used to create a minimum contrast with it.
|
105
|
+
:max_cont => @max_cont,
|
106
|
+
:max_bright => @max_bright,
|
107
|
+
:min_bright => @min_bright,
|
108
|
+
# :bright_median => 0.5,
|
109
|
+
:shade_of_grey => false} #forces r == g == b
|
110
|
+
df = df.merge opts
|
111
|
+
df[:bg_rgb] = Color::RGB.from_html(df[:bg_rgb]) if df[:bg_rgb]
|
112
|
+
color = brightok = contok = nil;
|
113
|
+
while (!color || !brightok || !contok ) do
|
114
|
+
r = (df[:r] || @rand.rand*256)%256 #mod for robustness
|
115
|
+
g = (df[:g] || @rand.rand*256)%256
|
116
|
+
b = (df[:b] || @rand.rand*256)%256
|
117
|
+
g = b = r if df[:shade_of_grey] == true
|
118
|
+
color = Color::RGB.new(r,g,b)
|
119
|
+
#puts "bg" + @backgroundcolor if df[:bg_rgb]
|
120
|
+
#puts "color "+color.html
|
121
|
+
#puts "contrast "+color.contrast(df[:bg_rgb]).to_s if df[:bg_rgb]
|
122
|
+
contok = df[:bg_rgb] ? (df[:min_cont]..df[:max_cont]).cover?( color.contrast(df[:bg_rgb]) ) : true
|
123
|
+
#puts "contok "+contok.to_s
|
124
|
+
brightok = (df[:min_bright]..df[:max_bright]).cover?( color.to_hsl.brightness )
|
125
|
+
#puts "brightok "+brightok.to_s
|
126
|
+
end
|
127
|
+
|
128
|
+
cn = color.html
|
129
|
+
cn= cn.slice(1,cn.size)
|
130
|
+
return cn
|
131
|
+
end
|
132
|
+
|
133
|
+
def go_fix_geany
|
134
|
+
#goes into the geany directory and kicks some ass. it replaces every single color definition with
|
135
|
+
#something random, of course with a consistent background.
|
136
|
+
|
137
|
+
puts "Backing up all your current color files"
|
138
|
+
@filelist.each do |f|
|
139
|
+
begin
|
140
|
+
# puts f+" -->"+@dir+"_old_"+@extstring+File.basename(f)
|
141
|
+
IO.copy_stream(f,@dir+"_old_"+@extstring+File.basename(f))
|
142
|
+
## rescue
|
143
|
+
# raise "sorry there was a problem backing up the following file: "+f
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
@filelist.each do |f|
|
148
|
+
# puts f.inspect
|
149
|
+
@fin = File.open(f,"r+")
|
150
|
+
@fout = File.open("/tmp/gean"+Time.new().nsec.to_s,"w+")
|
151
|
+
# puts @fin.inspect
|
152
|
+
|
153
|
+
while !@fin.eof? do
|
154
|
+
curpos = @fin.pos
|
155
|
+
line = @fin.readline
|
156
|
+
if line[0] != "#" && line.include?("=") && line.include?("0x") then
|
157
|
+
# go in and root out the color and give it a new one.
|
158
|
+
# puts "here is the line I'm working on -- "
|
159
|
+
# puts line
|
160
|
+
r1 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>@min_cont, :max_cont=>@max_cont).upcase
|
161
|
+
r2 = @backgroundcolor.upcase
|
162
|
+
token = line.split("=")[0]
|
163
|
+
p3 = line.split(";")[2] || "false"
|
164
|
+
p4 = line.split(";")[3] || "false"
|
165
|
+
case File.basename(f)
|
166
|
+
when "filetypes.common"
|
167
|
+
if token == "marker_search" then
|
168
|
+
r9 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>0.35, :max_cont=>0.99).upcase
|
169
|
+
newl = token +"="+"0x"+r1+";0x"+r9+";true;true"
|
170
|
+
elsif token == "caret" then
|
171
|
+
r9 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>0.35, :max_cont=>0.99).upcase
|
172
|
+
newl = token +"="+"0xFFFFFF;0x"+r9+";"+p3+";"+p4
|
173
|
+
elsif token == "current_line" then
|
174
|
+
r9 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>0.03, :max_cont=>0.06).upcase
|
175
|
+
newl = token +"="+"0x"+r1+";0x"+r9+";"+"true"+";"+"true"
|
176
|
+
elsif token == "selection" then
|
177
|
+
r9 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>0.08, :max_cont=>0.16).upcase
|
178
|
+
newl = token +"="+"0x"+r1+";0x"+r9+";"+"false"+";"+"true"
|
179
|
+
elsif token == "brace_good" then
|
180
|
+
rb = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>0.25, :max_cont=>0.9999).upcase
|
181
|
+
rf = randcolor(:bg_rgb=>rb, :min_cont=>0.30, :max_cont=>0.9999).upcase
|
182
|
+
newl = token +"="+"0x"+rf+";0x"+rb+";"+"false"+";"+"true"
|
183
|
+
elsif token == "brace_bad" then
|
184
|
+
rb = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>0.30, :max_cont=>0.9999).upcase
|
185
|
+
rf = randcolor(:bg_rgb=>rb, :min_cont=>0.30, :max_cont=>0.9999).upcase
|
186
|
+
newl = token +"="+"0x"+rf+";0x"+rb+";"+"true"+";"+"true"
|
187
|
+
else
|
188
|
+
newl = token +"="+"0x"+r1+";0x"+r2+";"+p3+";"+p4
|
189
|
+
end
|
190
|
+
|
191
|
+
when "filetypes.xml"
|
192
|
+
if token=="translucency" then
|
193
|
+
else
|
194
|
+
newl = token +"="+"0x"+r1+";0x"+r2+";"+p3+";"+p4
|
195
|
+
end
|
196
|
+
when "filetypes.ruby"
|
197
|
+
if token=="default" then
|
198
|
+
r3 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>@min_cont, :max_cont=>@max_cont).upcase
|
199
|
+
#for whatever reason this needs to go in there in a ruby file : pod=0x388afb;0x131313;false;false
|
200
|
+
newl = token +"="+"0x"+r1+";0x"+r2+";"+p3+";"+p4+"\npod=0x#{r3};0x#{@backgroundcolor};false;false"
|
201
|
+
else
|
202
|
+
newl = token +"="+"0x"+r1+";0x"+r2+";"+p3+";"+p4
|
203
|
+
end
|
204
|
+
else
|
205
|
+
if token.include?("comment") then
|
206
|
+
r1 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>0.18, :max_cont=>0.21).upcase
|
207
|
+
r2 = @backgroundcolor.upcase
|
208
|
+
newl = token +"="+"0x"+r1+";0x"+r2+";"+p3+";"+p4
|
209
|
+
else
|
210
|
+
newl = token +"="+"0x"+r1+";0x"+r2+";"+p3+";"+p4
|
211
|
+
end
|
212
|
+
end
|
213
|
+
@fout.puts(newl)
|
214
|
+
# puts newl
|
215
|
+
#r2= randcolor(:back_rgb=>@backgroundcolor, :min_cont=>@min_cont, :max_cont=>@max_cont)
|
216
|
+
#newl = line.sub(/\=0x*\;/,"=0x"+r1+";")
|
217
|
+
else
|
218
|
+
@fout.puts(line)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
if @fout then
|
222
|
+
File.delete(File.absolute_path @fin)
|
223
|
+
File.rename(File.absolute_path(@fout), @dir+File.basename(f) )
|
224
|
+
else puts "there was a problem writing to the new file so I left the old one in place"
|
225
|
+
end
|
226
|
+
@fout.close
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end #class
|
230
|
+
end #module
|
231
|
+
|
232
|
+
l = RMThemeGen::GeanyFixer.new
|
233
|
+
l.go_fix_geany
|
data/rmthemegen.gemspec
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rmthemegen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- David Heitzman
|
@@ -28,8 +28,8 @@ files:
|
|
28
28
|
- Gemfile
|
29
29
|
- README
|
30
30
|
- Rakefile
|
31
|
-
- lib/rmt_remote_rock.xml
|
32
31
|
- lib/rmthemegen.rb
|
32
|
+
- lib/rmthemegen/geany_fix.rb
|
33
33
|
- lib/rmthemegen/rgb_contrast_methods.rb
|
34
34
|
- lib/rmthemegen/rmthemegen.rb
|
35
35
|
- lib/rmthemegen/token_list.rb
|