From 3538134a50fac0ba74bb20cf39056312e02ec339 Mon Sep 17 00:00:00 2001 From: thematdev Date: Tue, 3 May 2022 16:44:47 +0300 Subject: [PATCH] First commit --- README.md | 6 ++++- scheme_migration.py | 54 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 scheme_migration.py diff --git a/README.md b/README.md index 5cd2f12..f314f81 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # konsole-scheme-migration -Migrate Konsole colorscheme to Kitty format \ No newline at end of file +Migrate Konsole colorscheme to Kitty format + +# Usage +Run script and enter your filescheme file(must end in `.colorscheme`) +Imported theme will be placed in `scheme.conf` diff --git a/scheme_migration.py b/scheme_migration.py new file mode 100644 index 0000000..3168e35 --- /dev/null +++ b/scheme_migration.py @@ -0,0 +1,54 @@ +import os +import itertools + + +def get_valid_filename(question, extension = ''): + filename = input(question) + filename = os.path.expanduser(filename) + if not (filename.endswith(extension) and os.path.exists(filename)): + print('Please, enter valid filename') + return get_valid_filename(question, extension) + return filename + + +def parse_color_from_integers(a, b, c): + return f'#{str(hex(a))[2:]}{str(hex(b))[2:]}{str(hex(c))[2:]}' + + +def parse_color_from_section(cell): + # Parsing string format Color=R,G,B + ints = cell.split(',') + ints[0] = ints[0][6:] + return parse_color_from_integers(*map(int, ints)) + + +def main(): + f = open(get_valid_filename('Enter path to Konsole filescheme: ', '.colorscheme'), 'r') + + data = [line.strip() for line in f.readlines()] + sections = [list(y) for x, y in itertools.groupby(data, lambda z: z == '') if not x] + + out = open('scheme.conf', 'w') + for section in sections: + desc = section[0][1:-1] + out.write(f'# importing {desc}\n') + + if desc == 'Background': + out.write(f'background {parse_color_from_section(section[1])}\n') + elif desc == 'Foreground': + out.write(f'foreground {parse_color_from_section(section[1])}\n') + elif desc.startswith('Color'): + mod = 0 + if desc.endswith('Intense'): + mod = 1 + if desc.endswith('Faint'): + mod = 2 + color = int(desc[5]) + out.write(f'color{color + 8 * mod} {parse_color_from_section(section[1])}\n') + + out.close() + f.close() + + +if __name__ == '__main__': + main()