Class: RMThemeGen::GeanyFixer

Inherits:
RMThemeParent show all
Defined in:
lib/rmthemegen/geany_fix.rb

Instance Attribute Summary collapse

Attributes inherited from RMThemeParent

#themename

Instance Method Summary collapse

Methods inherited from RMThemeParent

#before_create, #clean_colorsets, #clear_colorsets, #handle_rand_seed, #reset_colorsets

Constructor Details

#initializeGeanyFixer

Returns a new instance of GeanyFixer.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rmthemegen/geany_fix.rb', line 29

def initialize
#    @rand = Random.new
@iterations = 0
@iterations = ARGV[0].to_s.to_i

puts "geany_fix - puts a new (random) color theme into your geany directory"
puts "  copyright (c) David Heitzman 2011 "
puts "  Note: if you want to put back your old Geany colors, go to ~/.config/geany/filedefs/ and"
puts "  copy the corresponding _old_xxx file back onto filetypes.xyz, eg. filetypes.html, etc. "
puts "  Restart geany to see new colors  "
  
begin
@dir = (File.expand_path "~/.config/geany/filedefs/")
@filelist = Dir.glob(@dir+"/filetypes.*")
#  puts @dir+"filetypes.*"
#    puts @filelist.inspect
t =Time.now
@extstring = t.year.to_s+t.month.to_s+t.day.to_s+t.sec.to_s
#    rescue
 #     raise "Sorry. There was trouble accessing the files in " + @dir
end


  @italic_candidates = ["STRING", "SYMBOL", "REQUIRE"]

  @bold_candidates = ["KEYWORD","RUBY_SPECIFIC_CALL", "CONSTANT", "COMMA", "PAREN","RUBY_ATTR_ACCESSOR_CALL", "RUBY_ATTR_READER_CALL" ,"RUBY_ATTR_WRITER_CALL", "IDENTIFIER"]
# with code inspections we don't color the text, we just put a line or something under it .
  @code_inspections = ["ERROR","WARNING_ATTRIBUTES","DEPRECATED", "TYPO","WARNING_ATTRIBUTES", "BAD_CHARACTER",
  "CUSTOM_INVALID_STRING_ESCAPE_ATTRIBUTES","ERRORS_ATTRIBUTES", "MATCHED_BRACE_ATTRIBUTES"]
  @cross_out = ["DEPRECATED_ATTRIBUTES" ]

  @unders = %w(-1 0 1 2 5  )
  @underline_candidates = ["STRING"]
  @italic_chance = 0.2
  @bold_chance = 0.4
  @underline_chance = 0.3
  @bright_median = 0.85
    @min_bright = @bright_median * 0.65
    @max_bright =  [@bright_median * 1.35,1.0].max

    @min_bright = 0.0
    @max_bright =  1.0

  #	if we avoid any notion of "brightness", which is an absolute quality, then we
  # can make our background any color we want !

  #tighter contrast spec
  @cont_median = 0.85
    @min_cont = @cont_median * 0.65
    @max_cont =  [@cont_median * 1.35,1.0].max

  #broad contrast spec
  @min_cont = 0.32
  @max_cont = 1.0

  @schemeversion = 1
  @background_max_brightness = 0.16
  @background_grey = true #if false, allows background to be any color, as long as it meets brightness parameter
#  @foreground_min_brightness = 0.4


  @backgroundcolor= randcolor( :shade_of_grey=>@background_grey, :max_bright=>@background_max_brightness)# "0"

end

Instance Attribute Details

#xmloutObject (readonly)

a huge structure of xml that can be given to XmlSimple.xml_out() to create that actual color theme file



27
28
29
# File 'lib/rmthemegen/geany_fix.rb', line 27

def xmlout
  @xmlout
end

Instance Method Details

#go_fix_geanyObject



151
152
153
154
155
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/rmthemegen/geany_fix.rb', line 151

def go_fix_geany
  #goes into the geany directory and kicks some ass. it replaces every single color definition with
  #something random, of course with a consistent background. 

  @filelist.each do |f|
    begin
#          puts f+" -->"+@dir+"_old_"+@extstring+File.basename(f)
#          IO.copy_stream(f,@dir+"_old_"+@extstring+File.basename(f))
    copystring="cp #{f} #{@dir+"/_old_"+@extstring+File.basename(f)}"
#        puts(copystring) 
    `#{copystring}`
    rescue
      backup_problem = true
      raise "sorry there was a problem backing up the following file: "+f
    end
  end

  ##########################################
  # copy in our new files from token_list.rb
  ##########################################
  @@geany_file_contents.each_key do |key|
  filename=@dir+'/filetypes.'+key.to_s
#      puts filename
  @fout1 = File.open(filename,"w+")
    @@geany_file_contents[key].each do |c|
      @fout1.puts c
    end
  @fout1.close
  end 

  @filelist = Dir.glob(@dir+"/filetypes.*")
  @filelist.each do |f|
  #      puts f.inspect
    @fin = File.open(f,"r+")
    @fout = File.open(@dir+"/tmp_out_"+rand.to_s,"w+")
  #      puts @fin.inspect

    while !@fin.eof? do
      curpos = @fin.pos
      line  = @fin.readline
      if line[0] != "#" && line.include?("=") && line.include?("0x") then
       # go in and root out the color and give it a new one.
#            puts "here is the line I'm working on -- "
#            puts line
        r1 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>@min_cont, :max_cont=>@max_cont).upcase
        r2 = @backgroundcolor.upcase
        token = line.split("=")[0]
        p3 = line.split(";")[2] || "false"
        p4 = line.split(";")[3] || "false"
        case File.basename(f)
          when  "filetypes.common"
            if    token == "marker_search" then
              r9 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>0.35, :max_cont=>@max_cont).upcase
              newl = token +"="+"0x"+r1+";0x"+r9+";true;true"
            elsif token == "caret"  then
              r9 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>0.35, :max_cont=>@max_cont).upcase
              newl = token +"="+"0xFFFFFF;0x"+r9+";"+p3+";"+p4
            elsif token == "current_line" then
              r9 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>@min_cont*0.15, :max_cont=>@min_cont*0.3).upcase
              newl = token +"="+"0x"+r1+";0x"+r9+";"+"true"+";"+"false"
            elsif token == "selection" then
              r9 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>@min_cont*0.25, :max_cont=>@min_cont*0.5).upcase
              newl = token +"="+"0x"+r1+";0x"+r9+";"+"false"+";"+"true"
            elsif token == "brace_good" then
              rb = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>0.25, :max_cont=>@max_cont).upcase
              rf = randcolor(:bg_rgb=>rb, :min_cont=>0.30, :max_cont=>1.0).upcase
              newl = token +"="+"0x"+rf+";0x"+rb+";"+"true"+";"+"false"
            elsif token == "brace_bad" then
              rb = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>@min_cont, :max_cont=>1.0).upcase
              rf = randcolor(:bg_rgb=>rb, :min_cont=>0.30, :max_cont=>1.0).upcase
              newl = token +"="+"0x"+rf+";0x"+rb+";"+"true"+";"+"false"
            elsif token.include?("type") then 
              newl ="type=0xffffff;;true;false"
            elsif token.include?("indent_guide") then
              newl= "indent_guide=0xc0c0c0;;false;false"
            else
              newl = token +"="+"0x"+r1+";0x"+r2+";"+p3+";"+p4
            end

          when "filetypes.xml"
              newl = token +"="+"0x"+r1+";0x"+r2+";"+p3+";"+p4

          when "filetypes.ruby"
            if token=="default" then
              r3 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>@min_cont, :max_cont=>@max_cont).upcase
              #for whatever reason this needs to go in there in a ruby file : pod=0x388afb;0x131313;false;false
              newl = token +"="+"0x"+r1+";0x"+r2+";"+p3+";"+p4+"\npod=0x#{r3};0x#{@backgroundcolor};false;false"
            elsif token.include?("comment") then
              r1 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>@min_cont*0.87, :max_cont=>@min_cont*0.95).upcase
              r2 = @backgroundcolor.upcase
              newl = token +"="+"0x"+r1+";0x"+r2+";"+p3+";"+p4
            else
              newl = token +"="+"0x"+r1+";0x"+r2+";"+p3+";"+p4
            end
          else  ############ DEFAULT  ############ 
            if token.include?("comment") then
              r1 = randcolor(:bg_rgb=>@backgroundcolor, :min_cont=>@min_cont*0.77, :max_cont=>@min_cont*0.95).upcase
              r2 = @backgroundcolor.upcase
              newl = token +"="+"0x"+r1+";0x"+r2+";"+p3+";"+p4
            else
              newl = token +"="+"0x"+r1+";0x"+r2+";"+p3+";"+p4
            end
        end
        @fout.puts(newl)
      else
        @fout.puts(line)
      end
    end
    if @fout then
#        puts "wanting to delete "[email protected]_s
#        puts "wanting to copy this file onto it:"[email protected]_s
      File.delete(@fin.path.to_s)
      File.rename(@fout.path.to_s, @fin.path.to_s )
    else puts "there was a problem writing to the new file #{@fout.path.to_s} so I left the old one in place"
    end
    @fout.close
  end
end

#randcolor(opts = {}) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/rmthemegen/geany_fix.rb', line 118

def randcolor(opts={})

  df= { :r=>nil, :g=>nil, :b=>nil, #these are the usual 0..255
        :bg_rgb => nil,
        :min_cont  => @min_cont, #if a backrgb (background color)  is supplied this will be used to create a minimum contrast with it.
        :max_cont => @max_cont,
        :max_bright => @max_bright,
        :min_bright => @min_bright,
      #  :bright_median => 0.5,
        :shade_of_grey => false} #forces r == g == b
  df = df.merge opts
  df[:bg_rgb] = Color::RGB.from_html(df[:bg_rgb]) if df[:bg_rgb]
  color = brightok = contok = nil;
  while (!color || !brightok || !contok ) do
    r = (df[:r] || rand*256)%256 #mod for robustness
    g = (df[:g] || rand*256)%256
    b = (df[:b] || rand*256)%256
    g = b = r if df[:shade_of_grey] == true
    color = Color::RGB.new(r,g,b)
  #puts "bg" + @backgroundcolor if df[:bg_rgb]
  #puts "color "+color.html
  #puts "contrast "+color.contrast(df[:bg_rgb]).to_s if df[:bg_rgb]
    contok = df[:bg_rgb] ? (df[:min_cont]..df[:max_cont]).include?( color.contrast(df[:bg_rgb]) ) : true
  #puts "contok "+contok.to_s
    brightok = (df[:min_bright]..df[:max_bright]).include?( color.to_hsl.brightness )
  #puts "brightok "+brightok.to_s
  end

  cn = color.html
  cn= cn.slice(1,cn.size)
  return cn
end

#randfilename(existing = "") ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/rmthemegen/geany_fix.rb', line 103

def randfilename(existing = "")
 if existing != "" then
  out=existing
 else
  ar=["a","b","f","h","z","1","5"]
  ar.shuffle!
  out =""
  ar.each { |n|
    out << n
  }
 end
 return "rmt_"+out+".xml"
end

#randthemenameObject

initialize



94
95
96
97
98
99
100
101
# File 'lib/rmthemegen/geany_fix.rb', line 94

def randthemename
  out = " "
  while out.include? " "   do
   out = @@adjectives[rand * @@adjectives.size]+"_"+@@nouns[rand * @@nouns.size]
    
  end
  return out
end