forked from hkc/cc-stuff
63 lines
1.3 KiB
Python
63 lines
1.3 KiB
Python
|
#!/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()
|