Fix a few things in __main__.py

* Palette choices are determined by the list of palettes available and
  not hard-coded
* Auto palette is chosen by the length of the palette choices rather
  than hard-coded
* Palette help listing is text-wrapped at 70 characters

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2024-05-24 17:37:46 -07:00
parent 1277c2db8b
commit d5bd09072a

View File

@@ -15,7 +15,7 @@ from .svg import gensvg
# TODO - WASM compile for embedding directly in HTML # TODO - WASM compile for embedding directly in HTML
# TODO - option to add a caption based on the filename # TODO - option to add a caption based on the filename
# TODO - load palettes from a file # TODO - load palettes from a file
# TODO - HSV color # TODO - better dimensions for randomart matricizer
def main() -> None: def main() -> None:
@@ -31,19 +31,15 @@ def main() -> None:
) )
PALETTE_CHOICES = [ PALETTE_CHOICES = [
"auto", "auto",
"red", ] + list(PALETTES.keys())
"green",
"blue",
"black",
"cyan",
"yellow",
"magenta",
"white",
]
PALETTE_HELP = "\n".join( PALETTE_HELP = "\n".join(
[ [
"PALETTE CHOICES", "PALETTE CHOICES",
" " + ", ".join(PALETTE_CHOICES), '\n'.join(textwrap.wrap(
", ".join(PALETTE_CHOICES),
initial_indent=" ",
subsequent_indent=" ",
)),
] ]
) )
HASH_CHOICES = ["md5", "sha1", "sha224", "sha256", "sha384", "sha512"] HASH_CHOICES = ["md5", "sha1", "sha224", "sha256", "sha384", "sha512"]
@@ -55,7 +51,7 @@ def main() -> None:
INPUT_TYPE_HELP = "INPUT TYPE (-x, --input-type)\n" + "\n".join( INPUT_TYPE_HELP = "INPUT TYPE (-x, --input-type)\n" + "\n".join(
[f" {choice} - {desc}" for choice, desc in INPUT_TYPE_CHOICES.items()] [f" {choice} - {desc}" for choice, desc in INPUT_TYPE_CHOICES.items()]
) )
EPILOGUE = "\n\n".join([MATRIX_HELP, PALETTE_HELP]) EPILOGUE = "\n\n".join([MATRIX_HELP, PALETTE_HELP, INPUT_TYPE_HELP])
progname: str = sys.argv[0] progname: str = sys.argv[0]
if progname.endswith("__main__.py"): if progname.endswith("__main__.py"):
@@ -161,7 +157,7 @@ def main() -> None:
# Choose the palette # Choose the palette
palette: list[str] palette: list[str]
if args.palette == "auto": if args.palette == "auto":
palette = list(DEFAULT_PALETTES.values())[sum(hashdata) % 8] palette = list(DEFAULT_PALETTES.values())[sum(hashdata) % len(DEFAULT_PALETTES)]
else: else:
palette = PALETTES[args.palette] palette = PALETTES[args.palette]