Finish the wonderland: System told truthfully, in eight tabs instead of ten
Claude-Session: https://claude.ai/code/session_01Ms2FbjQy31TVf3CEvQhGM8
This commit is contained in:
@@ -58,6 +58,17 @@ MACHINE_SPECIFIC = {
|
||||
# machine where the file exists. Carried, then checked on arrival.
|
||||
PATH_VALUED = {"wallpaperPath", "wallpaperSlideshowPaths"}
|
||||
|
||||
# A preview is something a person reads before pressing Import. Past a screen or
|
||||
# two it stops being read and starts being scrolled, so the list is capped and
|
||||
# the count says how many there really are -- the import itself still applies
|
||||
# every change, because the cap is about what is shown, not what is done.
|
||||
CHANGE_LIMIT = 40
|
||||
|
||||
# Long enough for a wallpaper path or a theme name, short enough that no single
|
||||
# row can push the rest off the screen. Values are rendered for display here,
|
||||
# never re-parsed, so a truncated one costs nothing.
|
||||
VALUE_LIMIT = 120
|
||||
|
||||
|
||||
class BoundaryError(RuntimeError):
|
||||
"""A user-visible validation or file failure."""
|
||||
@@ -158,6 +169,29 @@ def fits(entry: dict, value) -> str:
|
||||
return ""
|
||||
|
||||
|
||||
def render(value) -> str:
|
||||
"""One setting's value as a line of text a person can compare.
|
||||
|
||||
Rendered here rather than in the page because the page would have to know
|
||||
the difference between a JSON setting and a scalar one to do it, and that
|
||||
knowledge already lives in the schema on this side. A value with no entry
|
||||
at all is "not set" rather than "null": the two look identical in JSON and
|
||||
mean quite different things to somebody reading a diff.
|
||||
"""
|
||||
if value is None:
|
||||
return "not set"
|
||||
if isinstance(value, bool):
|
||||
return "on" if value else "off"
|
||||
if isinstance(value, (int, float)):
|
||||
return f"{value:g}" if isinstance(value, float) else str(value)
|
||||
if isinstance(value, str):
|
||||
text = value
|
||||
else:
|
||||
text = json.dumps(value, separators=(",", ":"), sort_keys=True)
|
||||
text = " ".join(text.split())
|
||||
return text if len(text) <= VALUE_LIMIT else text[:VALUE_LIMIT - 1] + "…"
|
||||
|
||||
|
||||
def exportable() -> tuple[dict, list[dict]]:
|
||||
known = schema()
|
||||
current = stored()
|
||||
@@ -248,14 +282,17 @@ def plan(path: str) -> dict:
|
||||
continue
|
||||
apply[key] = value
|
||||
changes.append({"key": key,
|
||||
"from": current.get(key, None),
|
||||
"to": value})
|
||||
"from": render(current.get(key)),
|
||||
"to": render(value)})
|
||||
|
||||
return {
|
||||
"path": str(Path(path).expanduser()),
|
||||
"exportedFrom": str(bundle.get("exportedFrom", "")),
|
||||
"exportedAt": int(bundle.get("exportedAt", 0)),
|
||||
"changes": changes,
|
||||
"changes": changes[:CHANGE_LIMIT],
|
||||
# What the list would have held uncapped, so the page can say "and 12
|
||||
# more" rather than quietly showing forty of fifty-two.
|
||||
"changeCount": len(changes),
|
||||
"skipped": skipped,
|
||||
"apply": apply,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user