MiRCARTToAnsi.py: added.

MiRCARTToPngFile.py: clean up _ColourMap{Bold,Normal}.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2019-01-21 10:23:19 +01:00
parent efd8b20671
commit a4fa91f894
2 changed files with 80 additions and 16 deletions

64
MiRCART-python/MiRCARTToAnsi.py Executable file
View File

@ -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 <lucio@lucioillanes.de>
# 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: {} <MiRCART input file pathname>".format(sys.argv[0]), file=sys.stderr)
else:
main(*sys.argv)
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

View File

@ -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
]