From d5bd09072aa096c840999ac39a0b260281ce5c04 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Fri, 24 May 2024 17:37:46 -0700 Subject: [PATCH] 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 --- colorhash/__main__.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/colorhash/__main__.py b/colorhash/__main__.py index 5641338..81b8a82 100644 --- a/colorhash/__main__.py +++ b/colorhash/__main__.py @@ -15,7 +15,7 @@ from .svg import gensvg # TODO - WASM compile for embedding directly in HTML # TODO - option to add a caption based on the filename # TODO - load palettes from a file -# TODO - HSV color +# TODO - better dimensions for randomart matricizer def main() -> None: @@ -31,19 +31,15 @@ def main() -> None: ) PALETTE_CHOICES = [ "auto", - "red", - "green", - "blue", - "black", - "cyan", - "yellow", - "magenta", - "white", - ] + ] + list(PALETTES.keys()) PALETTE_HELP = "\n".join( [ "PALETTE CHOICES", - " " + ", ".join(PALETTE_CHOICES), + '\n'.join(textwrap.wrap( + ", ".join(PALETTE_CHOICES), + initial_indent=" ", + subsequent_indent=" ", + )), ] ) 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( [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] if progname.endswith("__main__.py"): @@ -161,7 +157,7 @@ def main() -> None: # Choose the palette palette: list[str] if args.palette == "auto": - palette = list(DEFAULT_PALETTES.values())[sum(hashdata) % 8] + palette = list(DEFAULT_PALETTES.values())[sum(hashdata) % len(DEFAULT_PALETTES)] else: palette = PALETTES[args.palette]