From 56f362c1ce4e6f8892936e29a82a359bfd605042 Mon Sep 17 00:00:00 2001 From: klemek Date: Sat, 7 Nov 2026 15:47:34 +0100 Subject: [PATCH] feat: add CLI arguments to project --- README.md | 23 +++- pyproject.toml | 2 +- resources/cp437_names.txt | 256 ++++++++++++++++++++++++++++++++++++ resources/cp437_sets.csv | 10 ++ src/glsl_glyphs/__init__.py | 2 +- src/glsl_glyphs/logs.py | 8 +- src/glsl_glyphs/params.py | 42 +++++- 7 files changed, 333 insertions(+), 10 deletions(-) create mode 100644 resources/cp437_names.txt create mode 100644 resources/cp437_sets.csv diff --git a/README.md b/README.md index 4ad3c98..7e93e3f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,28 @@ > Generate GLSL ready 8x8 glyph maps and usable functions -(wip) +## Usage + +```txt +usage: glsl_glyphs [-h] -i SOURCE_IMAGE_PATH -o TARGET_PATH [-n SOURCE_NAMES_PATH] [-s SOURCE_SETS_PATH] [--functions | --no-functions] + [--verbose | --no-verbose] [--quiet | --no-quiet] + +options: + -h, --help show this help message and exit + -i, --input SOURCE_IMAGE_PATH + png 8x8 glyph map + -o, --output TARGET_PATH + output glsl file + -n, --names SOURCE_NAMES_PATH + character names, one line each + -s, --sets SOURCE_SETS_PATH + defined sets in CSV: index,length,name + --functions, --no-functions + add GLSL functions to output (default) + --verbose, --no-verbose + more verbose logging + --quiet, --no-quiet disable logging +``` ## More info about included resources diff --git a/pyproject.toml b/pyproject.toml index 212bf67..2c90006 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ add-bounds = "major" [tool.ruff.lint] select = ["ALL"] -ignore = ["D", "E501", "ANN401", "BLE001", "COM812", "S101"] +ignore = ["D", "E501", "ANN401", "BLE001", "COM812", "S101", "CPY"] [tool.ty.src] include = ["src"] diff --git a/resources/cp437_names.txt b/resources/cp437_names.txt new file mode 100644 index 0000000..41d86c3 --- /dev/null +++ b/resources/cp437_names.txt @@ -0,0 +1,256 @@ +EMPTY +SMILEY BLACK +SMILEY LIGHT +HEART +DIAMOND +CLUB +SPADE +DOT +INVERT DOT +CIRCLE +INVERT CIRCLE +MALE +FEMALE +NOTE +DOUBLE NOTE +SUN +RIGHT TRIANGLE +LEFT TRIANGLE +ARROW UP DOWN +DOUBLE EXCLAMATION +PARAGRAPH +? +HALF SQUARE BOTTOM +ARROW UP DOWN UNDERLINED +ARROW UP +ARROW DOWN +ARROW RIGHT +ARROW LEFT +? +ARROW LEFT RIGHT +TRIANGLE UP +TRIANGLE DOWN +SPACE +! +" +# +$ +% +& +' +( +) +* ++ +, +- +. +/ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +: +; +< += +> +? +@ +A +B +C +D +E +F +G +H +I +J +K +L +M +N +O +P +Q +R +S +T +U +V +W +X +Y +Z +[ +ANTISHASH +] +^ +_ +` +a +b +c +d +e +f +g +h +i +j +k +l +m +n +o +p +q +r +s +t +u +v +w +x +y +z +{ +| +} +~ +HOUSE +Ç +ü +é +â +ä +à +å +ç +ê +ë +è +ï +î +ì +Ä +Å +É +æ +Æ +ô +ö +ò +û +ù +ÿ +Ö +Ü +¢ +£ +¥ +₧ +ƒ +á +í +ó +ú +ñ +Ñ +ª +º +¿ +⌐ +¬ +½ +¼ +¡ +« +» +░ +▒ +▓ +│ +┤ +╡ +╢ +╖ +╕ +╣ +║ +╗ +╝ +╜ +╛ +┐ +└ +┴ +┬ +├ +─ +┼ +╞ +╟ +╚ +╔ +╩ +╦ +╠ +═ +╬ +╧ +╨ +╤ +╥ +╙ +╘ +╒ +╓ +╫ +╪ +┘ +┌ +█ +▄ +▌ +▐ +▀ +α +ß +Γ +π +Σ +σ +µ +τ +Φ +Θ +Ω +δ +∞ +φ +ε +∩ +≡ +± +≥ +≤ +⌠ +⌡ +÷ +≈ +° +∙ +· +√ +ⁿ +² +■ +NBSP diff --git a/resources/cp437_sets.csv b/resources/cp437_sets.csv new file mode 100644 index 0000000..45cd05f --- /dev/null +++ b/resources/cp437_sets.csv @@ -0,0 +1,10 @@ +index, length, name +48, 10, NUMBERS +65, 26, UPPERCASE LETTERS +97, 26, LOWERCASE LETTERS +1, 15, SYMBOLS +24, 4, ARROWS +179, 40, BARS +224, 16, GREEK +128, 28, ACCENTS +176, 3, SHADES diff --git a/src/glsl_glyphs/__init__.py b/src/glsl_glyphs/__init__.py index 3289ac7..f0d0e99 100644 --- a/src/glsl_glyphs/__init__.py +++ b/src/glsl_glyphs/__init__.py @@ -1,4 +1,4 @@ import importlib.metadata -PKG_NAME = __name__ +PKG_NAME = "glsl-glyphs" PKG_VERSION = importlib.metadata.version(PKG_NAME) diff --git a/src/glsl_glyphs/logs.py b/src/glsl_glyphs/logs.py index 2ce841c..c1120fb 100644 --- a/src/glsl_glyphs/logs.py +++ b/src/glsl_glyphs/logs.py @@ -26,7 +26,7 @@ class TermColor(enum.StrEnum): return f"\033[{self.value}m" @typing.override - def __add__(self, value: typing.Any, /) -> str: # ty:ignore[invalid-method-override] + def __add__(self, value: typing.Any, /) -> str: return str(self) + str(value) def __radd__(self, value: typing.Any, /) -> str: @@ -53,7 +53,7 @@ class ColoredLoggingFormatter(logging.Formatter): } @typing.override - def __init__(self, trace: bool) -> None: + def __init__(self, trace: bool) -> None: # ty: ignore[invalid-method-override] self.trace: bool = trace super().__init__() @@ -77,8 +77,8 @@ class ColoredLoggingFormatter(logging.Formatter): def setup_logs(params: Parameters) -> None: stream_handler = logging.StreamHandler() - stream_handler.setFormatter(ColoredLoggingFormatter(trace=params.debug)) + stream_handler.setFormatter(ColoredLoggingFormatter(trace=params.verbose)) log_level = logging.INFO - if params.debug: + if params.verbose: log_level = logging.DEBUG logging.basicConfig(level=log_level, handlers=[stream_handler]) diff --git a/src/glsl_glyphs/params.py b/src/glsl_glyphs/params.py index dd0d026..9415ef9 100644 --- a/src/glsl_glyphs/params.py +++ b/src/glsl_glyphs/params.py @@ -7,7 +7,12 @@ from . import PKG_NAME @dataclasses.dataclass(frozen=True, slots=True) class Parameters: - debug: bool = False + source_image_path: str = "" + source_names_path: str | None = None + source_sets_path: str | None = None + target_path: str = "" + functions: bool = True + verbose: bool = False quiet: bool = False @classmethod @@ -22,10 +27,41 @@ def parse_parameters(args: typing.Sequence[str]) -> Parameters: suggest_on_error=True, ) parser.add_argument( - "--debug", action=argparse.BooleanOptionalAction, default=default_values.debug + "-i", + "--input", + required=True, + dest="source_image_path", + help="png 8x8 glyph map", ) parser.add_argument( - "--quiet", action=argparse.BooleanOptionalAction, default=default_values.quiet + "-o", "--output", required=True, dest="target_path", help="output glsl file" + ) + parser.add_argument( + "-n", "--names", dest="source_names_path", help="character names, one line each" + ) + parser.add_argument( + "-s", + "--sets", + dest="source_sets_path", + help="defined sets in CSV: index,length,name", + ) + parser.add_argument( + "--functions", + action=argparse.BooleanOptionalAction, + default=default_values.functions, + help="add GLSL functions to output (default)", + ) + parser.add_argument( + "--verbose", + action=argparse.BooleanOptionalAction, + default=default_values.verbose, + help="more verbose logging", + ) + parser.add_argument( + "--quiet", + action=argparse.BooleanOptionalAction, + default=default_values.quiet, + help="disable logging", ) parsed_args = parser.parse_args(args) return Parameters.from_namespace(parsed_args)