From 336b52bc660e3556c055cdac1f96b21ac89656ed Mon Sep 17 00:00:00 2001 From: Narrator Date: Thu, 29 Oct 2026 19:32:41 +0100 Subject: [PATCH] Screenshot scripts find their fonts on any distribution render.py and social.py had Arch's font paths built in, so on Debian or Ubuntu 'shots.sh all' built and started everything and then failed on the fonts. They now look the fonts up by name under /usr/share/fonts (or FONT_DIR). The README lists fontTools and the fonts, and mentions 'make test'. shots.sh's shows() no longer pipes into grep -q, which under pipefail can miss a match when tmux is still writing. Co-Authored-By: Claude Opus 5.5 --- README.md | 4 +++- scripts/screenshots/render.py | 19 +++++++++++++++---- scripts/screenshots/shots.sh | 4 +++- scripts/screenshots/social.py | 15 ++++++++++++--- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1579c45..d364b43 100644 --- a/README.md +++ b/README.md @@ -381,12 +381,14 @@ and build with `go build -mod=vendor`. The resulting binary is static and has no runtime dependencies besides `git`, `ssh` and Ansible (which interzone can install itself from a PyPI mirror). +`make test` runs what CI runs: gofmt, `go vet` and `go test -race ./...`. `go test ./...` includes layout tests that draw the main screens at phone (46×40) and desktop (120×36) size and compare them with `internal/ui/testdata/layout`; after an intended change, accept the new drawings with `go test ./internal/ui -run Layout -update`. The README's screenshots are retaken with `scripts/screenshots/shots.sh all` (tmux, Python -with Pillow), about 15 seconds, against a demo server that doesn't exist; +with Pillow and fontTools, and the DejaVu and Noto symbol, math and colour +emoji fonts), about 15 seconds, against a demo server that doesn't exist; `python3 scripts/screenshots/social.py docs/social-preview.png` redraws the link preview from them. diff --git a/scripts/screenshots/render.py b/scripts/screenshots/render.py index 61b3693..8c6c022 100644 --- a/scripts/screenshots/render.py +++ b/scripts/screenshots/render.py @@ -6,14 +6,25 @@ # Puts already rendered windows side by side (docs/screenshots/phone.png). # # Needs Pillow, fontTools and the DejaVu and Noto symbol fonts. -import re, sys, unicodedata +import glob, os, re, sys, unicodedata from PIL import Image, ImageDraw, ImageFont from fontTools.ttLib import TTFont +def font(name): + """Finds a font file by name wherever the distribution keeps it + (/usr/share/fonts/TTF on Arch, .../truetype/dejavu on Debian), or + under FONT_DIR.""" + roots = [os.environ.get("FONT_DIR", ""), "/usr/share/fonts", os.path.expanduser("~/.local/share/fonts")] + for root in filter(None, roots): + hits = glob.glob(os.path.join(root, "**", name), recursive=True) + if hits: + return sorted(hits)[0] + sys.exit(f"render.py: can't find the font {name}; install it or set FONT_DIR") + SIZE = 26 -FONTS = ["/usr/share/fonts/TTF/DejaVuSansMono.ttf", "/usr/share/fonts/TTF/DejaVuSansMono-Bold.ttf"] -FALLBACK = ["/usr/share/fonts/TTF/DejaVuSans.ttf", "/usr/share/fonts/noto/NotoSansSymbols2-Regular.ttf", "/usr/share/fonts/noto/NotoSansMath-Regular.ttf"] -EMOJI = "/usr/share/fonts/noto/NotoColorEmoji.ttf" # a bitmap font: drawn at 109 px, then scaled +FONTS = [font("DejaVuSansMono.ttf"), font("DejaVuSansMono-Bold.ttf")] +FALLBACK = [font("DejaVuSans.ttf"), font("NotoSansSymbols2-Regular.ttf"), font("NotoSansMath-Regular.ttf")] +EMOJI = font("NotoColorEmoji.ttf") # a bitmap font: drawn at 109 px, then scaled BG, FG = (21, 19, 30), (220, 216, 235) reg = ImageFont.truetype(FONTS[0], SIZE) diff --git a/scripts/screenshots/shots.sh b/scripts/screenshots/shots.sh index 2c716ca..7da7dbd 100755 --- a/scripts/screenshots/shots.sh +++ b/scripts/screenshots/shots.sh @@ -88,7 +88,9 @@ stop() { screen() { tmux capture-pane -t shot -p; } -shows() { screen | grep -qF -- "$1"; } +# Not "screen | grep -q": grep stops at the first match and, under +# pipefail, tmux writing the rest can make it look like no match. +shows() { [[ $(screen) == *"$1"* ]]; } # waitfor waits up to 10 s for text to appear on the screen. waitfor() { diff --git a/scripts/screenshots/social.py b/scripts/screenshots/social.py index 5e6dcfc..657887a 100644 --- a/scripts/screenshots/social.py +++ b/scripts/screenshots/social.py @@ -1,14 +1,23 @@ # social.py OUT.png # The 1280×640 link preview (GitHub's "Social preview", og:image): the # name and pitch on the left, the Server screenshot on the right. -import sys +import glob, os, sys from PIL import Image, ImageDraw, ImageFilter, ImageFont W, H = 1280, 640 BG, FG, MUTED = (21, 19, 30), (220, 216, 235), (140, 134, 160) PURPLE, PINK, YELLOW = (157, 124, 252), (220, 122, 202), (250, 193, 101) -MONO = "/usr/share/fonts/TTF/DejaVuSansMono.ttf" -MONO_B = "/usr/share/fonts/TTF/DejaVuSansMono-Bold.ttf" +def font(name): + """Finds a font file by name, as render.py does.""" + roots = [os.environ.get("FONT_DIR", ""), "/usr/share/fonts", os.path.expanduser("~/.local/share/fonts")] + for root in filter(None, roots): + hits = glob.glob(os.path.join(root, "**", name), recursive=True) + if hits: + return sorted(hits)[0] + sys.exit(f"social.py: can't find the font {name}; install it or set FONT_DIR") + +MONO = font("DejaVuSansMono.ttf") +MONO_B = font("DejaVuSansMono-Bold.ttf") img = Image.new("RGB", (W, H), BG)