Last active
August 19, 2023 15:34
-
-
Save ZaWertun/7c8d14c248cfee5d1b6cac0304249278 to your computer and use it in GitHub Desktop.
Script to convert Konsole color schema to Alacritty color schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
def parse_ini(lines) | |
data = {} | |
section = nil | |
lines.each do |line| | |
if line =~ /\[(.+)\]/ | |
section = $1 | |
elsif section && line =~ /(.+)=(.*)/ | |
data[section] ||= {} | |
data[section][$1] = $2 | |
end | |
end | |
data | |
end | |
def dec2hex(str) | |
hex = str.split(',').map{|s| s.to_i.to_s(16).rjust(2, '0')} | |
'#' + hex.join('') | |
end | |
MAPPING = { | |
'Color0' => 'black', | |
'Color1' => 'red', | |
'Color2' => 'green', | |
'Color3' => 'yellow', | |
'Color4' => 'blue', | |
'Color5' => 'magenta', | |
'Color6' => 'cyan', | |
'Color7' => 'white', | |
'Background' => 'background', | |
'Foreground' => 'foreground' | |
}.freeze | |
def konsole2alacritty(data) | |
colors = {'primary' => {}, 'normal' => {}, 'bright' => {}, 'dim' => {}} | |
colors['primary']['background'] = dec2hex(data['Background']['Color']) | |
colors['primary']['dim_background'] = dec2hex(data['BackgroundFaint']['Color']) | |
colors['primary']['bright_background'] = dec2hex(data['BackgroundIntense']['Color']) | |
MAPPING.each do |key, color| | |
if key =~ /^Color/ | |
colors['normal'][color] = dec2hex data[key]['Color'] | |
colors['dim'][color] = dec2hex data["#{key}Faint"]['Color'] | |
colors['bright'][color] = dec2hex data["#{key}Intense"]['Color'] | |
else | |
colors['primary'][color] = dec2hex data[key]['Color'] | |
colors['primary']["dim_#{color}"] = dec2hex data["#{key}Faint"]['Color'] | |
colors['primary']["bright_#{color}"] = dec2hex data["#{key}Intense"]['Color'] | |
end | |
end | |
{'colors' => colors} | |
end | |
lines = File.readlines(ARGV[0]).map(&:chomp) | |
konsole = parse_ini(lines) | |
alacritty = konsole2alacritty(konsole) | |
puts "# Converted from konsole color schema \"#{ARGV[0]}\"" | |
puts YAML.dump(alacritty).gsub("---\n", '') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment