diff --git a/kuhy_credit/credit.json b/kuhy_credit/credit.json new file mode 100644 index 0000000..76e89c6 --- /dev/null +++ b/kuhy_credit/credit.json @@ -0,0 +1,6 @@ +{ + "url": "https://kuhy.duckdns.org", + "text": "Created by kuhy", + "logo": "unified-design-system/logo/final/kuhy.svg", + "tokens": "web_ui/src/tokens.css" +} diff --git a/kuhy_credit/flutter/lib/src/credit_data.g.dart b/kuhy_credit/flutter/lib/src/credit_data.g.dart new file mode 100644 index 0000000..80406a8 --- /dev/null +++ b/kuhy_credit/flutter/lib/src/credit_data.g.dart @@ -0,0 +1,139 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND (generated by kuhy_credit/generator/generate.py; DO NOT EDIT). +// ignore_for_file: public_member_api_docs + +const String kCreditUrl = "https://kuhy.duckdns.org"; +const String kCreditText = "Created by kuhy"; +const double kLogoSize = 512; +const int kLogoField = 0xFF211D1B; +const List<(int, List)> kLogoShapes = [ + ( + 0xFFB8862E, + [ + 232.45, 126.71, 235.4, 121.83, 236.86, 117.46, 237.16, 113.16, 236.11, + 108.55, 233.71, 104.34, 230.14, 100.74, 225.62, 97.95, 220.41, 96.16, + 214.75, 95.51, 208.86, 96.11, 202.89, 97.96, 196.97, 101.02, 191.8, + 104.61, 186.14, 109.43, 168.83, 127.05, 163.79, 131.69, 158.86, + 135.08, 156.85, 135.91, 155.0, 136.26, 153.32, 136.1, 151.51, 135.26, + 150.17, 134.03, 148.74, 131.95, 146.53, 126.68, 142.68, 113.58, + 140.39, 107.28, 137.47, 101.8, 134.17, 98.03, 131.62, 96.28, 129.3, + 95.34, 126.82, 94.91, 124.22, 94.99, 121.55, 95.59, 118.85, 96.69, + 116.18, 98.26, 113.59, 100.29, 110.67, 103.26, 108.46, 106.12, 104.82, + 112.71, 103.46, 116.33, 102.26, 120.85, 101.33, 129.4, 101.51, 134.83, + 102.18, 140.16, 107.16, 161.56, 107.92, 166.59, 108.16, 170.93, + 107.96, 175.3, 107.23, 180.39, 103.3, 196.89, 102.03, 203.6, 101.44, + 209.71, 101.57, 215.83, 102.56, 221.84, 104.46, 227.54, 106.85, + 232.14, 110.3, 236.77, 113.3, 239.71, 117.11, 242.44, 120.52, 244.13, + 124.51, 245.27, 128.36, 245.46, 131.44, 244.86, 134.25, 243.55, 137.1, + 241.19, 138.84, 238.98, 140.33, 236.37, 142.79, 229.46, 144.26, 222.2, + 146.91, 203.45, 149.0, 195.46, 150.82, 191.74, 152.78, 189.39, 155.06, + 187.98, 157.64, 187.54, 160.46, 188.07, 163.46, 189.54, 166.57, + 191.89, 170.18, 195.54, 176.49, 203.82, 187.93, 221.96, 192.91, + 229.15, 198.18, 235.26, 203.3, 239.57, 207.07, 241.74, 210.4, 243.03, + 213.78, 243.76, 217.74, 243.92, 221.07, 243.47, 224.8, 242.29, 228.25, + 240.44, 230.89, 238.38, 233.17, 235.92, 235.02, 233.11, 236.37, 230.0, + 237.18, 226.63, 237.42, 223.07, 237.07, 219.35, 236.13, 215.54, 234.6, + 211.66, 230.9, 205.16, 225.43, 198.15, 219.02, 191.41, 205.04, 178.08, + 200.57, 173.11, 197.35, 167.98, 196.49, 165.31, 196.29, 163.13, + 196.57, 160.98, 197.54, 158.44, 199.16, 155.9, 201.39, 153.37, 206.78, + 148.63, 224.45, 135.06, 228.82, 130.95, + ], + ), + ( + 0xFFB8862E, + [ + 439.15, 304.62, 441.35, 299.45, 442.51, 294.18, 442.42, 288.99, + 441.16, 284.54, 438.79, 280.56, 435.43, 277.23, 431.27, 274.73, + 426.09, 273.1, 421.13, 272.75, 416.7, 273.37, 412.03, 275.08, 407.76, + 277.8, 404.33, 280.97, 400.93, 285.13, 391.39, 300.46, 387.52, 305.61, + 384.97, 308.13, 382.62, 309.84, 379.82, 311.14, 377.32, 311.67, + 374.44, 311.56, 371.59, 310.69, 368.84, 309.1, 366.22, 306.86, 361.68, + 301.2, 353.72, 288.2, 349.9, 282.87, 345.1, 278.03, 339.97, 274.81, + 336.22, 273.46, 332.8, 272.84, 328.82, 272.8, 324.89, 273.46, 321.18, + 274.78, 317.81, 276.73, 314.92, 279.23, 312.64, 282.19, 311.36, + 284.65, 310.49, 287.28, 310.02, 290.04, 309.96, 292.87, 310.28, + 295.74, 311.1, 299.1, 313.73, 305.2, 316.79, 310.09, 321.01, 315.47, + 337.3, 332.65, 344.34, 340.99, 350.25, 349.71, 354.13, 357.71, 356.15, + 364.64, 356.94, 371.76, 356.69, 378.61, 354.92, 395.62, 354.93, + 400.36, 355.46, 405.02, 356.78, 409.97, 358.95, 414.48, 361.98, + 418.37, 365.77, 421.42, 369.24, 423.14, 372.98, 424.16, 376.83, + 424.43, 380.67, 423.95, 384.34, 422.72, 387.71, 420.81, 390.68, + 418.27, 393.42, 414.79, 394.87, 412.17, 396.16, 408.88, 397.04, 405.4, + 397.53, 401.79, 397.58, 394.42, 395.86, 378.48, 395.63, 371.63, + 396.54, 364.05, 398.85, 356.69, 402.9, 348.74, 408.61, 340.49, 415.36, + 332.56, 431.64, 315.37, 435.86, 309.98, + ], + ), + ( + 0xFFECEAE9, + [ + 272.87, 180.5, 273.78, 191.15, 275.43, 199.68, 277.93, 207.24, 281.46, + 214.32, 286.01, 220.83, 291.97, 227.15, 298.81, 232.68, 306.29, + 237.38, 314.83, 241.44, 323.65, 244.37, 331.97, 245.96, 340.33, + 246.39, 348.69, 245.62, 356.98, 243.7, 365.74, 240.46, 374.17, 236.11, + 379.85, 232.38, 385.15, 228.16, 389.95, 223.48, 393.76, 218.86, + 397.03, 213.89, 399.73, 208.6, 401.84, 203.03, 403.53, 196.59, 404.61, + 189.99, 405.3, 181.99, 405.89, 159.12, 407.09, 137.35, 407.21, 129.01, + 406.69, 121.27, 405.6, 115.09, 403.79, 109.27, 401.53, 104.61, 398.24, + 100.21, 394.25, 96.96, 389.72, 95.06, 385.41, 94.63, 381.04, 95.41, + 376.28, 97.71, 371.95, 101.35, 368.3, 106.12, 366.03, 110.43, 364.13, + 115.78, 363.07, 120.69, 362.53, 126.4, 362.58, 131.38, 363.12, 136.95, + 366.62, 155.29, 367.54, 162.94, 367.32, 171.38, 366.55, 176.01, 365.5, + 179.98, 363.26, 185.87, 360.61, 190.86, 357.41, 195.43, 353.74, + 199.38, 349.69, 202.52, 345.92, 204.46, 342.02, 205.56, 338.06, + 205.77, 334.12, 205.08, 330.28, 203.52, 326.61, 201.16, 322.73, + 197.62, 319.27, 193.35, 316.32, 188.55, 313.95, 183.43, 312.21, + 178.16, 310.8, 170.23, 310.73, 162.45, 311.59, 155.45, 315.0, 137.8, + 315.74, 128.01, 315.47, 123.01, 314.68, 118.04, 313.31, 113.22, + 311.38, 108.68, 308.91, 104.56, 305.95, 101.0, 302.59, 98.14, 298.95, + 96.07, 295.15, 94.89, 291.33, 94.64, 287.61, 95.31, 284.11, 96.89, + 281.8, 98.52, 279.7, 100.54, 277.81, 102.91, 275.86, 106.15, 273.2, + 112.94, 271.66, 120.41, 271.11, 126.72, 271.03, 133.73, 272.32, + 158.32, + ], + ), + ( + 0xFFECEAE9, + [ + 142.5, 408.93, 144.93, 412.86, 148.33, 416.82, 151.62, 419.58, 155.73, + 421.94, 159.96, 423.33, 164.11, 423.69, 168.0, 423.04, 171.46, 421.41, + 173.61, 419.69, 175.81, 417.09, 177.3, 414.53, 178.71, 411.07, 180.34, + 403.92, 181.9, 389.45, 182.76, 384.3, 184.38, 379.06, 186.6, 375.03, + 188.42, 372.84, 190.56, 370.93, 193.02, 369.3, 196.36, 367.72, 203.33, + 365.93, 207.41, 365.55, 211.54, 365.59, 218.2, 366.61, 224.14, 368.79, + 226.71, 370.32, 228.97, 372.13, 232.2, 376.09, 234.21, 380.29, 235.51, + 385.06, 237.68, 403.4, 239.06, 409.98, 241.43, 415.72, 243.06, 418.13, + 244.99, 420.16, 247.7, 422.03, 250.76, 423.22, 254.12, 423.7, 257.08, + 423.52, 260.7, 422.61, 263.71, 421.29, 267.19, 419.06, 269.9, 416.7, + 273.71, 412.09, 276.7, 406.63, 278.73, 400.57, 279.77, 394.13, 279.87, + 387.57, 279.19, 381.08, 277.76, 374.06, 273.42, 357.39, 272.7, 353.01, + 272.43, 348.73, 272.65, 344.45, 273.45, 339.45, 277.62, 323.51, + 278.95, 317.31, 279.71, 311.68, 279.93, 306.77, 279.2, 298.62, 277.23, + 291.66, 274.04, 285.39, 269.78, 280.17, 267.06, 277.83, 263.57, + 275.63, 260.56, 274.33, 256.94, 273.46, 253.99, 273.3, 250.64, 273.8, + 248.07, 274.77, 245.32, 276.56, 243.34, 278.53, 241.66, 280.88, 239.2, + 286.54, 237.66, 293.75, 235.48, 312.08, 233.95, 317.39, 231.82, 321.5, + 230.08, 323.74, 228.0, 325.7, 225.6, 327.39, 222.9, 328.79, 216.76, + 330.71, 209.32, 331.48, 201.85, 330.81, 198.02, 329.85, 195.07, + 328.73, 192.39, 327.32, 190.0, 325.62, 187.94, 323.64, 186.21, 321.39, + 184.11, 317.26, 182.6, 311.93, 180.42, 293.59, 179.04, 287.01, 177.76, + 283.44, 176.37, 280.76, 174.68, 278.43, 172.69, 276.48, 169.92, + 274.72, 167.34, 273.77, 163.98, 273.3, 161.03, 273.48, 157.4, 274.38, + 154.4, 275.7, 150.92, 277.93, 148.21, 280.29, 143.97, 285.54, 141.1, + 291.09, 139.19, 297.22, 138.23, 304.49, 138.34, 311.05, 139.18, 317.5, + 144.55, 338.96, 145.64, 347.04, 145.57, 351.31, 144.91, 356.27, + 139.77, 376.54, 138.77, 382.07, 138.23, 387.76, 138.29, 393.51, + 139.06, 399.17, 140.59, 404.59, + ], + ), +]; +const int kDarkSurface = 0xFF2B2624; +const int kDarkBorder = 0xFF463E3A; +const int kDarkText = 0xFFECEAE9; +const int kLightSurface = 0xFFFCFBFB; +const int kLightBorder = 0xFFE0DAD7; +const int kLightText = 0xFF211D1B; +const int kFocus = 0xFFB8862E; +const double kRadius = 12; +const double kSpaceSm = 8; +const double kSpaceMd = 16; +const double kTextBody = 16; diff --git a/kuhy_credit/generator/__init__.py b/kuhy_credit/generator/__init__.py new file mode 100644 index 0000000..77abf5c --- /dev/null +++ b/kuhy_credit/generator/__init__.py @@ -0,0 +1 @@ +"""Build-time generator: writes every stack's credit data from credit.json.""" diff --git a/kuhy_credit/generator/emit.py b/kuhy_credit/generator/emit.py new file mode 100644 index 0000000..7d1f9a2 --- /dev/null +++ b/kuhy_credit/generator/emit.py @@ -0,0 +1,156 @@ +"""Render the shared credit data as source text for each stack. + +Every emitter returns the full file. Long data (the SVG, the polygon points) +is wrapped into short lines so each stack's linter accepts the file as is. +""" + +from __future__ import annotations + +import json +import shlex +import textwrap +from dataclasses import dataclass +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from generator.svg import Logo + from generator.tokens import Palette, Tokens + +MARK = "generated by kuhy_credit/generator/generate.py; DO NOT EDIT" + + +@dataclass(frozen=True) +class Credit: + """Everything a stack needs: the words, the link, the art, the tokens.""" + + url: str + text: str + svg: str + logo: Logo + tokens: Tokens + + +def _num(v: float) -> str: + return f"{v:g}" if v != int(v) else f"{int(v)}.0" + + +def _wrap(items: list[str], indent: str, width: int = 76) -> str: + joined = ", ".join(items) + "," + return textwrap.fill(joined, width, initial_indent=indent, subsequent_indent=indent) + + +def _points(points: tuple[float, ...], indent: int) -> str: + return _wrap([_num(p) for p in points], " " * indent) + + +def _chunks(text: str, size: int = 60) -> list[str]: + return [json.dumps(text[i : i + size]) for i in range(0, len(text), size)] + + +def _argb(hex_colour: str) -> str: + return f"0xFF{hex_colour.lstrip('#').upper()}" + + +def python(c: Credit) -> str: + """kuhy_credit/_data.py.""" + shapes = "".join( + f' (\n "{s.fill}",\n (\n{_points(s.points, 12)}\n ),\n ),\n' + for s in c.logo.shapes + ) + + def pal(p: Palette) -> str: + return f'{{"surface": "{p.surface}", "border": "{p.border}", "text": "{p.text}"}}' + + t = c.tokens + return ( + f'"""The shared credit data ({MARK})."""\n\n' + f"URL = {json.dumps(c.url)}\nTEXT = {json.dumps(c.text)}\n" + f"LOGO_SIZE = {c.logo.size}\nLOGO_FIELD = {json.dumps(c.logo.field)}\n" + f"LOGO_SHAPES: tuple[tuple[str, tuple[float, ...]], ...] = (\n{shapes})\n" + f"DARK = {pal(t.dark)}\nLIGHT = {pal(t.light)}\n" + f'FOCUS = "{t.focus}"\nRADIUS = {t.radius}\nSPACE_SM = {t.space_sm}\n' + f"SPACE_MD = {t.space_md}\nTEXT_BODY = {t.text_body}\n" + ) + + +def web(c: Credit) -> str: + """web/src/credit-data.js.""" + svg = "\n + ".join(_chunks(c.svg)) + t = c.tokens + + def pal(p: Palette) -> str: + return f'{{ surface: "{p.surface}", border: "{p.border}", text: "{p.text}" }}' + + return ( + f"// The shared credit data ({MARK}).\n" + f"export const CREDIT_URL = {json.dumps(c.url)};\n" + f"export const CREDIT_TEXT = {json.dumps(c.text)};\n" + f"export const LOGO_SVG =\n {svg};\n" + f"export const TOKENS = {{\n dark: {pal(t.dark)},\n light: {pal(t.light)},\n" + f' focus: "{t.focus}",\n radius: {t.radius},\n spaceSm: {t.space_sm},\n' + f" spaceMd: {t.space_md},\n textBody: {t.text_body},\n}};\n" + ) + + +def flutter(c: Credit) -> str: + """flutter/lib/src/credit_data.g.dart.""" + shapes = "".join( + f" (\n {_argb(s.fill)},\n [\n{_points(s.points, 6)}\n ],\n ),\n" + for s in c.logo.shapes + ) + t = c.tokens + return ( + f"// GENERATED CODE - DO NOT MODIFY BY HAND ({MARK}).\n" + "// ignore_for_file: public_member_api_docs\n\n" + f"const String kCreditUrl = {json.dumps(c.url)};\n" + f"const String kCreditText = {json.dumps(c.text)};\n" + f"const double kLogoSize = {c.logo.size};\n" + f"const int kLogoField = {_argb(c.logo.field)};\n" + f"const List<(int, List)> kLogoShapes = [\n{shapes}];\n" + f"const int kDarkSurface = {_argb(t.dark.surface)};\n" + f"const int kDarkBorder = {_argb(t.dark.border)};\n" + f"const int kDarkText = {_argb(t.dark.text)};\n" + f"const int kLightSurface = {_argb(t.light.surface)};\n" + f"const int kLightBorder = {_argb(t.light.border)};\n" + f"const int kLightText = {_argb(t.light.text)};\n" + f"const int kFocus = {_argb(t.focus)};\n" + f"const double kRadius = {t.radius};\n" + f"const double kSpaceSm = {t.space_sm};\n" + f"const double kSpaceMd = {t.space_md};\n" + f"const double kTextBody = {t.text_body};\n" + ) + + +def godot(c: Credit) -> str: + """godot/addons/kuhy_credit/credit_data.gd.""" + svg = "\n\t+ ".join(_chunks(c.svg)) + t = c.tokens + + def pal(p: Palette) -> str: + return ( + f'{{\n\t"surface": Color("{p.surface}"),\n\t"border": Color("{p.border}"),' + f'\n\t"text": Color("{p.text}"),\n}}' + ) + + return ( + f"## The shared credit data ({MARK}).\n" + "extends RefCounted\n\n" + f"const URL := {json.dumps(c.url)}\n" + f"const TEXT := {json.dumps(c.text)}\n" + f"const LOGO_SVG := (\n\t{svg}\n)\n" + f"const DARK := {pal(t.dark)}\n" + f"const LIGHT := {pal(t.light)}\n" + f'const FOCUS := Color("{t.focus}")\n' + f"const RADIUS := {t.radius}\nconst SPACE_SM := {t.space_sm}\n" + f"const SPACE_MD := {t.space_md}\nconst TEXT_BODY := {t.text_body}\n" + ) + + +def terminal(c: Credit) -> str: + """terminal/kuhy-credit.sh.""" + return ( + "#!/bin/bash\n" + f"# Prints the one-line kuhy credit and opens nothing ({MARK}).\n" + "set -euo pipefail\n" + f"printf '%s %s\\n' {shlex.quote(c.text)} {shlex.quote(c.url)}\n" + ) diff --git a/kuhy_credit/generator/generate.py b/kuhy_credit/generator/generate.py new file mode 100644 index 0000000..8b903fd --- /dev/null +++ b/kuhy_credit/generator/generate.py @@ -0,0 +1,109 @@ +"""Write, or check, every stack's generated credit data. + + python -m generator.generate # rewrite all stacks + python -m generator.generate --check # exit 1 and name each drifted stack + +Reads kuhy_credit/credit.json (URL + text), the M1 art and tokens.css; the +paths in credit.json are relative to the repo root (the credit dir's parent). +""" + +from __future__ import annotations + +import argparse +import json +import sys +from dataclasses import dataclass +from pathlib import Path + +from generator import emit +from generator.svg import parse_logo +from generator.tokens import parse_tokens + +CREDIT_DIR = Path(__file__).resolve().parents[1] + +STACKS = { + "python": "kuhy_credit/_data.py", + "web": "web/src/credit-data.js", + "flutter": "flutter/lib/src/credit_data.g.dart", + "godot": "godot/addons/kuhy_credit/credit_data.gd", + "terminal": "terminal/kuhy-credit.sh", +} +_EMITTERS = { + "python": emit.python, + "web": emit.web, + "flutter": emit.flutter, + "godot": emit.godot, + "terminal": emit.terminal, +} + + +@dataclass(frozen=True) +class Drift: + """A stack whose generated file differs from what the sources give.""" + + stack: str + path: str + + +def load(credit_dir: Path) -> emit.Credit: + """Read credit.json and the files it points at.""" + data = json.loads((credit_dir / "credit.json").read_text()) + root = credit_dir.parent + svg = (root / data["logo"]).read_text() + return emit.Credit( + url=data["url"], + text=data["text"], + svg=svg, + logo=parse_logo(svg), + tokens=parse_tokens((root / data["tokens"]).read_text()), + ) + + +def render(credit_dir: Path) -> dict[str, str]: + """Every stack's expected file content.""" + credit = load(credit_dir) + return {stack: _EMITTERS[stack](credit) for stack in STACKS} + + +def drift(credit_dir: Path) -> list[Drift]: + """Stacks whose file on disk is missing or differs from render().""" + out = [] + for stack, text in render(credit_dir).items(): + path = credit_dir / STACKS[stack] + if not path.is_file() or path.read_text() != text: + out.append(Drift(stack, STACKS[stack])) + return out + + +def write(credit_dir: Path) -> None: + """Rewrite every stack's generated file.""" + for stack, text in render(credit_dir).items(): + path = credit_dir / STACKS[stack] + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(text) + if stack == "terminal": + path.chmod(0o755) + + +def main(argv: list[str] | None = None) -> int: + """CLI entry point; returns the exit code.""" + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--check", action="store_true", help="fail on drift, write nothing") + parser.add_argument("--dir", type=Path, default=CREDIT_DIR, help="the kuhy_credit dir") + args = parser.parse_args(argv) + if not args.check: + write(args.dir) + print(f"wrote {len(STACKS)} stacks") + return 0 + found = drift(args.dir) + for d in found: + print(f"drift: {d.stack} ({d.path}) differs from credit.json/logo/tokens") + if found: + print("fix: python -m generator.generate (from kuhy_credit/)") + return 1 + print(f"all {len(STACKS)} stacks in sync") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/kuhy_credit/generator/svg.py b/kuhy_credit/generator/svg.py new file mode 100644 index 0000000..a039278 --- /dev/null +++ b/kuhy_credit/generator/svg.py @@ -0,0 +1,86 @@ +"""Parse the M1 logo SVG into flat polygons every stack can draw. + +The art is a square field rect plus filled paths built only from absolute +M/L/Z commands. Each subpath becomes one polygon. The parser refuses anything +else (curves, relative commands) and refuses subpaths whose bounding boxes +overlap: an overlap could be a hole, which a plain polygon fill would paint +over. If the art ever gains a hole, generation fails loudly instead of +shipping a wrong logo. +""" + +from __future__ import annotations + +import re +import xml.etree.ElementTree as ET +from dataclasses import dataclass + +_NS = "{http://www.w3.org/2000/svg}" +_TOKEN = re.compile(r"[A-Za-z]|-?\d+(?:\.\d+)?") + + +@dataclass(frozen=True) +class Shape: + """One filled polygon: its colour and flat x, y, x, y, ... points.""" + + fill: str + points: tuple[float, ...] + + +@dataclass(frozen=True) +class Logo: + """The logo as a square size, a field colour and polygons on top.""" + + size: int + field: str + shapes: tuple[Shape, ...] + + +def _subpaths(d: str) -> list[list[float]]: + """Split path data into point lists, one per M ... Z subpath.""" + out: list[list[float]] = [] + current: list[float] = [] + for tok in _TOKEN.findall(d): + if tok in {"M", "L"}: + continue + if tok == "Z": + out.append(current) + current = [] + elif tok[0].isalpha(): + msg = f"unsupported path command {tok!r}: only M, L and Z" + raise ValueError(msg) + else: + current.append(float(tok)) + return out + + +def _bbox(points: list[float]) -> tuple[float, float, float, float]: + xs, ys = points[0::2], points[1::2] + return min(xs), min(ys), max(xs), max(ys) + + +def _check_disjoint(polys: list[list[float]]) -> None: + boxes = [_bbox(p) for p in polys] + for i, a in enumerate(boxes): + for b in boxes[i + 1 :]: + if a[0] < b[2] and b[0] < a[2] and a[1] < b[3] and b[1] < a[3]: + msg = "logo subpaths overlap: a hole needs a real path renderer" + raise ValueError(msg) + + +def parse_logo(text: str) -> Logo: + """Parse the SVG text into a :class:`Logo`.""" + root = ET.fromstring(text) # noqa: S314 - our own checked-in art + size = int(float(root.attrib["viewBox"].split()[2])) + field = next((r for r in root.iter(f"{_NS}rect") if r.get("id") == "field"), None) + field = field if field is not None else root.find("rect[@id='field']") + if field is None: + msg = "logo has no rect id=field" + raise ValueError(msg) + shapes: list[Shape] = [] + polys: list[list[float]] = [] + for path in [*root.iter(f"{_NS}path"), *root.iter("path")]: + for poly in _subpaths(path.attrib["d"]): + shapes.append(Shape(path.attrib["fill"], tuple(poly))) + polys.append(poly) + _check_disjoint(polys) + return Logo(size, field.attrib["fill"], tuple(shapes)) diff --git a/kuhy_credit/generator/tokens.py b/kuhy_credit/generator/tokens.py new file mode 100644 index 0000000..ff91da5 --- /dev/null +++ b/kuhy_credit/generator/tokens.py @@ -0,0 +1,75 @@ +"""Read the few design tokens the credit panel needs from tokens.css. + +tokens.css is the web stack's copy of unified-design-system; palette_check +already keeps it equal to the Dart and Tk copies, so reading this one file is +reading the shared token set. +""" + +from __future__ import annotations + +import re +from dataclasses import dataclass + +_ROOT = re.compile(r"^:root\s*\{(.*?)^\}", re.DOTALL | re.MULTILINE) +_LIGHT = re.compile(r"@media \(prefers-color-scheme: light\)\s*\{\s*:root\s*\{(.*?)\}", re.DOTALL) +_VAR = re.compile(r"(--[a-z0-9-]+):\s*([^;]+);") +_COMMENT = re.compile(r"/\*.*?\*/", re.DOTALL) + + +@dataclass(frozen=True) +class Palette: + """Panel colours for one theme.""" + + surface: str + border: str + text: str + + +@dataclass(frozen=True) +class Tokens: + """Both palettes plus the theme-free sizes, in px.""" + + dark: Palette + light: Palette + focus: str + radius: int + space_sm: int + space_md: int + text_body: int + + +def _vars(block: str) -> dict[str, str]: + return {k: v.strip() for k, v in _VAR.findall(block)} + + +def _get(table: dict[str, str], name: str) -> str: + if name not in table: + msg = f"tokens.css has no {name}" + raise ValueError(msg) + return table[name] + + +def _palette(table: dict[str, str]) -> Palette: + return Palette(_get(table, "--surface-1"), _get(table, "--border"), _get(table, "--text")) + + +def _px(table: dict[str, str], name: str) -> int: + return int(_get(table, name).removesuffix("px")) + + +def parse_tokens(css: str) -> Tokens: + """Parse the dark default and the light override out of tokens.css.""" + css = _COMMENT.sub("", css) + root_match = _ROOT.search(css) or re.search(r":root\s*\{(.*?)\}", css, re.DOTALL) + root = _vars(root_match.group(1)) if root_match else {} + light_match = _LIGHT.search(css) + light = {**root, **_vars(light_match.group(1) if light_match else "")} + return Tokens( + dark=_palette(root), + light=_palette(light), + focus=_get(root, "--focus-ring"), + radius=_px(root, "--radius-md"), + space_sm=_px(root, "--space-2"), + space_md=_px(root, "--space-3"), + text_body=_px(root, "--text-body"), + ) diff --git a/kuhy_credit/godot/addons/kuhy_credit/credit_data.gd b/kuhy_credit/godot/addons/kuhy_credit/credit_data.gd new file mode 100644 index 0000000..de2280d --- /dev/null +++ b/kuhy_credit/godot/addons/kuhy_credit/credit_data.gd @@ -0,0 +1,124 @@ +## The shared credit data (generated by kuhy_credit/generator/generate.py; DO NOT EDIT). +extends RefCounted + +const URL := "https://kuhy.duckdns.org" +const TEXT := "Created by kuhy" +const LOGO_SVG := ( + "\n\n\n\n\n" +) +const DARK := { + "surface": Color("#2b2624"), + "border": Color("#463e3a"), + "text": Color("#eceae9"), +} +const LIGHT := { + "surface": Color("#fcfbfb"), + "border": Color("#e0dad7"), + "text": Color("#211d1b"), +} +const FOCUS := Color("#b8862e") +const RADIUS := 12 +const SPACE_SM := 8 +const SPACE_MD := 16 +const TEXT_BODY := 16 diff --git a/kuhy_credit/kuhy_credit/__init__.py b/kuhy_credit/kuhy_credit/__init__.py new file mode 100644 index 0000000..255a8dc --- /dev/null +++ b/kuhy_credit/kuhy_credit/__init__.py @@ -0,0 +1,16 @@ +"""The shared "Created by kuhy" credit for Python programs. + +``credit_line()`` is the terminal form; :mod:`kuhy_credit.tk` holds the +Tkinter logo widget. The words and the link come from the generated +``_data`` module, which comes from ``credit.json``. +""" + +from kuhy_credit._data import TEXT, URL + + +def credit_line() -> str: + """The one-line credit for terminal programs: the text, then the URL.""" + return f"{TEXT} {URL}" + + +__all__ = ["TEXT", "URL", "credit_line"] diff --git a/kuhy_credit/kuhy_credit/_data.py b/kuhy_credit/kuhy_credit/_data.py new file mode 100644 index 0000000..7839960 --- /dev/null +++ b/kuhy_credit/kuhy_credit/_data.py @@ -0,0 +1,141 @@ +"""The shared credit data (generated by kuhy_credit/generator/generate.py; DO NOT EDIT).""" + +URL = "https://kuhy.duckdns.org" +TEXT = "Created by kuhy" +LOGO_SIZE = 512 +LOGO_FIELD = "#211D1B" +LOGO_SHAPES: tuple[tuple[str, tuple[float, ...]], ...] = ( + ( + "#B8862E", + ( + 232.45, 126.71, 235.4, 121.83, 236.86, 117.46, 237.16, 113.16, + 236.11, 108.55, 233.71, 104.34, 230.14, 100.74, 225.62, 97.95, + 220.41, 96.16, 214.75, 95.51, 208.86, 96.11, 202.89, 97.96, + 196.97, 101.02, 191.8, 104.61, 186.14, 109.43, 168.83, 127.05, + 163.79, 131.69, 158.86, 135.08, 156.85, 135.91, 155.0, 136.26, + 153.32, 136.1, 151.51, 135.26, 150.17, 134.03, 148.74, 131.95, + 146.53, 126.68, 142.68, 113.58, 140.39, 107.28, 137.47, 101.8, + 134.17, 98.03, 131.62, 96.28, 129.3, 95.34, 126.82, 94.91, + 124.22, 94.99, 121.55, 95.59, 118.85, 96.69, 116.18, 98.26, + 113.59, 100.29, 110.67, 103.26, 108.46, 106.12, 104.82, 112.71, + 103.46, 116.33, 102.26, 120.85, 101.33, 129.4, 101.51, 134.83, + 102.18, 140.16, 107.16, 161.56, 107.92, 166.59, 108.16, 170.93, + 107.96, 175.3, 107.23, 180.39, 103.3, 196.89, 102.03, 203.6, + 101.44, 209.71, 101.57, 215.83, 102.56, 221.84, 104.46, 227.54, + 106.85, 232.14, 110.3, 236.77, 113.3, 239.71, 117.11, 242.44, + 120.52, 244.13, 124.51, 245.27, 128.36, 245.46, 131.44, 244.86, + 134.25, 243.55, 137.1, 241.19, 138.84, 238.98, 140.33, 236.37, + 142.79, 229.46, 144.26, 222.2, 146.91, 203.45, 149.0, 195.46, + 150.82, 191.74, 152.78, 189.39, 155.06, 187.98, 157.64, 187.54, + 160.46, 188.07, 163.46, 189.54, 166.57, 191.89, 170.18, 195.54, + 176.49, 203.82, 187.93, 221.96, 192.91, 229.15, 198.18, 235.26, + 203.3, 239.57, 207.07, 241.74, 210.4, 243.03, 213.78, 243.76, + 217.74, 243.92, 221.07, 243.47, 224.8, 242.29, 228.25, 240.44, + 230.89, 238.38, 233.17, 235.92, 235.02, 233.11, 236.37, 230.0, + 237.18, 226.63, 237.42, 223.07, 237.07, 219.35, 236.13, 215.54, + 234.6, 211.66, 230.9, 205.16, 225.43, 198.15, 219.02, 191.41, + 205.04, 178.08, 200.57, 173.11, 197.35, 167.98, 196.49, 165.31, + 196.29, 163.13, 196.57, 160.98, 197.54, 158.44, 199.16, 155.9, + 201.39, 153.37, 206.78, 148.63, 224.45, 135.06, 228.82, 130.95, + ), + ), + ( + "#B8862E", + ( + 439.15, 304.62, 441.35, 299.45, 442.51, 294.18, 442.42, 288.99, + 441.16, 284.54, 438.79, 280.56, 435.43, 277.23, 431.27, 274.73, + 426.09, 273.1, 421.13, 272.75, 416.7, 273.37, 412.03, 275.08, + 407.76, 277.8, 404.33, 280.97, 400.93, 285.13, 391.39, 300.46, + 387.52, 305.61, 384.97, 308.13, 382.62, 309.84, 379.82, 311.14, + 377.32, 311.67, 374.44, 311.56, 371.59, 310.69, 368.84, 309.1, + 366.22, 306.86, 361.68, 301.2, 353.72, 288.2, 349.9, 282.87, + 345.1, 278.03, 339.97, 274.81, 336.22, 273.46, 332.8, 272.84, + 328.82, 272.8, 324.89, 273.46, 321.18, 274.78, 317.81, 276.73, + 314.92, 279.23, 312.64, 282.19, 311.36, 284.65, 310.49, 287.28, + 310.02, 290.04, 309.96, 292.87, 310.28, 295.74, 311.1, 299.1, + 313.73, 305.2, 316.79, 310.09, 321.01, 315.47, 337.3, 332.65, + 344.34, 340.99, 350.25, 349.71, 354.13, 357.71, 356.15, 364.64, + 356.94, 371.76, 356.69, 378.61, 354.92, 395.62, 354.93, 400.36, + 355.46, 405.02, 356.78, 409.97, 358.95, 414.48, 361.98, 418.37, + 365.77, 421.42, 369.24, 423.14, 372.98, 424.16, 376.83, 424.43, + 380.67, 423.95, 384.34, 422.72, 387.71, 420.81, 390.68, 418.27, + 393.42, 414.79, 394.87, 412.17, 396.16, 408.88, 397.04, 405.4, + 397.53, 401.79, 397.58, 394.42, 395.86, 378.48, 395.63, 371.63, + 396.54, 364.05, 398.85, 356.69, 402.9, 348.74, 408.61, 340.49, + 415.36, 332.56, 431.64, 315.37, 435.86, 309.98, + ), + ), + ( + "#ECEAE9", + ( + 272.87, 180.5, 273.78, 191.15, 275.43, 199.68, 277.93, 207.24, + 281.46, 214.32, 286.01, 220.83, 291.97, 227.15, 298.81, 232.68, + 306.29, 237.38, 314.83, 241.44, 323.65, 244.37, 331.97, 245.96, + 340.33, 246.39, 348.69, 245.62, 356.98, 243.7, 365.74, 240.46, + 374.17, 236.11, 379.85, 232.38, 385.15, 228.16, 389.95, 223.48, + 393.76, 218.86, 397.03, 213.89, 399.73, 208.6, 401.84, 203.03, + 403.53, 196.59, 404.61, 189.99, 405.3, 181.99, 405.89, 159.12, + 407.09, 137.35, 407.21, 129.01, 406.69, 121.27, 405.6, 115.09, + 403.79, 109.27, 401.53, 104.61, 398.24, 100.21, 394.25, 96.96, + 389.72, 95.06, 385.41, 94.63, 381.04, 95.41, 376.28, 97.71, + 371.95, 101.35, 368.3, 106.12, 366.03, 110.43, 364.13, 115.78, + 363.07, 120.69, 362.53, 126.4, 362.58, 131.38, 363.12, 136.95, + 366.62, 155.29, 367.54, 162.94, 367.32, 171.38, 366.55, 176.01, + 365.5, 179.98, 363.26, 185.87, 360.61, 190.86, 357.41, 195.43, + 353.74, 199.38, 349.69, 202.52, 345.92, 204.46, 342.02, 205.56, + 338.06, 205.77, 334.12, 205.08, 330.28, 203.52, 326.61, 201.16, + 322.73, 197.62, 319.27, 193.35, 316.32, 188.55, 313.95, 183.43, + 312.21, 178.16, 310.8, 170.23, 310.73, 162.45, 311.59, 155.45, + 315.0, 137.8, 315.74, 128.01, 315.47, 123.01, 314.68, 118.04, + 313.31, 113.22, 311.38, 108.68, 308.91, 104.56, 305.95, 101.0, + 302.59, 98.14, 298.95, 96.07, 295.15, 94.89, 291.33, 94.64, + 287.61, 95.31, 284.11, 96.89, 281.8, 98.52, 279.7, 100.54, + 277.81, 102.91, 275.86, 106.15, 273.2, 112.94, 271.66, 120.41, + 271.11, 126.72, 271.03, 133.73, 272.32, 158.32, + ), + ), + ( + "#ECEAE9", + ( + 142.5, 408.93, 144.93, 412.86, 148.33, 416.82, 151.62, 419.58, + 155.73, 421.94, 159.96, 423.33, 164.11, 423.69, 168.0, 423.04, + 171.46, 421.41, 173.61, 419.69, 175.81, 417.09, 177.3, 414.53, + 178.71, 411.07, 180.34, 403.92, 181.9, 389.45, 182.76, 384.3, + 184.38, 379.06, 186.6, 375.03, 188.42, 372.84, 190.56, 370.93, + 193.02, 369.3, 196.36, 367.72, 203.33, 365.93, 207.41, 365.55, + 211.54, 365.59, 218.2, 366.61, 224.14, 368.79, 226.71, 370.32, + 228.97, 372.13, 232.2, 376.09, 234.21, 380.29, 235.51, 385.06, + 237.68, 403.4, 239.06, 409.98, 241.43, 415.72, 243.06, 418.13, + 244.99, 420.16, 247.7, 422.03, 250.76, 423.22, 254.12, 423.7, + 257.08, 423.52, 260.7, 422.61, 263.71, 421.29, 267.19, 419.06, + 269.9, 416.7, 273.71, 412.09, 276.7, 406.63, 278.73, 400.57, + 279.77, 394.13, 279.87, 387.57, 279.19, 381.08, 277.76, 374.06, + 273.42, 357.39, 272.7, 353.01, 272.43, 348.73, 272.65, 344.45, + 273.45, 339.45, 277.62, 323.51, 278.95, 317.31, 279.71, 311.68, + 279.93, 306.77, 279.2, 298.62, 277.23, 291.66, 274.04, 285.39, + 269.78, 280.17, 267.06, 277.83, 263.57, 275.63, 260.56, 274.33, + 256.94, 273.46, 253.99, 273.3, 250.64, 273.8, 248.07, 274.77, + 245.32, 276.56, 243.34, 278.53, 241.66, 280.88, 239.2, 286.54, + 237.66, 293.75, 235.48, 312.08, 233.95, 317.39, 231.82, 321.5, + 230.08, 323.74, 228.0, 325.7, 225.6, 327.39, 222.9, 328.79, + 216.76, 330.71, 209.32, 331.48, 201.85, 330.81, 198.02, 329.85, + 195.07, 328.73, 192.39, 327.32, 190.0, 325.62, 187.94, 323.64, + 186.21, 321.39, 184.11, 317.26, 182.6, 311.93, 180.42, 293.59, + 179.04, 287.01, 177.76, 283.44, 176.37, 280.76, 174.68, 278.43, + 172.69, 276.48, 169.92, 274.72, 167.34, 273.77, 163.98, 273.3, + 161.03, 273.48, 157.4, 274.38, 154.4, 275.7, 150.92, 277.93, + 148.21, 280.29, 143.97, 285.54, 141.1, 291.09, 139.19, 297.22, + 138.23, 304.49, 138.34, 311.05, 139.18, 317.5, 144.55, 338.96, + 145.64, 347.04, 145.57, 351.31, 144.91, 356.27, 139.77, 376.54, + 138.77, 382.07, 138.23, 387.76, 138.29, 393.51, 139.06, 399.17, + 140.59, 404.59, + ), + ), +) +DARK = {"surface": "#2b2624", "border": "#463e3a", "text": "#eceae9"} +LIGHT = {"surface": "#fcfbfb", "border": "#e0dad7", "text": "#211d1b"} +FOCUS = "#b8862e" +RADIUS = 12 +SPACE_SM = 8 +SPACE_MD = 16 +TEXT_BODY = 16 diff --git a/kuhy_credit/kuhy_credit/terminal.py b/kuhy_credit/kuhy_credit/terminal.py new file mode 100644 index 0000000..19871d6 --- /dev/null +++ b/kuhy_credit/kuhy_credit/terminal.py @@ -0,0 +1,9 @@ +"""``kuhy-credit``: print the one-line credit. Opens nothing.""" + +from kuhy_credit import credit_line + + +def main() -> int: + """Print the credit line; returns the exit code.""" + print(credit_line()) + return 0 diff --git a/kuhy_credit/pyproject.toml b/kuhy_credit/pyproject.toml new file mode 100644 index 0000000..7399e12 --- /dev/null +++ b/kuhy_credit/pyproject.toml @@ -0,0 +1,59 @@ +[build-system] +requires = ["setuptools>=61"] +build-backend = "setuptools.build_meta" + +[project] +name = "kuhy-credit" +version = "0.1.0" +description = "The shared 'Created by kuhy' logo credit: Tkinter widget and terminal line" +requires-python = ">=3.14" +dependencies = [] # pure stdlib: tkinter and webbrowser ship with Python + +[project.scripts] +kuhy-credit = "kuhy_credit.terminal:main" + +[tool.setuptools.packages.find] +include = ["kuhy_credit*"] +exclude = ["kuhy_credit.tests*"] + +[tool.ruff] +target-version = "py314" +line-length = 100 +extend-exclude = ["web", "flutter", "godot"] + +[tool.ruff.lint] +select = ["ALL"] +ignore = ["D203", "D213", "COM812", "ISC001", "S603", "S607", "CPY001"] + +[tool.ruff.lint.per-file-ignores] +"tests/*.py" = ["ARG", "D", "PLC0415", "PLR2004", "S101", "SLF001", "E501"] +"kuhy_credit/_data.py" = ["E501"] +# The generator and the terminal helper are CLIs: printing is their output. +"generator/generate.py" = ["T201"] +"kuhy_credit/terminal.py" = ["T201"] + +[tool.ruff.lint.pydocstyle] +convention = "google" + +[tool.pytest.ini_options] +testpaths = ["tests"] +pythonpath = ["."] +addopts = [ + "--strict-markers", + "--strict-config", + "-ra", + "--cov=kuhy_credit", + "--cov=generator", + "--cov-branch", + "--cov-report=term-missing", +] +filterwarnings = ["error"] + +[tool.coverage.run] +branch = true +omit = ["*/tests/*"] + +[tool.coverage.report] +fail_under = 100 +show_missing = true +exclude_lines = ["pragma: no cover", 'if __name__ == "__main__":'] diff --git a/kuhy_credit/terminal/kuhy-credit.sh b/kuhy_credit/terminal/kuhy-credit.sh new file mode 100755 index 0000000..d63c49c --- /dev/null +++ b/kuhy_credit/terminal/kuhy-credit.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# Prints the one-line kuhy credit and opens nothing (generated by kuhy_credit/generator/generate.py; DO NOT EDIT). +set -euo pipefail +printf '%s %s\n' 'Created by kuhy' https://kuhy.duckdns.org diff --git a/kuhy_credit/tests/__init__.py b/kuhy_credit/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kuhy_credit/tests/test_generator.py b/kuhy_credit/tests/test_generator.py new file mode 100644 index 0000000..f3643e2 --- /dev/null +++ b/kuhy_credit/tests/test_generator.py @@ -0,0 +1,129 @@ +"""Generator: SVG parsing, token parsing, emitters and the drift check.""" + +from __future__ import annotations + +import json +import shutil +from pathlib import Path + +import pytest + +from generator import generate, svg, tokens + +CREDIT_DIR = Path(__file__).resolve().parents[1] +REPO_ROOT = CREDIT_DIR.parent + + +def test_logo_parses_into_disjoint_polygons() -> None: + logo = svg.parse_logo((REPO_ROOT / "unified-design-system/logo/final/kuhy.svg").read_text()) + assert logo.size == 512 + assert logo.field == "#211D1B" + assert [s.fill for s in logo.shapes] == ["#B8862E"] * 2 + ["#ECEAE9"] * 2 + assert all(len(s.points) >= 3 for s in logo.shapes) + + +def test_overlapping_subpaths_are_rejected() -> None: + doc = ( + '' + '' + ) + with pytest.raises(ValueError, match="overlap"): + svg.parse_logo(doc) + + +def test_unsupported_path_command_is_rejected() -> None: + doc = ( + '' + '' + ) + with pytest.raises(ValueError, match="unsupported"): + svg.parse_logo(doc) + + +def test_missing_field_is_rejected() -> None: + with pytest.raises(ValueError, match="field"): + svg.parse_logo('') + + +def test_tokens_read_dark_and_light_from_css() -> None: + tok = tokens.parse_tokens((REPO_ROOT / "web_ui/src/tokens.css").read_text()) + assert tok.dark.surface == "#2b2624" + assert tok.light.surface == "#fcfbfb" + assert tok.dark.text == "#eceae9" + assert tok.light.text == "#211d1b" + assert tok.focus == "#b8862e" + assert (tok.radius, tok.space_sm, tok.space_md, tok.text_body) == (12, 8, 16, 16) + + +def test_missing_token_is_rejected() -> None: + with pytest.raises(ValueError, match="--surface-1"): + tokens.parse_tokens(":root { --bg: #000000; }") + + +def test_every_generated_file_matches_the_sources() -> None: + assert generate.drift(CREDIT_DIR) == [] + + +def test_main_check_passes_on_a_clean_tree(capsys: pytest.CaptureFixture[str]) -> None: + assert generate.main(["--check"]) == 0 + assert "in sync" in capsys.readouterr().out + + +@pytest.fixture +def copy(tmp_path: Path) -> Path: + """A throwaway copy of the repo bits the generator reads and writes.""" + root = tmp_path / "repo" + for rel in ("unified-design-system/logo/final", "web_ui/src"): + (root / rel).mkdir(parents=True) + shutil.copy( + REPO_ROOT / "unified-design-system/logo/final/kuhy.svg", + root / "unified-design-system/logo/final", + ) + shutil.copy(REPO_ROOT / "web_ui/src/tokens.css", root / "web_ui/src") + (root / "kuhy_credit").mkdir() + shutil.copy(CREDIT_DIR / "credit.json", root / "kuhy_credit") + return root / "kuhy_credit" + + +def test_write_then_check_round_trips(copy: Path) -> None: + assert {d.stack for d in generate.drift(copy)} == set(generate.STACKS) + generate.write(copy) + assert generate.drift(copy) == [] + + +@pytest.mark.parametrize("stack", sorted(generate.STACKS)) +def test_editing_one_stack_names_that_stack( + copy: Path, stack: str, capsys: pytest.CaptureFixture[str] +) -> None: + generate.write(copy) + target = copy / generate.STACKS[stack] + target.write_text(target.read_text().replace("https://kuhy.duckdns.org", "https://example.org")) + assert [d.stack for d in generate.drift(copy)] == [stack] + assert generate.main(["--check", "--dir", str(copy)]) == 1 + assert stack in capsys.readouterr().out + + +def test_changing_the_shared_url_drifts_every_stack(copy: Path) -> None: + generate.write(copy) + data = json.loads((copy / "credit.json").read_text()) + data["url"] = "https://example.org" + (copy / "credit.json").write_text(json.dumps(data)) + assert {d.stack for d in generate.drift(copy)} == set(generate.STACKS) + + +def test_main_writes_without_check(copy: Path, capsys: pytest.CaptureFixture[str]) -> None: + assert generate.main(["--dir", str(copy)]) == 0 + assert "wrote" in capsys.readouterr().out + assert generate.drift(copy) == [] + + +def test_css_without_root_is_rejected() -> None: + with pytest.raises(ValueError, match="--surface-1"): + tokens.parse_tokens("") + + +def test_whole_numbers_keep_a_decimal_point() -> None: + from generator import emit + + assert emit._num(12.0) == "12.0" + assert emit._num(12.5) == "12.5" diff --git a/kuhy_credit/tests/test_terminal.py b/kuhy_credit/tests/test_terminal.py new file mode 100644 index 0000000..64605a1 --- /dev/null +++ b/kuhy_credit/tests/test_terminal.py @@ -0,0 +1,25 @@ +import subprocess +from pathlib import Path + +import pytest + +from kuhy_credit import TEXT, URL, credit_line, terminal + +CREDIT_DIR = Path(__file__).resolve().parents[1] + + +def test_credit_line_is_text_then_url() -> None: + assert credit_line() == "Created by kuhy https://kuhy.duckdns.org" + assert (TEXT, URL) == ("Created by kuhy", "https://kuhy.duckdns.org") + + +def test_main_prints_one_line(capsys: pytest.CaptureFixture[str]) -> None: + assert terminal.main() == 0 + assert capsys.readouterr().out == "Created by kuhy https://kuhy.duckdns.org\n" + + +def test_shell_helper_prints_the_same_line() -> None: + out = subprocess.run( + [str(CREDIT_DIR / "terminal/kuhy-credit.sh")], check=True, capture_output=True, text=True + ).stdout + assert out == credit_line() + "\n" diff --git a/kuhy_credit/web/src/credit-data.js b/kuhy_credit/web/src/credit-data.js new file mode 100644 index 0000000..0d98f52 --- /dev/null +++ b/kuhy_credit/web/src/credit-data.js @@ -0,0 +1,115 @@ +// The shared credit data (generated by kuhy_credit/generator/generate.py; DO NOT EDIT). +export const CREDIT_URL = "https://kuhy.duckdns.org"; +export const CREDIT_TEXT = "Created by kuhy"; +export const LOGO_SVG = + "\n\n\n\n\n"; +export const TOKENS = { + dark: { surface: "#2b2624", border: "#463e3a", text: "#eceae9" }, + light: { surface: "#fcfbfb", border: "#e0dad7", text: "#211d1b" }, + focus: "#b8862e", + radius: 12, + spaceSm: 8, + spaceMd: 16, + textBody: 16, +};