From 93592ee43978005a86e0d83486c7b866e2c1b61f Mon Sep 17 00:00:00 2001 From: jaseg Date: Wed, 18 Dec 2013 18:22:00 +0100 Subject: Moving on with the host program --- host/matelight/renderers.py | 143 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 host/matelight/renderers.py (limited to 'host/matelight/renderers.py') diff --git a/host/matelight/renderers.py b/host/matelight/renderers.py new file mode 100644 index 0000000..4508063 --- /dev/null +++ b/host/matelight/renderers.py @@ -0,0 +1,143 @@ +import numpy as np +try: + import re2 as re +except ImportError: + import re +from PIL import Image +from pixelterm import xtermcolors + +default_palette = [ + (0x00, 0x00, 0x00), # 0 normal colors + (0xcd, 0x00, 0x00), # 1 + (0x00, 0xcd, 0x00), # 2 + (0xcd, 0xcd, 0x00), # 3 + (0x00, 0x00, 0xee), # 4 + (0xcd, 0x00, 0xcd), # 5 + (0x00, 0xcd, 0xcd), # 6 + (0xe5, 0xe5, 0xe5), # 7 + (0x7f, 0x7f, 0x7f), # 8 bright colors + (0xff, 0x00, 0x00), # 9 + (0x00, 0xff, 0x00), # 10 + (0xff, 0xff, 0x00), # 11 + (0x5c, 0x5c, 0xff), # 12 + (0xff, 0x00, 0xff), # 13 + (0x00, 0xff, 0xff), # 14 + (0xff, 0xff, 0xff)] # 15 + +class CharGenerator: + def __init__(self, seq=None, lg=None, text=''): + settings = False, False, False, default_palette[8], default_palette[0] + if lg: + settings = lg,bold, lg.blink, lg.underscore, lg.fg, lg.bg + self.bold, self.blink, self.underscore, self.fg, self.bg = settings + self.text = text + self.parse_escape_sequence(seq) + + def parse_escape_sequence(seq): + codes = list(map(int, seq[2:-1].split(';'))) + fg, bg, reverse, i = self.fg, self.bg, False, 0 + while i