diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-20 16:25:53 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-20 16:25:53 -0400 |
| commit | 28b4d1cf86b9355a0db6e00f4c599ed02cf4f2e7 (patch) | |
| tree | 6724275f3e7f46081ad424f04c821559ffa2f19e /scripts/theme-studio | |
| parent | 9a52370b47c0fe73b4fb7d6f77aabe70a96f192d (diff) | |
| download | dotemacs-28b4d1cf86b9355a0db6e00f4c599ed02cf4f2e7.tar.gz dotemacs-28b4d1cf86b9355a0db6e00f4c599ed02cf4f2e7.zip | |
refactor(theme-studio): unify the two condition_matches clause checkers
condition_matches encoded the same four display-condition rules twice -- once
for the dict spec shape, once for the list-of-clauses shape. Normalize both to a
single {key: values} mapping and run the rules once in _condition_clauses_pass.
Verified byte-identical over 31 representative conditions (dict, list, scalar,
and malformed). The pre-existing Pyright complaints in choose_gui_light are
unrelated and untouched.
Diffstat (limited to 'scripts/theme-studio')
| -rw-r--r-- | scripts/theme-studio/capture-default-faces.py | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/scripts/theme-studio/capture-default-faces.py b/scripts/theme-studio/capture-default-faces.py index 8c8fd6679..a5214fd5a 100644 --- a/scripts/theme-studio/capture-default-faces.py +++ b/scripts/theme-studio/capture-default-faces.py @@ -163,47 +163,45 @@ def normalize_value(value: object) -> object: return value +def _condition_clauses_pass(clauses: dict) -> bool: + """Apply the four display-condition rules to a {key: values} mapping. + Returns False when any present clause excludes the GUI-light target.""" + if "class" in clauses: + vals = clauses["class"] + if "color" not in vals and "grayscale" not in vals: + return False + if "min-colors" in clauses: + vals = clauses["min-colors"] + if vals and isinstance(vals[0], int) and vals[0] > 16777216: + return False + if "background" in clauses: + vals = clauses["background"] + if vals and "light" not in vals: + return False + if "type" in clauses: + if "tty" in clauses["type"]: + return False + return True + + def condition_matches(condition: object) -> bool: if condition in (True, "t", None): return True if condition == "default": return False + # Normalize the two display-spec shapes -- a {key: values} dict, or a list of + # [key, *values] clauses -- to one {key: values} mapping, then run the four + # rules once (see `_condition_clauses_pass'). if isinstance(condition, dict): - if "class" in condition: - vals = condition["class"] or [] - if "color" not in vals and "grayscale" not in vals: - return False - if "min-colors" in condition: - vals = condition["min-colors"] or [] - if vals and isinstance(vals[0], int) and vals[0] > 16777216: - return False - if "background" in condition: - vals = condition["background"] or [] - if vals and "light" not in vals: - return False - if "type" in condition and "tty" in (condition["type"] or []): - return False - return True + clauses = {k: (condition[k] or []) for k in condition} + return _condition_clauses_pass(clauses) if not isinstance(condition, list): return False + clauses = {} for clause in condition: - if not isinstance(clause, list) or not clause: - continue - key = clause[0] - vals = clause[1:] - if key == "class": - if "color" not in vals and "grayscale" not in vals: - return False - elif key == "min-colors": - if vals and isinstance(vals[0], int) and vals[0] > 16777216: - return False - elif key == "background": - if vals and "light" not in vals: - return False - elif key == "type": - if "tty" in vals: - return False - return True + if isinstance(clause, list) and clause: + clauses[clause[0]] = clause[1:] + return _condition_clauses_pass(clauses) def choose_gui_light(default_spec: object) -> dict[str, object]: |
