#!/bin/python3 from __future__ import annotations import shutil def ask_int(prompt: str) -> int: """Prompt user for a positive integer.""" while True: try: value = int(input(prompt).strip()) if value <= 0: print("Please enter a positive integer.") continue return value except ValueError: print("Please enter a valid integer.") def ask_float(prompt: str) -> float: """Prompt user for a positive float.""" while True: try: value = float(input(prompt).strip()) if value <= 0: print("Please enter a positive number.") continue return value except ValueError: print("Please enter a valid number.") def ask_optional_float(prompt: str) -> float | None: """Prompt user for an optional positive float.""" while True: raw = input(f"{prompt} [Enter = keep default]: ").strip().replace(",", ".") if not raw: return None try: value = float(raw) except ValueError: print("Please enter a number.") continue if value <= 0: print("Value must be greater than 0.") continue return value def ask_yes_no(prompt: str) -> bool: """Prompt the user for a yes/no answer.""" while True: answer = input(prompt).strip().lower() if answer in {"y", "yes"}: return True if answer in {"n", "no"}: return False print("Please enter yes or no. [y/n]") def check_openscad() -> None: if shutil.which("openscad") is None: raise SystemExit( "OpenSCAD was not found in PATH. " "Install OpenSCAD or make sure the 'openscad' command is available." )