From a7dba833cc01b390bc882c8169496b756feb08aa Mon Sep 17 00:00:00 2001 From: Caleb Foust Date: Fri, 12 Jan 2024 17:22:12 +0800 Subject: [PATCH] feat: generate casts in storybook --- docs/src/quick-start.md | 2 ++ docs/storybook.py | 25 +++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/docs/src/quick-start.md b/docs/src/quick-start.md index 1428eeeb..51de1e07 100644 --- a/docs/src/quick-start.md +++ b/docs/src/quick-start.md @@ -22,6 +22,8 @@ If your terminal is wider than 80 columns, you'll notice that the pane does not All actions in `cy`, such as creating panes and switching between them, are triggered by sequences of keys. +{{story cast cy/viewport}} + Here are a few you can try: 1. To make the pane fill the entire viewport, type `ctrl+a` `g`. (Repeat to center it again.) diff --git a/docs/storybook.py b/docs/storybook.py index 77e23ace..eab6c504 100644 --- a/docs/storybook.py +++ b/docs/storybook.py @@ -11,10 +11,10 @@ import sys from pathlib import Path -STORY_REGEX = re.compile("{{story ((\w+).)?(png|gif) (.+)}}") +STORY_REGEX = re.compile("{{story ((\w+).)?(png|gif|cast) (.+)}}") COMMON = """ -Set FontSize 15 +Set FontSize 18 Set Width 1300 Set Height 650 Set Padding 0 @@ -57,14 +57,20 @@ def transform_chapter(chapter): h.update(command.encode('utf-8')) filename = h.hexdigest()[:12] + original = filename + filename += "." + type_ filename = "images/" + filename + replacement = f"![{command}]({filename})" + if filename.endswith("cast"): + replacement = f"
" + replace.append( ( ref.start(0), ref.end(0), - f"![{command}]({filename})", + replacement, ) ) @@ -107,7 +113,7 @@ def transform_chapter(chapter): Enter Sleep 500ms Show -Sleep 8s +Sleep 15s """ elif filename.endswith(".png"): script = f""" @@ -120,6 +126,12 @@ def transform_chapter(chapter): Sleep 1s Screenshot {filename} """ + elif filename.endswith(".cast"): + subprocess.check_call( + f"./storybook --cast {filename} -s {command}", + shell=True + ) + continue tape = ( filename.replace("png", "tape") @@ -133,14 +145,11 @@ def transform_chapter(chapter): vhs = "./vhs" while not os.path.exists(filename): - code = subprocess.call( + subprocess.check_call( f"{vhs} -q {tape}", shell=True ) - if code != 0: - raise Exception(code) - os.unlink(tape) if not os.path.exists(filename): raise Exception(f"failed to produce {filename}")