Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions assets/demo/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,18 @@ def art(step: list[str]) -> list[str]:
return out


def timing(typed: str, count: int, questions: int) -> str:
"""CSS for when each step shows: the opening waits for a reader, the report streams."""
typing = 0.03 * len(typed)
rules = [
f".term.play .typed {{ animation: type {typing:.1f}s steps({len(typed)}) 0.3s both; }}",
f"@keyframes type {{ from {{ width: 0; }} to {{ width: {len(typed)}ch; }} }}",
]
t = typing + 0.7
def timing(typed: list[str], count: int, questions: int) -> str:
"""CSS for when each step shows: the command types line by line, the opening waits for a
reader, the report streams."""
rules, start = [], 0.3
for n, line in enumerate(typed, 1):
typing = 0.03 * len(line)
rules += [
f".term.play .typed:nth-of-type({n}) {{ animation: type{n} {typing:.1f}s steps({len(line)}) {start:.1f}s both; }}",
f"@keyframes type{n} {{ from {{ width: 0; }} to {{ width: {len(line)}ch; }} }}",
]
start += typing
t = start + 0.4
for n in range(count):
# The first step is the command line's sibling at nth-child(2).
gap = 1.4 if n < questions else 0
Expand All @@ -229,6 +233,18 @@ def timing(typed: str, count: int, questions: int) -> str:
return "\n".join(rules) + "\n"


def wrap(command: list[str]) -> list[str]:
"""The command as shell lines that fit the terminal: each continued with a backslash, after
the first's "$ " prompt or a two-space indent."""
lines = [command[0]]
for arg in command[1:]:
if len(lines[-1]) + len(arg) + len(" \\") + 3 <= COLUMNS:
lines[-1] += " " + arg
else:
lines.append(arg)
return [line + " \\" for line in lines[:-1]] + lines[-1:]


def plain_lines(transcript: str) -> list[str]:
"""The run's lines without colors, each as its last overwrite left it."""
return [SGR.sub("", line.split("\r")[-1]) for line in transcript.replace("\r\n", "\n").split("\n")]
Expand Down Expand Up @@ -539,8 +555,8 @@ def main() -> None:
sys.exit("pass one --since YYYY-MM-DD, so the usage boxes can name their window")
since = date.fromisoformat(starts[0])
billing = [f"--billing={profile}={answer}" for profile, answer in answers.items()]
# The page shows the command as run, answers included.
typed = " ".join(command + billing)
# The page shows the command as run, answers included, wrapped to fit the terminal.
typed = wrap(command + billing)
# Doctor dates its window in UTC, ending when it runs.
now = datetime.now(timezone.utc)
transcript = run(command + billing, COLUMNS)
Expand All @@ -552,7 +568,8 @@ def main() -> None:
run_steps, questions = steps(transcript)
figures, bars = results(transcript, plan, api, {p for p, a in answers.items() if a == "api"}, since, now)
body = "".join(f'<span class="step">{chr(10).join(s)}\n</span>' for s in run_steps)
fragment = f'<pre class="screen"><code><span class="cmdline">$ <span class="typed">{typed}</span>\n</span>{body}</code></pre>'
cmdline = "\n ".join(f'<span class="typed">{html.escape(line)}</span>' for line in typed)
fragment = f'<pre class="screen"><code><span class="cmdline">$ {cmdline}\n</span>{body}</code></pre>'
replace(site / "index.html", "<!-- doctor -->", "<!-- /doctor -->", fragment)
replace(site / "index.html", "<!-- results -->", "<!-- /results -->", figures)
replace(
Expand Down
22 changes: 0 additions & 22 deletions quest/m2/agent-ergonomics/site-billing-refresh.md

This file was deleted.

Loading
Loading