From 1de1f6717b68f934019baf2fa52c76e0f94f2e38 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Sun, 15 Mar 2020 21:21:19 +0100 Subject: Tremulous color support (24-bit modes only) --- rcon.py | 28 +++++++-- source.py | 150 +++++++++++++++++++++++++++++++++++++++++++++++ testing/log_simulator.py | 11 +++- trem_colors.py | 96 ++++++++++++++++++++++++++++++ 4 files changed, 277 insertions(+), 8 deletions(-) create mode 100644 source.py create mode 100644 trem_colors.py diff --git a/rcon.py b/rcon.py index 0185f12..d744792 100644 --- a/rcon.py +++ b/rcon.py @@ -1,4 +1,5 @@ import urwid, os, subprocess, fcntl, glob +from trem_colors import trem_to_markup, trem_palette try: from local_config import * @@ -34,9 +35,14 @@ class JournalViewer: lc, "" if lc == 1 else "s", "on" if self.following else "off")) - def write(self, text): + def write(self, text, color_override=None): for line in str(text).split("\n"): - self.list_walker.append(urwid.Text(line)) + if color_override is None: + markup = trem_to_markup(line) + else: + markup = (color_override, line) + self.list_walker.append(urwid.Text(markup)) + self.update() def proc_open(self, argv): @@ -147,7 +153,8 @@ class Console: def select_server(self, server): self.server = server - self.viewer.write("*** Now viewing logs from %s ***" % server) + self.viewer.write("Now viewing logs from %s" % server, + color_override="system") self.edit_pre.button.set_label(server) argv = [arg % server if "%s" in arg else arg for arg in LOG_COMMAND] @@ -161,15 +168,26 @@ class Console: palette = [ + # UI elements ("button", "white", "dark red"), ("button focus", "white, bold", "light red"), ("status", "black", "white"), ("edit focus", "white", "black"), ("edit", "white", "dark gray"), ("popup", "white", "dark red"), -] -loop = urwid.MainLoop(None, palette, pop_ups=True) + # Log text + ("system", "white, bold", "dark gray"), + + ("WTF", "black", "black", "black", "#123456", "black"), +] \ + + trem_palette + +screen = urwid.raw_display.Screen() +screen.set_terminal_properties(colors=2**24) +screen.register_palette(palette) + +loop = urwid.MainLoop(None, screen=screen, pop_ups=True) console = Console(loop) loop.widget = console.root loop.unhandled_input = console.unhandled_input diff --git a/source.py b/source.py new file mode 100644 index 0000000..6d0c6f1 --- /dev/null +++ b/source.py @@ -0,0 +1,150 @@ +# a quick crap script for working with Tremulous's source code +import re + +color_vectors = """vec4_t colorBlack = {0.000f, 0.000f, 0.000f, 1.000f}; +vec4_t colorRed = {1.000f, 0.000f, 0.000f, 1.000f}; +vec4_t colorGreen = {0.000f, 1.000f, 0.000f, 1.000f}; +vec4_t colorBlue = {0.000f, 0.000f, 1.000f, 1.000f}; +vec4_t colorYellow = {1.000f, 1.000f, 0.000f, 1.000f}; +vec4_t colorMagenta = {1.000f, 0.000f, 1.000f, 1.000f}; +vec4_t colorCyan = {0.000f, 1.000f, 1.000f, 1.000f}; +vec4_t colorWhite = {1.000f, 1.000f, 1.000f, 1.000f}; +vec4_t colorGray = {0.502f, 0.502f, 0.502f, 1.000f}; +vec4_t colorOrange = {1.000f, 0.686f, 0.000f, 1.000f}; +vec4_t colorRoseBud = {0.996f, 0.671f, 0.604f, 1.000f}; +vec4_t colorPaleGreen = {0.596f, 0.984f, 0.596f, 1.000f}; +vec4_t colorPaleGolden = {0.933f, 0.910f, 0.667f, 1.000f}; +vec4_t colorColumbiaBlue = {0.608f, 0.867f, 1.000f, 1.000f}; +vec4_t colorPaleTurquoise = {0.686f, 0.933f, 0.933f, 1.000f}; +vec4_t colorPaleVioletRed = {0.859f, 0.439f, 0.576f, 1.000f}; +vec4_t colorPalacePaleWhite = {0.910f, 0.898f, 0.863f, 1.000f}; +vec4_t colorOlive = {0.231f, 0.235f, 0.212f, 1.000f}; +vec4_t colorTomato = {1.000f, 0.388f, 0.278f, 1.000f}; +vec4_t colorLime = {0.749f, 1.000f, 0.000f, 1.000f}; +vec4_t colorLemon = {1.000f, 0.969f, 0.000f, 1.000f}; +vec4_t colorBlueBerry = {0.310f, 0.525f, 0.969f, 1.000f}; +vec4_t colorTurquoise = {0.251f, 0.878f, 0.816f, 1.000f}; +vec4_t colorWildWatermelon = {0.992f, 0.357f, 0.471f, 1.000f}; +vec4_t colorSaltpan = {0.933f, 0.953f, 0.898f, 1.000f}; +vec4_t colorGrayChateau = {0.624f, 0.639f, 0.655f, 1.000f}; +vec4_t colorRust = {0.718f, 0.255f, 0.055f, 1.000f}; +vec4_t colorCopperGreen = {0.431f, 0.553f, 0.443f, 1.000f}; +vec4_t colorGold = {1.000f, 0.843f, 0.000f, 1.000f}; +vec4_t colorSteelBlue = {0.275f, 0.510f, 0.706f, 1.000f}; +vec4_t colorSteelGray = {0.482f, 0.565f, 0.584f, 1.000f}; +vec4_t colorBronze = {0.804f, 0.498f, 0.196f, 1.000f}; +vec4_t colorSilver = {0.753f, 0.753f, 0.753f, 1.000f}; +vec4_t colorDarkGray = {0.663f, 0.663f, 0.663f, 1.000f}; +vec4_t colorDarkOrange = {1.000f, 0.549f, 0.000f, 1.000f}; +vec4_t colorDarkGreen = {0.000f, 0.392f, 0.000f, 1.000f}; +vec4_t colorRedOrange = {1.000f, 0.247f, 0.204f, 1.000f}; +vec4_t colorForestGreen = {0.133f, 0.545f, 0.133f, 1.000f}; +vec4_t colorBrightSun = {0.926f, 0.741f, 0.173f, 1.000f}; +vec4_t colorMediumSlateBlue = {0.482f, 0.408f, 0.933f, 1.000f}; +vec4_t colorCeleste = {0.698f, 1.000f, 1.000f, 1.000f}; +vec4_t colorIronstone = {0.525f, 0.314f, 0.251f, 1.000f}; +vec4_t colorTimberwolf = {0.859f, 0.843f, 0.824f, 1.000f}; +vec4_t colorOnyx = {0.059f, 0.059f, 0.059f, 1.000f}; +vec4_t colorRosewood = {0.396f, 0.000f, 0.043f, 1.000f}; +vec4_t colorKokoda = {0.482f, 0.471f, 0.353f, 1.000f}; +vec4_t colorPorsche = {0.875f, 0.616f, 0.357f, 1.000f}; +vec4_t colorCloudBurst = {0.208f, 0.369f, 0.310f, 1.000f}; +vec4_t colorBlueDiane = {0.208f, 0.318f, 0.310f, 1.000f}; +vec4_t colorRope = {0.557f, 0.349f, 0.235f, 1.000f}; +vec4_t colorBlonde = {0.980f, 0.941f, 0.745f, 1.000f}; +vec4_t colorSmokeyBlack = {0.063f, 0.047f, 0.031f, 1.000f}; +vec4_t colorAmericanRose = {1.000f, 0.012f, 0.243f, 1.000f}; +vec4_t colorNeonGreen = {0.224f, 1.000f, 0.078f, 1.000f}; +vec4_t colorNeonYellow = {0.980f, 0.929f, 0.153f, 1.000f}; +vec4_t colorUltramarine = {0.071f, 0.039f, 0.561f, 1.000f}; +vec4_t colorTurquoiseBlue = {0.000f, 1.000f, 0.937f, 1.000f}; +vec4_t colorDarkMagenta = {0.545f, 0.000f, 0.545f, 1.000f}; +vec4_t colorMagicMint = {0.667f, 0.941f, 0.820f, 1.000f}; +vec4_t colorLightGray = {0.827f, 0.827f, 0.827f, 1.000f}; +vec4_t colorLightSalmon = {1.000f, 0.600f, 0.600f, 1.000f}; +vec4_t colorLightGreen = {0.565f, 0.933f, 0.565f, 1.000f};""" + +cc_defines = """#define COLOR_BLACK '0' +#define COLOR_RED '1' +#define COLOR_GREEN '2' +#define COLOR_YELLOW '3' +#define COLOR_BLUE '4' +#define COLOR_CYAN '5' +#define COLOR_MAGENTA '6' +#define COLOR_WHITE '7' +#define COLOR_GRAY '8' +#define COLOR_ORANGE '9' +#define COLOR_ROSE_BUD 'a' +#define COLOR_PALE_GREEN 'b' +#define COLOR_PALE_GOLDEN 'c' +#define COLOR_COLUMBIA_BLUE 'd' +#define COLOR_PALE_TURQUOISE 'e' +#define COLOR_PALE_VIOLET_RED 'f' +#define COLOR_PALACE_PALE_WHITE 'g' +#define COLOR_OLIVE 'h' +#define COLOR_TOMATO 'i' +#define COLOR_LIME 'j' +#define COLOR_LEMON 'k' +#define COLOR_BLUE_BERRY 'l' +#define COLOR_TURQUOISE 'm' +#define COLOR_WILD_WATERMELON 'n' +#define COLOR_SALTPAN 'o' +#define COLOR_GRAY_CHATEAU 'p' +#define COLOR_RUST 'q' +#define COLOR_COPPER_GREEN 'r' +#define COLOR_GOLD 's' +#define COLOR_STEEL_BLUE 't' +#define COLOR_STEEL_GRAY 'u' +#define COLOR_BRONZE 'v' +#define COLOR_SILVER 'w' +#define COLOR_DARK_GRAY 'x' +#define COLOR_DARK_ORANGE 'y' +#define COLOR_DARK_GREEN 'z' +#define COLOR_RED_ORANGE 'A' +#define COLOR_FOREST_GREEN 'B' +#define COLOR_BRIGHT_SUN 'C' +#define COLOR_MEDIUM_SLATE_BLUE 'D' +#define COLOR_CELESTE 'E' +#define COLOR_IRONSTONE 'F' +#define COLOR_TIMBERWOLF 'G' +#define COLOR_ONYX 'H' +#define COLOR_ROSEWOOD 'I' +#define COLOR_KOKODA 'J' +#define COLOR_PORSCHE 'K' +#define COLOR_CLOUD_BURST 'L' +#define COLOR_BLUE_DIANE 'M' +#define COLOR_ROPE 'N' +#define COLOR_BLONDE 'O' +#define COLOR_SMOKEY_BLACK 'P' +#define COLOR_AMERICAN_ROSE 'Q' +#define COLOR_NEON_GREEN 'R' +#define COLOR_NEON_YELLOW 'S' +#define COLOR_ULTRAMARINE 'T' +#define COLOR_TURQUOISE_BLUE 'U' +#define COLOR_DARK_MAGENTA 'V' +#define COLOR_MAGIC_MINT 'W' +#define COLOR_LIGHT_GRAY 'X' +#define COLOR_LIGHT_SALMON 'Y' +#define COLOR_LIGHT_GREEN 'Z'""" + +colors = [] +for cc in cc_defines.split("\n"): + rv = re.match("#define\s+COLOR_([A-Z_]+)\s+\'(.)\'", cc) + + name, symbol = rv.groups() + search = name.replace("_", "").lower() + + for line in color_vectors.split("\n"): + rv = re.match(".*color([a-zA-Z]+)", line) + if search != rv.group(1).lower(): + continue + + rv = re.match(".*{(\d+\.\d+)f, (\d+\.\d+)f, (\d+\.\d+)f", line) + rgb = [float(group) for group in rv.groups()] + colors.append([symbol, rgb, name.replace("_", " ").lower()]) + +print("palette_24_bit = [") +for symbol, rgb, name in colors: + code = "#" + "".join(["%02x" % int(c * 255) for c in rgb]) + print("\t(\"trem %s\", \"%s\", \"black\"), # %s" % (symbol, code, name)) +print("]") diff --git a/testing/log_simulator.py b/testing/log_simulator.py index ab9cfc0..8256412 100644 --- a/testing/log_simulator.py +++ b/testing/log_simulator.py @@ -3,20 +3,25 @@ import time, random # lipsum.pl pasta = [ "Drogi Marszałku, Wysoka Izbo.", - "PKB rośnie.", + "PKB ^2rośnie^7.", "Z drugiej strony, wykorzystanie unijnych dotacji rozszerza nam horyzonty kierunków postępowego wychowania.", "Nie muszę państwa przekonywać, że zmiana istniejących kryteriów umożliwia w określaniu postaw uczestników wobec zadań stanowionych przez organizację.", - "Restrukturyzacja.", + "^3Restrukturyzacja.", "Nie chcę państwu niczego sugerować, ale aktualna struktura organizacji spełnia istotną rolę w określaniu dalszych kierunków postępowego wychowania.", "Jednakże, inwestowanie w kształtowaniu kolejnych kroków w określaniu obecnej sytuacji.", "Podniosły się wskaźniki.", "Wyższe założenie ideowe, a także dokończenie aktualnych projektów pociąga za najważniejszy punkt naszych działań obierzemy praktykę, nie możemy zdradzać iż rozszerzenie naszej działalności wymaga niezwykłej precyzji w przygotowaniu i bogate doświadczenia pozwalają na stałe zabezpieczenie informacyjne naszej działalności jest zauważenie, że konsultacja z szerokim aktywem rozszerza nam efekt systemu szkolenia kadry odpowiadającego potrzebom.", "Nie muszę państwa przekonywać, że zakończenie tego projektu wymaga niezwykłej precyzji w tym zakresie rozszerza nam horyzonty systemu obsługi spełnia istotną rolę w restrukturyzacji przedsiębiorstwa.", "Natomiast zawiązanie koalicji pociąga za sobą proces wdrożenia i znaczenia tych problemów nie trzeba udowadniać, ponieważ realizacja określonych zadań stanowionych przez organizację.", - "Tylko spokojnie.", + "^1Tylko spokojnie.", "Nie muszę państwa przekonywać, że zmiana istniejących kryteriów koliduje z." ] +print("Testing colors: ", end="") +for ch in "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": + print("^%s%s" % (ch, ch), end="") +print("") + def print_line(): print(random.choice(pasta), flush=True) diff --git a/trem_colors.py b/trem_colors.py new file mode 100644 index 0000000..073fc7a --- /dev/null +++ b/trem_colors.py @@ -0,0 +1,96 @@ +def trem_to_markup(text): + style = "trem 7" + markup = list() + + cursor = 0 + start = 0 + while True: + caret = text.find("^", cursor) + cursor = caret + 1 + + end = caret if caret != -1 else None + markup.append((style, text[start:end])) + + if caret == -1: + break + + if caret + 1 < len(text): + cc = text[caret + 1] + + # Two carets turn into a literal caret + if cc == "^": + start = cursor + cursor += 1 + continue + else: + style = "trem " + cc + + start = cursor + 1 + + return markup + +# FIXME: fill in the low-color mode colors (columns 2 and 3) +trem_palette = [ + ("trem 0", "white", "black", None, "#000000", "black"), # black + ("trem 1", "white", "black", None, "#ff0000", "black"), # red + ("trem 2", "white", "black", None, "#00ff00", "black"), # green + ("trem 3", "white", "black", None, "#ffff00", "black"), # yellow + ("trem 4", "white", "black", None, "#0000ff", "black"), # blue + ("trem 5", "white", "black", None, "#00ffff", "black"), # cyan + ("trem 6", "white", "black", None, "#ff00ff", "black"), # magenta + ("trem 7", "white", "black", None, "#ffffff", "black"), # white + ("trem 8", "white", "black", None, "#808080", "black"), # gray + ("trem 9", "white", "black", None, "#ffae00", "black"), # orange + ("trem a", "white", "black", None, "#fdab9a", "black"), # rose bud + ("trem b", "white", "black", None, "#97fa97", "black"), # pale green + ("trem c", "white", "black", None, "#ede8aa", "black"), # pale golden + ("trem d", "white", "black", None, "#9bddff", "black"), # columbia blue + ("trem e", "white", "black", None, "#aeeded", "black"), # pale turquoise + ("trem f", "white", "black", None, "#db6f92", "black"), # pale violet red + ("trem g", "white", "black", None, "#e8e4dc", "black"), # palace pale white + ("trem h", "white", "black", None, "#3a3b36", "black"), # olive + ("trem i", "white", "black", None, "#ff6246", "black"), # tomato + ("trem j", "white", "black", None, "#beff00", "black"), # lime + ("trem k", "white", "black", None, "#fff700", "black"), # lemon + ("trem l", "white", "black", None, "#4f85f7", "black"), # blue berry + ("trem m", "white", "black", None, "#40dfd0", "black"), # turquoise + ("trem n", "white", "black", None, "#fc5b78", "black"), # wild watermelon + ("trem o", "white", "black", None, "#edf3e4", "black"), # saltpan + ("trem p", "white", "black", None, "#9fa2a7", "black"), # gray chateau + ("trem q", "white", "black", None, "#b7410e", "black"), # rust + ("trem r", "white", "black", None, "#6d8d70", "black"), # copper green + ("trem s", "white", "black", None, "#ffd600", "black"), # gold + ("trem t", "white", "black", None, "#4682b4", "black"), # steel blue + ("trem u", "white", "black", None, "#7a9094", "black"), # steel gray + ("trem v", "white", "black", None, "#cd7e31", "black"), # bronze + ("trem w", "white", "black", None, "#c0c0c0", "black"), # silver + ("trem x", "white", "black", None, "#a9a9a9", "black"), # dark gray + ("trem y", "white", "black", None, "#ff8b00", "black"), # dark orange + ("trem z", "white", "black", None, "#006300", "black"), # dark green + ("trem A", "white", "black", None, "#ff3e34", "black"), # red orange + ("trem B", "white", "black", None, "#218a21", "black"), # forest green + ("trem C", "white", "black", None, "#ecbc2c", "black"), # bright sun + ("trem D", "white", "black", None, "#7a68ed", "black"), # medium slate blue + ("trem E", "white", "black", None, "#b1ffff", "black"), # celeste + ("trem F", "white", "black", None, "#855040", "black"), # ironstone + ("trem G", "white", "black", None, "#dbd6d2", "black"), # timberwolf + ("trem H", "white", "black", None, "#0f0f0f", "black"), # onyx + ("trem I", "white", "black", None, "#64000a", "black"), # rosewood + ("trem J", "white", "black", None, "#7a785a", "black"), # kokoda + ("trem K", "white", "black", None, "#df9d5b", "black"), # porsche + ("trem L", "white", "black", None, "#355e4f", "black"), # cloud burst + ("trem M", "white", "black", None, "#35514f", "black"), # blue diane + ("trem N", "white", "black", None, "#8e583b", "black"), # rope + ("trem O", "white", "black", None, "#f9efbd", "black"), # blonde + ("trem P", "white", "black", None, "#100b07", "black"), # smokey black + ("trem Q", "white", "black", None, "#ff033d", "black"), # american rose + ("trem R", "white", "black", None, "#39ff13", "black"), # neon green + ("trem S", "white", "black", None, "#f9ec27", "black"), # neon yellow + ("trem T", "white", "black", None, "#12098f", "black"), # ultramarine + ("trem U", "white", "black", None, "#00ffee", "black"), # turquoise blue + ("trem V", "white", "black", None, "#8a008a", "black"), # dark magenta + ("trem W", "white", "black", None, "#aaefd1", "black"), # magic mint + ("trem X", "white", "black", None, "#d2d2d2", "black"), # light gray + ("trem Y", "white", "black", None, "#ff9999", "black"), # light salmon + ("trem Z", "white", "black", None, "#90ed90", "black"), # light green +] -- cgit