forked from hkc/cc-stuff
1
0
Fork 0
cc-stuff/nfpview.py

63 lines
1.3 KiB
Python
Raw Normal View History

2023-12-20 19:59:28 +03:00
#!/usr/bin/env python3
from argparse import ArgumentParser
colors = {
"0": (240, 240, 240),
"1": (242, 178, 51),
"2": (229, 127, 216),
"3": (153, 178, 242),
"4": (222, 222, 108),
"5": (127, 204, 25),
"6": (242, 178, 204),
"7": ( 76, 76, 76),
"8": (153, 153, 153),
"9": ( 76, 153, 178),
"a": (178, 102, 229),
"b": ( 51, 102, 204),
"c": (127, 102, 76),
"d": ( 87, 166, 78),
"e": (204, 76, 76),
"f": ( 17, 17, 17),
}
color_names = {
"0": "white",
"1": "orange",
"2": "magenta",
"3": "lightBlue",
"4": "yellow",
"5": "lime",
"6": "pink",
"7": "gray",
"8": "lightGray",
"9": "cyan",
"a": "purple",
"b": "blue",
"c": "brown",
"d": "green",
"e": "red",
"f": "black",
}
parser = ArgumentParser(description="CC default image viewer")
parser.add_argument("filename")
def color(v: str):
return tuple(bytes.fromhex(v.lstrip('#')))
for k, (r, g, b) in colors.items():
parser.add_argument(f"-{k}", type=color, default=(r, g, b),
help="Set color %s" % color_names[k])
args = parser.parse_args()
with open(args.filename, "r") as fp:
for line in fp:
for char in line.rstrip():
if char in colors:
print("\x1b[48;2;%d;%d;%dm \x1b[0m" % colors[char], end="")
else:
print(" ", end="")
print()