Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Extract shared demo script utilities
Maximilian Roos1d33d3bb8686
diff --git a/docs/demos/shared/__init__.py b/docs/demos/shared/__init__.pyindex a0fb39b59..1d24adf8a 100644--- a/docs/demos/shared/__init__.py+++ b/docs/demos/shared/__init__.py@@ -17,6 +17,8 @@ from .lib import (check_dependencies,setup_demo_output,build_shell_env,+ clean_ansi_output,+ run_fish_script,record_all_themes,)from .themes import THEMES, format_theme_for_vhs@@ -40,5 +42,7 @@ __all__ = ["check_dependencies","setup_demo_output","build_shell_env",+ "clean_ansi_output",+ "run_fish_script","record_all_themes",]diff --git a/docs/demos/shared/lib.py b/docs/demos/shared/lib.pyindex 99fe70044..5e99577c4 100644--- a/docs/demos/shared/lib.py+++ b/docs/demos/shared/lib.py@@ -1,6 +1,7 @@"""Shared infrastructure for demo recording scripts."""import os+import reimport shutilimport subprocessfrom dataclasses import dataclass@@ -399,6 +400,36 @@ def build_shell_env(demo_env: "DemoEnv", repo_root: Path, extra: dict = None) ->return env+def clean_ansi_output(text: str) -> str:+ """Strip ANSI escape codes and control characters from text."""+ # Strip ANSI escape sequences+ clean = re.sub(r"\x1B\[[0-9;?]*[A-Za-z]", "", text)+ # Strip control characters (except newline, tab, carriage return)+ clean = re.sub(r"[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]", "", clean)+ return clean+++def run_fish_script(+ demo_env: "DemoEnv",+ script: str,+ env: dict,+ cwd: Path = None,+) -> str:+ """Run a fish script and return cleaned output.++ Automatically prepends shell init and cleans ANSI from output.+ """+ full_script = "wt config shell init fish | source\n" + script+ result = subprocess.run(+ ["fish", "-c", full_script],+ cwd=cwd or demo_env.repo,+ env=env,+ capture_output=True,+ text=True,+ )+ return clean_ansi_output(result.stdout + result.stderr)++def record_all_themes(demo_env: "DemoEnv",tape_template: Path,diff --git a/docs/demos/wt-core/build b/docs/demos/wt-core/buildindex f6909f89c..9b3154ed8 100755--- a/docs/demos/wt-core/build+++ b/docs/demos/wt-core/build@@ -10,8 +10,6 @@ This demo shows the core workflow with hooks:6. wt remove - remove worktree with pre-remove hook"""-import re-import subprocessimport sysfrom pathlib import Path@@ -22,7 +20,7 @@ sys.path.insert(0, str(DEMOS_DIR))from shared import (DemoEnv, git, prepare_demo_repo,- check_dependencies, setup_demo_output, build_shell_env, record_all_themes,+ check_dependencies, setup_demo_output, build_shell_env, run_fish_script, record_all_themes,)REPO_ROOT = DEMOS_DIR.parent.parent@@ -100,24 +98,9 @@ def record_text(demo_env: DemoEnv):]env = build_shell_env(demo_env, REPO_ROOT)-- # Run commands and capture output using fish with shell init- script = "wt config shell init fish | source\n"- for cmd in commands:- script += f"echo '$ {cmd}'\n{cmd}\necho ''\n"-- result = subprocess.run(- ["fish", "-c", script],- cwd=demo_env.repo, env=env,- capture_output=True, text=True- )- output = result.stdout + result.stderr-- # Clean output- clean = re.sub(r"\x1B\[[0-9;?]*[A-Za-z]", "", output) # Strip ANSI- clean = re.sub(r"[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]", "", clean) # Strip control chars-- (OUT_DIR / "run.txt").write_text(clean)+ script = "\n".join(f"echo '$ {cmd}'\n{cmd}\necho ''" for cmd in commands)+ output = run_fish_script(demo_env, script, env)+ (OUT_DIR / "run.txt").write_text(output)def main():diff --git a/docs/demos/wt-merge/build b/docs/demos/wt-merge/buildindex 740a69834..ec52d0a03 100755--- a/docs/demos/wt-merge/build+++ b/docs/demos/wt-merge/build@@ -1,8 +1,6 @@#!/usr/bin/env python3"""Build script for wt-merge demo GIF."""-import re-import subprocessimport sysfrom pathlib import Path@@ -13,7 +11,7 @@ sys.path.insert(0, str(DEMOS_DIR))from shared import (DemoEnv, prepare_demo_repo,- check_dependencies, setup_demo_output, build_shell_env, record_all_themes,+ check_dependencies, setup_demo_output, build_shell_env, run_fish_script, record_all_themes,)REPO_ROOT = DEMOS_DIR.parent.parent@@ -60,26 +58,16 @@ def record_text(demo_env: DemoEnv):"NEXTEST_NO_FAIL_FAST": "1",})- # Run commands and capture output using fish with shell init- script = "wt config shell init fish | source\n"+ # Build script with delays after merge commands+ script_lines = []for cmd in commands:- script += f'{cmd}\n'+ script_lines.append(cmd)if cmd.startswith("wt merge"):- script += 'sleep 2\n'+ script_lines.append("sleep 2")- result = subprocess.run(- ["fish", "-c", script],- cwd=demo_env.repo, env=env,- capture_output=True, text=True- )- output = result.stdout + result.stderr-- # Clean output- clean = re.sub(r"\x1B\[[0-9;?]*[A-Za-z]", "", output) # Strip ANSI- clean = re.sub(r"[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]", "", clean) # Strip control chars- clean = clean.replace("^D", "")-- (OUT_DIR / "run.txt").write_text(clean)+ output = run_fish_script(demo_env, "\n".join(script_lines), env)+ output = output.replace("^D", "") # Clean EOF marker+ (OUT_DIR / "run.txt").write_text(output)def main():