Skip to content

Instantly share code, notes, and snippets.

@avalak
Created December 19, 2013 09:12
Show Gist options
  • Save avalak/8036515 to your computer and use it in GitHub Desktop.
Save avalak/8036515 to your computer and use it in GitHub Desktop.
Virtual Terminal color scheme generator for linux kernel and grub2
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Usage:
# 1. Save as `vt-color-scheme.py` in $PATH (/usr/bin for example)
# 2. Make executable `chmod +x vt-color-scheme.py`
# 3. Add `$(vt-color-scheme.py)` to `GRUB_CMDLINE_LINUX` in `/etc/default/grub`
# example `GRUB_CMDLINE_LINUX="$(vt-color-scheme.py)"`
# 4. Create new grub config with `sudo grub-mkconfig -o /boot/grub/grub.cfg`
# 5. Reboot to apply changes
KERNEL_PARAMS = ['vt.default_red', 'vt.default_grn', 'vt.default_blu', ]
# Tango color scheme from Tango theme
# http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines
TANGO_SCHEME = [
'#2e3426', # '#2e3436'
'#cc0000',
'#4e9a06',
'#c4a000',
'#3465a4',
'#75507b',
'#06989a',
'#d3d7cf',
'#555753',
'#ef2929',
'#8ae234',
'#fce94f',
'#729fcf',
'#ad7fa8',
'#34e2e2',
'#eeeeec',
]
def color_scheme_to_rgb_channel_data(color_scheme):
"""
[ '#r1g1b1', '#r2g2b2', ... ] => [ [r1, r2, ...], [g1, g2, ...], [b1, b2, ...], ]
"""
def split_to_rgb(color):
# rgb str -> [red, green, blue]
hex_value = int(color, 16)
return [hex_value >> 16 & 255, hex_value >> 8 & 255, hex_value & 255]
return zip(*[split_to_rgb(color.strip('#')) for color in color_scheme])
def prepare_param(param, channel_data):
return '{param}={values}'.format(param=param, values=','.join(hex(byte) for byte in channel_data))
def main(colors):
print(' '.join(prepare_param(param, channel) for param, channel in \
zip(KERNEL_PARAMS, color_scheme_to_rgb_channel_data(colors))))
if __name__ == '__main__':
main(TANGO_SCHEME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment