From add023fa5f0cc9269ac866f903248da9d65be6cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Mon, 21 Jan 2019 10:23:19 +0100 Subject: [PATCH] MiRCARTToAnsi.py: added. MiRCARTToPngFile.py: clean up _ColourMap{Bold,Normal}. --- MiRCART-python/MiRCARTToAnsi.py | 64 ++++++++++++++++++++++++++++++ MiRCART-python/MiRCARTToPngFile.py | 32 +++++++-------- 2 files changed, 80 insertions(+), 16 deletions(-) create mode 100755 MiRCART-python/MiRCARTToAnsi.py diff --git a/MiRCART-python/MiRCARTToAnsi.py b/MiRCART-python/MiRCARTToAnsi.py new file mode 100755 index 0000000..0cf539a --- /dev/null +++ b/MiRCART-python/MiRCARTToAnsi.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# +# MiRCARTToAnsi.py -- ToAnsi mIRC art {from,to} file (for munki) +# Copyright (c) 2018 Lucio Andrés Illanes Albornoz +# This project is licensed under the terms of the MIT licence. +# + +from MiRCARTCanvasImportStore import MiRCARTCanvasImportStore +import sys + +MiRCARTToAnsiColours = [ + 97, # Bright White + 30, # Black + 94, # Light Blue + 32, # Green + 31, # Red + 91, # Light Red + 35, # Pink + 33, # Yellow + 93, # Light Yellow + 92, # Light Green + 36, # Cyan + 96, # Light Cyan + 34, # Blue + 95, # Light Pink + 90, # Grey + 37, # Light Grey +]; + +def ToAnsi(inPathName): + canvasStore = MiRCARTCanvasImportStore(inPathName) + inMap = canvasStore.outMap.copy(); del canvasStore; + with open(inPathName, "w+") as outFile: + for inCurRow in range(len(inMap)): + lastAttribs = MiRCARTCanvasImportStore._CellState.CS_NONE + lastColours = None + for inCurCol in range(len(inMap[inCurRow])): + inCurCell = inMap[inCurRow][inCurCol] + if lastAttribs != inCurCell[2]: + if inCurCell[2] & MiRCARTCanvasImportStore._CellState.CS_BOLD: + print("\u001b[1m", end="", file=outFile) + if inCurCell[2] & MiRCARTCanvasImportStore._CellState.CS_UNDERLINE: + print("\u001b[4m", end="", file=outFile) + lastAttribs = inCurCell[2] + if lastColours == None or lastColours != inCurCell[:2]: + ansiBg = MiRCARTToAnsiColours[int(inCurCell[1])] + 10 + ansiFg = MiRCARTToAnsiColours[int(inCurCell[0])] + print("\u001b[{:02d}m\u001b[{:02d}m{}".format(ansiBg, ansiFg, inCurCell[3]), end="", file=outFile) + lastColours = inCurCell[:2] + else: + print(inCurCell[3], end="", file=outFile) + print("\u001b[0m\n", end="", file=outFile) + +# +# Entry point +def main(*argv): + ToAnsi(argv[1]) +if __name__ == "__main__": + if (len(sys.argv) - 1) != 1: + print("usage: {} ".format(sys.argv[0]), file=sys.stderr) + else: + main(*sys.argv) + +# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/MiRCART-python/MiRCARTToPngFile.py b/MiRCART-python/MiRCARTToPngFile.py index cfd9592..45bee4e 100755 --- a/MiRCART-python/MiRCARTToPngFile.py +++ b/MiRCART-python/MiRCARTToPngFile.py @@ -16,40 +16,40 @@ class MiRCARTToPngFile: # {{{ _ColourMapBold: mIRC colour number to RGBA map given ^B (bold) _ColourMapBold = [ - [255, 255, 255], # White - [85, 85, 85], # Grey + [255, 255, 255], # Bright White + [85, 85, 85], # Black [85, 85, 255], # Light Blue - [85, 255, 85], # Light Green - [255, 85, 85], # Light Red + [85, 255, 85], # Green + [255, 85, 85], # Red [255, 85, 85], # Light Red [255, 85, 255], # Pink - [255, 255, 85], # Light Yellow + [255, 255, 85], # Yellow [255, 255, 85], # Light Yellow [85, 255, 85], # Light Green + [85, 255, 255], # Cyan [85, 255, 255], # Light Cyan - [85, 255, 255], # Light Cyan - [85, 85, 255], # Light Blue - [255, 85, 255], # Pink + [85, 85, 255], # Blue + [255, 85, 255], # Light Pink [85, 85, 85], # Grey - [255, 255, 255], # White + [255, 255, 255], # Light Grey ] # }}} # {{{ _ColourMapNormal: mIRC colour number to RGBA map given none of ^[BFV_] (bold, italic, reverse, underline) _ColourMapNormal = [ - [255, 255, 255], # White + [255, 255, 255], # Bright White [0, 0, 0], # Black - [0, 0, 187], # Blue + [0, 0, 187], # Light Blue [0, 187, 0], # Green - [255, 85, 85], # Light Red - [187, 0, 0], # Red - [187, 0, 187], # Purple + [255, 85, 85], # Red + [187, 0, 0], # Light Red + [187, 0, 187], # Pink [187, 187, 0], # Yellow [255, 255, 85], # Light Yellow [85, 255, 85], # Light Green [0, 187, 187], # Cyan [85, 255, 255], # Light Cyan - [85, 85, 255], # Light Blue - [255, 85, 255], # Pink + [85, 85, 255], # Blue + [255, 85, 255], # Light Pink [85, 85, 85], # Grey [187, 187, 187], # Light Grey ]