mirror of
https://github.com/mrfluffy-dev/oreo-cursor.git
synced 2026-01-17 05:40:34 +00:00
Merge pull request #12 from Souravgoswami/script-development
Updated convert.rb ; New Art ; Encoding to UTF-8 ; Other changes
This commit is contained in:
@@ -5,9 +5,15 @@
|
||||
|
||||
# Written by Sourav Goswami <souravgoswami@protonmail.com>
|
||||
|
||||
## Future Ruby release may have frozen string literals.
|
||||
# It's good to keep it false so that our program doesn't crash in the future.
|
||||
|
||||
# Version should be floating point number
|
||||
VERSION = "0.1".freeze
|
||||
|
||||
# Make sure sync is enabled
|
||||
STDOUT.sync = STDERR.sync = true
|
||||
|
||||
# Check Ruby version
|
||||
abort "Error! Atleast Ruby 2.4 is needed! You are running #{RUBY_VERSION} (#{RUBY_PLATFORM})" if RUBY_VERSION.split(?.).first(2).join.to_i < 24
|
||||
|
||||
@@ -38,7 +44,7 @@ puts "Error with the output directory. Does it exist? Is it writable?" unless Fi
|
||||
class String
|
||||
def colourize
|
||||
colours, line_length, temp = [], -1, ''
|
||||
sample_colour, rev, repeat = rand(7), rand < 0.5, rand < 0.5
|
||||
sample_colour, rev = rand(7), rand < 0.5
|
||||
|
||||
each_line do |c|
|
||||
n, i = c.length, -1
|
||||
@@ -61,6 +67,8 @@ class String
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
colours.reverse! if rev
|
||||
end
|
||||
|
||||
i = -1
|
||||
@@ -76,13 +84,25 @@ end
|
||||
# Show help
|
||||
if ARGV.any? { |x| x[/\A\-(\-help|h)\Z/] }
|
||||
<<~EOF.colourize
|
||||
This program is used to generate oreo cursor colours.
|
||||
This program is used to generate oreo cursors.
|
||||
It can generate cursor of your defined colours.
|
||||
|
||||
Arguments:
|
||||
--help | -h\t\tShow this help
|
||||
--config= | -c=\t\tSpecify the configration file
|
||||
\t\t\t[defaults to colours.conf]
|
||||
--version | -v\t\tShow version
|
||||
\u2B23 Arguments:
|
||||
1. --help | -h\t\tShow this help
|
||||
2. --config= | -c=\t\tSpecify the configration file
|
||||
\t\t\t\t[defaults to colours.conf]
|
||||
3. --version | -v\t\tShow version
|
||||
|
||||
\u2B23 Config File:
|
||||
You need a config file. A sample file will look like this:
|
||||
|
||||
# Name = Colour LabelColour ShadowColour ShadowOpacity
|
||||
black = #424242 #fff #111 #0.4
|
||||
spark_violet = #6435C9
|
||||
|
||||
# This is a comment.
|
||||
# By default, LabelColour is #ffffff, ShadowColour is #000
|
||||
# And ShadowOpacity is 0.3
|
||||
EOF
|
||||
|
||||
exit
|
||||
@@ -103,29 +123,35 @@ CONFIG_FILE = if cf && File.readable?(cf)
|
||||
elsif cf && !File.readable?(cf)
|
||||
puts ":: #{cf} is not readable, using colours.conf"
|
||||
sleep 1
|
||||
'colours.conf'
|
||||
File.join(__dir__, 'colours.conf')
|
||||
else
|
||||
'colours.conf'
|
||||
File.join(__dir__, 'colours.conf')
|
||||
end
|
||||
|
||||
require 'io/console'
|
||||
tw = STDOUT.winsize[1]
|
||||
<<~EOF.lines.map { |x| '//' + ?\s * (tw / 2.0 - x.length / 2 - 2).clamp(0, Float::INFINITY) + x.chomp + ?\s * (tw / 2 - x.length / 2.0 - 2).to_i.clamp(0, Float::INFINITY) + '//' + ?\n}.join.colourize
|
||||
#{?- * (tw - 20)}
|
||||
.d88b. d8888b. d88888b .d88b.
|
||||
.8P Y8. 88 `8D 88' .8P Y8.
|
||||
88 88 88oobY' 88ooooo 88 88
|
||||
88 88 88`8b 88~~~~~ 88 88
|
||||
`8b d8' 88 `88. 88. `8b d8'
|
||||
`Y88P' 88 YD Y88888P `Y88P'
|
||||
|
||||
.o88b. db db d8888b. .d8888. .d88b. d8888b. .d8888.
|
||||
d8P Y8 88 88 88 `8D 88' YP .8P Y8. 88 `8D 88' YP
|
||||
8P 88 88 88oobY' `8bo. 88 88 88oobY' `8bo.
|
||||
8b 88 88 88`8b `Y8b. 88 88 88`8b `Y8b.
|
||||
Y8b d8 88b d88 88 `88. db 8D `8b d8' 88 `88. db 8D
|
||||
`Y88P' ~Y8888P' 88 YD `8888Y' Y88P' 88 YD `8888Y'
|
||||
#{?- * (tw - 20)}
|
||||
# Art generated from https://fsymbols.com/generators/carty/
|
||||
# Used utf-8, editors messes up with the font and makes development harder.
|
||||
# To generate utf-8 chars to utf-8 codes using String#dump
|
||||
<<~EOF.lines.map { |x| '//' + ?\s * (tw / 2.0 - x.length / 2 - 2).clamp(0, Float::INFINITY) + x.chomp + ?\s * (tw / 2 - x.length / 2.0 - 2).to_i.clamp(0, Float::INFINITY) + '//' + ?\n}.join.colourize
|
||||
#{?- * (tw / 1.25)}
|
||||
|
||||
\u2591\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2588\u2588\u2588\u2588\u2588\u2557\u2591
|
||||
\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557
|
||||
\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2591\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551
|
||||
\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u255D\u2591\u2591\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551
|
||||
\u255A\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u255A\u2588\u2588\u2588\u2588\u2588\u2554\u255D
|
||||
\u2591\u255A\u2550\u2550\u2550\u2550\u255D\u2591\u255A\u2550\u255D\u2591\u2591\u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u2591\u255A\u2550\u2550\u2550\u2550\u255D\u2591
|
||||
|
||||
\u2591\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2588\u2588\u2557\u2591\u2591\u2591\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2557
|
||||
\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2591\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D
|
||||
\u2588\u2588\u2551\u2591\u2591\u255A\u2550\u255D\u2588\u2588\u2551\u2591\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u255A\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u255A\u2588\u2588\u2588\u2588\u2588\u2557\u2591
|
||||
\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2557\u2588\u2588\u2551\u2591\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2591\u255A\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2591\u255A\u2550\u2550\u2550\u2588\u2588\u2557
|
||||
\u255A\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u255A\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D
|
||||
\u2591\u255A\u2550\u2550\u2550\u2550\u255D\u2591\u2591\u255A\u2550\u2550\u2550\u2550\u2550\u255D\u2591\u255A\u2550\u255D\u2591\u2591\u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u255D\u2591\u2591\u255A\u2550\u2550\u2550\u2550\u255D\u2591\u255A\u2550\u255D\u2591\u2591\u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u255D\u2591
|
||||
|
||||
#{?- * (tw / 1.25)}
|
||||
EOF
|
||||
|
||||
colours = {}
|
||||
@@ -198,57 +224,61 @@ if File.readable?(CONFIG_FILE)
|
||||
colours.merge!(name => [colour, label, shadow, shadow_opacity])
|
||||
end
|
||||
else
|
||||
puts ":: Unable to read #{CONFIG_FILE}"
|
||||
abort ":: Unable to read #{CONFIG_FILE}"
|
||||
end
|
||||
|
||||
colours.each do |x, y|
|
||||
# Make the directory name is the colour name mentioned in the config file
|
||||
dirname = File.join(OUT_DIR, "oreo_#{x}_cursors")
|
||||
begin
|
||||
colours.each do |x, y|
|
||||
# Make the directory name is the colour name mentioned in the config file
|
||||
dirname = File.join(OUT_DIR, "oreo_#{x}_cursors")
|
||||
|
||||
# Make the directory mentioned in the config file
|
||||
# We will store svg files here, mapped to colours
|
||||
Dir.mkdir(dirname) unless Dir.exist?(dirname)
|
||||
# Make the directory mentioned in the config file
|
||||
# We will store svg files here, mapped to colours
|
||||
Dir.mkdir(dirname) unless Dir.exist?(dirname)
|
||||
|
||||
# Delete files from dirname if it's not empty. The reason is to get rid of excess files.
|
||||
Dir.children(dirname).each do |x|
|
||||
file = File.join(dirname, x)
|
||||
File.delete(file) if File.file?(file)
|
||||
end
|
||||
|
||||
# Iterate over each base files and add colours to them,
|
||||
# and write them to the directories fetched from configuration file
|
||||
Dir.glob("#{BASE}/*svg.oreo").each do |z|
|
||||
if File.file?(z)
|
||||
# Destination file has the name.svg converted from name.svg.oreo
|
||||
dest_file = File.join(dirname, File.basename(z).split(?..freeze).tap(&:pop).join(?..freeze))
|
||||
|
||||
# Read the base file
|
||||
data = IO.read(z)
|
||||
|
||||
# Change Background Colour
|
||||
data.gsub!(/\{\{ background \}\}/i, y[0])
|
||||
|
||||
# Change Label Colour
|
||||
data.gsub!(/\{\{ label \}\}/i, y[1])
|
||||
|
||||
# Change Shadow Colour
|
||||
data.gsub!(/\{\{ shadow \}\}/i, y[2])
|
||||
|
||||
# Change Shadow Opacity
|
||||
data.gsub!(/\{\{ shadow\s*opacity \}\}/i, y[3])
|
||||
|
||||
# Write converted data to destination file
|
||||
IO.write(dest_file, data)
|
||||
# Delete files from dirname if it's not empty. The reason is to get rid of excess files.
|
||||
Dir.children(dirname).each do |x|
|
||||
file = File.join(dirname, x)
|
||||
File.delete(file) if File.file?(file)
|
||||
end
|
||||
|
||||
# Iterate over each base files and add colours to them,
|
||||
# and write them to the directories fetched from configuration file
|
||||
Dir.glob("#{BASE}/*svg.oreo").each do |z|
|
||||
if File.file?(z)
|
||||
# Destination file has the name.svg converted from name.svg.oreo
|
||||
dest_file = File.join(dirname, File.basename(z).split(?..freeze).tap(&:pop).join(?..freeze))
|
||||
|
||||
# Read the base file
|
||||
data = IO.read(z)
|
||||
|
||||
# Change Background Colour
|
||||
data.gsub!(/\{\{ background \}\}/i, y[0])
|
||||
|
||||
# Change Label Colour
|
||||
data.gsub!(/\{\{ label \}\}/i, y[1])
|
||||
|
||||
# Change Shadow Colour
|
||||
data.gsub!(/\{\{ shadow \}\}/i, y[2])
|
||||
|
||||
# Change Shadow Opacity
|
||||
data.gsub!(/\{\{ shadow\s*opacity \}\}/i, y[3])
|
||||
|
||||
# Write converted data to destination file
|
||||
IO.write(dest_file, data, encoding: 'UTF-8'.freeze)
|
||||
end
|
||||
end
|
||||
|
||||
# Write to index file
|
||||
IO.write(File.join(dirname, 'index.theme'.freeze), INDEX_THEME.call(x), encoding: 'UTF-8'.freeze)
|
||||
|
||||
c = y[0]
|
||||
r, g, b = c[1..2].to_i(16), c[3..4].to_i(16), c[5..6].to_i(16)
|
||||
|
||||
puts ":: Created \e[38;2;#{r};#{g};#{b}m#{dirname}/\e[0m"
|
||||
end
|
||||
|
||||
# Write to index file
|
||||
IO.write(File.join(dirname, 'index.theme'.freeze), INDEX_THEME.call(x))
|
||||
|
||||
c = y[0]
|
||||
r, g, b = c[1..2].to_i(16), c[3..4].to_i(16), c[5..6].to_i(16)
|
||||
|
||||
puts ":: Created \e[38;2;#{r};#{g};#{b}m#{dirname}/\e[0m"
|
||||
rescue Exception
|
||||
puts "\n\nUh oh! Program crashed!\n\t#{$!.backtrace.join(?\n)}\n\t#{$!}".colourize
|
||||
else
|
||||
puts ":: Successfully created src/ files"
|
||||
end
|
||||
|
||||
puts ":: Successfully created src/ files"
|
||||
|
||||
Reference in New Issue
Block a user