mirror of
https://github.com/mrfluffy-dev/oreo-cursor.git
synced 2026-01-17 05:40:34 +00:00
Added ability to change label colour, shadow colour, and shadow opacity
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
# Name = Colour LabelColour ShadowColour ShadowOpacity
|
||||
|
||||
# Default cursors by Varlesh
|
||||
black = #424242
|
||||
blue = #4E81ED
|
||||
@@ -6,18 +8,17 @@ pink = #EE5387
|
||||
purple = #7E57C2
|
||||
red = #F44336
|
||||
teal = #009789
|
||||
white = #C6C6C6
|
||||
white = #C6C6C6 #424242
|
||||
|
||||
# Spark cursors: Custom colours by Sourav
|
||||
spark_dark = #222
|
||||
spark_lite = #eee
|
||||
spark_lite = #fefefe #222222
|
||||
spark_red = #f55
|
||||
spark_blue = #55f
|
||||
spark_pink = #ff50a6
|
||||
spark_orange = #FFA726
|
||||
spark_green = #4E9A06
|
||||
spark_purple = #912BFF
|
||||
spark_lite = #eee
|
||||
spark_yellow = #E7EC00
|
||||
spark_light_pink = #FFA8D3
|
||||
spark_violet = #6435C9
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env ruby
|
||||
# Frozen_String_Literal: true
|
||||
|
||||
REPLACE = "#4E81ED".upcase.freeze
|
||||
|
||||
BASE = File.join(__dir__, 'oreo_base_cursors')
|
||||
CONFIG_FILE = 'colours.conf'
|
||||
OUT_DIR = File.join(File.expand_path('..', __dir__), 'src')
|
||||
@@ -20,24 +20,17 @@ puts "Error with the output directory. Does it exist? Is it writable?" unless Fi
|
||||
|
||||
colours = {}
|
||||
|
||||
if File.readable?(CONFIG_FILE)
|
||||
IO.readlines(CONFIG_FILE).each_with_index do |x, i|
|
||||
next if x.start_with?(?#) || x.strip.empty?
|
||||
name, colour = x.split(?=).then { |y| [y[0].to_s.strip, y[1].to_s.strip] }
|
||||
|
||||
def colour_validation!(colour, i, silent = false)
|
||||
# Colours are uppercased
|
||||
colour.upcase!
|
||||
|
||||
# Make sure colour name is not 0 characters long or too long
|
||||
if name.length.zero? || name.length > 512
|
||||
puts %Q(:: Line #{i.next}: "#{name}" is not a valid name.)
|
||||
next
|
||||
end
|
||||
# Spaces are trimmed
|
||||
colour.strip!
|
||||
|
||||
# Make sure all the colour characters are valid hex
|
||||
if !!colour[/[^a-fA-F0-9#]/] || ![3, 6].include?(colour.start_with?(?#) ? colour[1..-1].length : colour.length)
|
||||
puts %Q(:: Line #{i.next}: "#{colour}" is not a valid colour)
|
||||
next
|
||||
puts %Q(:: Line #{i.next}: "#{colour}" is not a valid colour) unless silent
|
||||
return false
|
||||
end
|
||||
|
||||
# Make sure colour starts with #
|
||||
@@ -45,24 +38,58 @@ if File.readable?(CONFIG_FILE)
|
||||
|
||||
# Make sure colour is 6 characters long
|
||||
colour.replace(?# + colour.chars[1..-1].map { |y| y + y }.join) if colour.length == 4
|
||||
true
|
||||
end
|
||||
|
||||
if File.readable?(CONFIG_FILE)
|
||||
IO.readlines(CONFIG_FILE).each_with_index do |x, i|
|
||||
next if x.start_with?(?#) || x.strip.empty?
|
||||
|
||||
# Label colour
|
||||
label = +'#fff'
|
||||
l = +x.split[3].to_s
|
||||
label = l if colour_validation!(l, i, true)
|
||||
colour_validation!(label, 0)
|
||||
|
||||
# Shadow colour
|
||||
shadow = +'#000'
|
||||
s = +x.split[4].to_s
|
||||
shadow = s if colour_validation!(s, i, true)
|
||||
colour_validation!(shadow, 0)
|
||||
|
||||
# Shadow opacity
|
||||
shadow_opacity = '0.3'
|
||||
so = x.split.map(&:strip).select { |y| y.to_f.to_s == y || y.to_i.to_s == y }[-1]
|
||||
shadow_opacity = +so.strip if so
|
||||
|
||||
# Get cursor name and colour
|
||||
name, colour = x.split(?=).then { |y| [+y[0].to_s.strip, +y[1].to_s.split[0].to_s.strip] }
|
||||
|
||||
# Make sure colour name is not 0 characters long or too long
|
||||
if name.length.zero? || name.length > 512
|
||||
puts %Q(:: Line #{i.next}: "#{name}" is not a valid name.)
|
||||
next
|
||||
end
|
||||
|
||||
next unless colour_validation!(colour, i)
|
||||
|
||||
# Print RGB in the terminal
|
||||
r, g, b = colour[1..2].to_i(16), colour[3..4].to_i(16), colour[5..6].to_i(16)
|
||||
puts "\e[1;38;2;#{r};#{g};#{b}m:: #{name}:\e[0m \e[38;2;#{r};#{g};#{b}m#{colour}\e[0m"
|
||||
lr, lg, lb = label[1..2].to_i(16), label[3..4].to_i(16), label[5..6].to_i(16)
|
||||
sr, sg, sb = shadow[1..2].to_i(16), shadow[3..4].to_i(16), shadow[5..6].to_i(16)
|
||||
|
||||
colours.merge!(name => colour)
|
||||
puts "\e[1;38;2;#{r};#{g};#{b}m:: #{name}:"\
|
||||
"\e[0m \e[38;2;#{r};#{g};#{b}m#{colour}"\
|
||||
"\e[0m | \e[38;2;#{lr};#{lg};#{lb}mLabel"\
|
||||
"\e[0m | \e[38;2;#{sr};#{sg};#{sb}mShadow(#{shadow_opacity})"\
|
||||
"\e[0m |"
|
||||
|
||||
colours.merge!(name => [colour, label, shadow, shadow_opacity])
|
||||
end
|
||||
else
|
||||
puts "Unable to read #{CONFIG_FILE}"
|
||||
puts ":: Unable to read #{CONFIG_FILE}"
|
||||
end
|
||||
|
||||
r = []
|
||||
r << REPLACE[1] if REPLACE.split('').drop(1).uniq.count == 1
|
||||
|
||||
str = REPLACE[1..-1].downcase.+(REPLACE[1..-1].upcase).split('')
|
||||
r.concat(str.combination(6).to_a.map { |x| x.prepend(?#).join } ) unless str.all? { |x| x == x.to_i }
|
||||
r.uniq!
|
||||
|
||||
colours.each do |x, y|
|
||||
dirname = File.join(OUT_DIR, "oreo_#{x}_cursors")
|
||||
Dir.mkdir(dirname) unless Dir.exist?(dirname)
|
||||
@@ -77,10 +104,23 @@ colours.each do |x, y|
|
||||
if File.file?(z)
|
||||
dest_file = File.join(dirname, File.basename(z))
|
||||
data = IO.read(z)
|
||||
r.each { |c| data.gsub!(c, y) }
|
||||
|
||||
# Background Colour
|
||||
data.gsub!(/\{\{ background \}\}/i, y[0])
|
||||
|
||||
# Label Colour
|
||||
data.gsub!(/\{\{ label \}\}/i, y[1])
|
||||
|
||||
# Shadow Colour
|
||||
data.gsub!(/\{\{ shadow \}\}/i, y[2])
|
||||
|
||||
# Shadow Opacity
|
||||
data.gsub!(/\{\{ shadow\s*opacity \}\}/i, y[3])
|
||||
|
||||
IO.write(dest_file, data)
|
||||
end
|
||||
end
|
||||
|
||||
# Write to index file
|
||||
IO.write(File.join(dirname, 'index.theme'), INDEX_THEME.call(x))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user