Last active
July 22, 2018 11:44
-
-
Save aurieh/65af0016aa63a399a46b94b3f57df155 to your computer and use it in GitHub Desktop.
little tool to help translate termite config to kitty.conf
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
import sys | |
import os | |
from configparser import ConfigParser | |
from io import StringIO | |
def writeline(self, line): | |
return self.write(line + os.linesep) | |
def to_yn(b): | |
return 'yes' if b else 'no' | |
termite = ConfigParser() | |
termite.read(sys.argv[1]) | |
termite = dict(termite.items()) | |
kitty = StringIO() | |
setattr(kitty, 'writeline', writeline.__get__(kitty, kitty.__class__)) | |
options = termite.get('options', {}) | |
colors = termite.get('colors', {}) | |
# Fonts | |
font = options.get('font', 'monospace 9') | |
font_parts = font.split(' ') | |
if len(font_parts) > 1: | |
try: | |
font_family = font_parts[:-1] | |
font_size = int(font_parts[-1]) | |
except ValueError: | |
font_family = font_parts | |
font_size = 0 | |
font_family = ' '.join(font_family) | |
else: | |
font_family = font_parts[0] | |
font_size = 0 | |
kitty.writeline(f'font_family {font_family}') | |
kitty.writeline(f'font_size {font_size}') | |
# Cursor | |
cursor = colors.get('cursor', '#cccccc') | |
cursor_shape = colors.get('cursor_shape', 'block') | |
if cursor_shape == 'ibeam': | |
cursor_shape = 'beam' | |
cursor_blink = options.get('cursor_blink', 'on') | |
if cursor_blink == 'system' or cursor_blink == 'on': | |
cursor_blink = 0.5 | |
else: | |
cursor_blink = 0.0 | |
kitty.writeline(f'cursor {cursor}') | |
kitty.writeline(f'cursor_shape {cursor_shape}') | |
kitty.writeline(f'cursor_blink_interval {cursor_blink}') | |
# Scrollback | |
scrollback_lines = options.get('scrollback_lines', '2000') | |
kitty.writeline(f'scrollback_lines {scrollback_lines}') | |
# Mouse | |
mouse_hide_wait = options.get('mouse_autohide', False) | |
if mouse_hide_wait: | |
mouse_hide_wait = 3.0 | |
else: | |
mouse_hide_wait = 0.0 | |
kitty.writeline(f'mouse_hide_wait {mouse_hide_wait}') | |
# Terminal bell | |
enable_audio_bell = to_yn(options.get('audible_bell', False)) | |
window_alert_on_bell = to_yn(options.get('urgent_on_bell', True)) | |
kitty.writeline(f'enable_audio_bell {enable_audio_bell}') | |
kitty.writeline(f'window_alert_on_bell {window_alert_on_bell}') | |
# Color scheme | |
foreground = colors.get('foreground', '#dddddd') | |
background = colors.get('background', '#000000') | |
# TODO: opacity | |
for x in range(0, 256): | |
k = 'color' + str(x) | |
color = colors.get(k) | |
if color: | |
kitty.writeline(f'{k} {color}') | |
kitty.writeline(f'foreground {foreground}') | |
kitty.writeline(f'background {background}') | |
print(kitty.getvalue()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment