Two layers, as the spikes' report settled: 1. `VoelinTheme`, a GPUI global (theme/tokens.rs): the 43 colour tokens of ui/theme.slint for light and dark (generated from the Slint file by a script, then checked by the test below), the backdrop gradient, and `Metrics`: the radii, spacing, type sizes, weights, control and shell sizes and the two durations at a text size factor (font-scale: the sidebar's `264 * max(1, scale)` and the top bar's `max(44, control + 8)` included). 2. gpui-component's `ThemeColor`, written on every change (theme/components.rs): the base of the report's table (background, foreground, border, input, ring, overlay; primary with hover, active and foreground from the client's accent; secondary and muted from surface-2 and its raised steps; gpui-component's "accent", which is a hover background, from surface-3; popover; list, table, sidebar, title and status bar, tabs, switch, slider, scrollbar, link, selection; danger, success, warning and info with a hover and active made by mixing and a text that is white or the window's ink, whichever contrasts more) and the 28 `button_*` fields a theme file would derive from them (without them the buttons keep the default theme's blue). The mixing, the WCAG contrast and `readable` are `Rgba` methods with tests. The window's background is bg-app; the backdrop and bg-rail stay in `VoelinTheme` (gpui-component has no rail, and GPUI's gradient has two stops against Slint's three: the swatch draws the first and the last and says so). The mode (`Choice`: system, light, dark) follows the window's appearance in `system` (`observe_window_appearance` calls `set_system_appearance`; a light or dark choice ignores the window) and sets the platform's window appearance where the platform draws the frame (macOS; a no-op elsewhere). The text size factor rewrites the metrics, the theme's font size (font-body) and radii. theme/slint_parity.rs reads ui/theme.slint at test time (`include_str!`) and compares every declaration of the `Theme` global with tokens.rs by name: the colours (dark and light), every length with the file's own arithmetic (a small evaluator of `*`, `+`, `max()` and token references) at four text sizes, the weights, durations, the font family and the backdrop's stops, and fails on a name on one side only or a declaration kind it does not know. A mutation check (accent, radius-md and the top bar's formula changed in tokens.rs) failed the tests with the names of the tokens, then was reverted. fonts.rs adds the five Inter TTFs of the Slint front end (`include_bytes!`) to GPUI's text system; the theme names the family. build.rs turns the 147 Lucide 1.48 SVGs of crates/voelin-ui/ui/assets/icons into a sorted table of `include_bytes!` (std only, no new dependency) that assets.rs serves as gpui-component's `icons/<name>.svg` before gpui-kit-assets' Lucide 1.43 catalogue (1,830 paths, which answers the rest and, as it does, an error for a path it lacks); a test checks that `mic.svg` is the client's, differs from the catalogue's, and that other icons fall through. Development switches (dev.rs): `VOELIN_OPEN=swatch`, `VOELIN_DEV_THEME= dark|light|system`, `VOELIN_FONT_SCALE`, `VOELIN_WINDOW_SIZE` (the Slint front end's names where they exist). swatch.rs is the page: the 43 colours in the groups of docs/ui.md's "Theme tokens" table with name and value (a test checks each token is in exactly one group), the backdrop, radii, spacing, the type scale, buttons, switches and checkboxes of gpui-component and 16 icons; it scrolls when the window is smaller. scripts/gpui-shot.sh makes the screenshot headless the way scripts/shots.sh does for Slint (xvfb-run, or GPUI_SHOT_HEADLESS=1 under headless.sh on NixOS; Wayland, the session bus and the XDG directories out of the environment), then closes the window with Alt+F4 and reports how the app ended. docs/ui/gpui-swatch-dark.png and -light.png are its output (Xvfb :97, openbox, lavapipe via wgpu's Vulkan backend, the debug binary, 1440x960, truecolour: a 256-colour reduction would change the tokens' values; the Slint pictures live in docs/screenshots/, the task asked for docs/ui/). Checked on Rust 1.95.0: fmt, clippy -D warnings --no-deps (all targets, the build script included), `cargo test -p voelin-gpui` 26 tests, cargo deny, `scripts/notices.sh --check`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
90 lines
3.8 KiB
Bash
Executable File
90 lines
3.8 KiB
Bash
Executable File
#!/bin/sh
|
|
# Take a screenshot of the GPUI front end with development switches set,
|
|
# headless, and close its window the way a user would (docs/ui.md, "The GPUI
|
|
# front end"): the equivalent of scripts/shots.sh for `voelin-gpui`.
|
|
#
|
|
# scripts/gpui-shot.sh <out.png> [<VOELIN_OPEN> [<width>x<height>]]
|
|
#
|
|
# The window opens on a display of its own, never the desktop's: the script
|
|
# runs itself again under `xvfb-run` (Debian, Ubuntu, the CI image) unless
|
|
# GPUI_SHOT_HEADLESS=1 says the caller already did that, as on NixOS:
|
|
#
|
|
# GPUI_SHOT_HEADLESS=1 spikes/gpui/shell.sh spikes/gpui/headless.sh -- \
|
|
# scripts/gpui-shot.sh docs/ui/gpui-swatch-dark.png swatch 1440x960
|
|
#
|
|
# Wayland is taken out of the environment (GPUI prefers it, so the window
|
|
# would open on the desktop), and so are the desktop's session bus and its
|
|
# portals; the app's state and the XDG directories are a temporary one.
|
|
# GPUI needs a Vulkan driver or OpenGL at run time: on a machine without a
|
|
# GPU, Mesa's lavapipe (`mesa-vulkan-drivers`) draws in software. Without a
|
|
# window manager (xvfb-run alone) the window is stopped with TERM, with one
|
|
# (openbox, as headless.sh starts) it gets a close request, which is what the
|
|
# last line says.
|
|
#
|
|
# VOELIN_BIN: the binary (default target/release/voelin-gpui, else
|
|
# target/debug); DELAY: seconds the window is shown before the picture
|
|
# (default 4). VOELIN_DEV_THEME, VOELIN_FONT_SCALE and the other switches of
|
|
# `src/dev.rs` are passed on as set.
|
|
set -eu
|
|
out=${1:?usage: gpui-shot.sh <out.png> [<VOELIN_OPEN> [<width>x<height>]]}
|
|
open=${2:-}
|
|
size=${3:-1440x960}
|
|
w=${size%x*}
|
|
h=${size#*x}
|
|
if [ "${GPUI_SHOT_HEADLESS:-}" != 1 ]; then
|
|
command -v xvfb-run >/dev/null || {
|
|
echo "gpui-shot.sh: no xvfb-run; start a display of your own and set GPUI_SHOT_HEADLESS=1" >&2
|
|
exit 2
|
|
}
|
|
GPUI_SHOT_HEADLESS=1 exec xvfb-run -a -s "-screen 0 $((w * 2))x$((h * 2))x24" "$0" "$@"
|
|
fi
|
|
[ -n "${DISPLAY:-}" ] || { echo "gpui-shot.sh: no DISPLAY" >&2; exit 2; }
|
|
root=$(cd "$(dirname "$0")/.." && pwd)
|
|
bin=${VOELIN_BIN:-}
|
|
if [ -z "$bin" ]; then
|
|
target=${CARGO_TARGET_DIR:-$root/target}
|
|
for kind in release debug; do
|
|
[ -x "$target/$kind/voelin-gpui" ] && { bin=$target/$kind/voelin-gpui; break; }
|
|
done
|
|
fi
|
|
[ -x "$bin" ] || { echo "gpui-shot.sh: no voelin-gpui binary (cargo build -p voelin-gpui --release)" >&2; exit 2; }
|
|
work=$(mktemp -d)
|
|
trap 'kill ${pid:-} 2>/dev/null || true; rm -rf "$work"' EXIT INT TERM
|
|
mkdir -p "$work/runtime"
|
|
chmod 700 "$work/runtime"
|
|
env -u WAYLAND_DISPLAY -u WAYLAND_SOCKET -u XDG_SESSION_TYPE -u DBUS_SESSION_BUS_ADDRESS \
|
|
XDG_RUNTIME_DIR="$work/runtime" XDG_CONFIG_HOME="$work/config" XDG_DATA_HOME="$work/data" \
|
|
XDG_CACHE_HOME="$work/cache" XDG_STATE_HOME="$work/state" VOELIN_DATA_DIR="$work/data/voelin" \
|
|
GPUI_X11_SCALE_FACTOR=1 VOELIN_FFMPEG=0 \
|
|
VOELIN_OPEN="$open" VOELIN_WINDOW_SIZE="$size" \
|
|
"$bin" >"$work/app.log" 2>&1 &
|
|
pid=$!
|
|
i=0
|
|
until win=$(xdotool search --name '^Voelin$' 2>/dev/null | head -1) && [ -n "$win" ]; do
|
|
i=$((i + 1))
|
|
kill -0 "$pid" 2>/dev/null || { echo "gpui-shot.sh: the app ended before its window:" >&2; tail -20 "$work/app.log" >&2; exit 1; }
|
|
[ $i -lt 300 ] || { echo "gpui-shot.sh: no window after 30 s:" >&2; tail -20 "$work/app.log" >&2; exit 1; }
|
|
sleep 0.1
|
|
done
|
|
sleep "${DELAY:-4}"
|
|
xwd -id "$win" -silent | magick xwd:- "png:$out"
|
|
echo "$out: $(magick identify -format '%wx%h' "$out")"
|
|
# Close it as a user does; with no window manager, ask the process to end.
|
|
xdotool windowactivate --sync "$win" 2>/dev/null || true
|
|
xdotool key alt+F4 2>/dev/null || true
|
|
i=0
|
|
while kill -0 "$pid" 2>/dev/null; do
|
|
i=$((i + 1))
|
|
if [ $i -ge 30 ]; then
|
|
kill -TERM "$pid" 2>/dev/null || true
|
|
wait "$pid" 2>/dev/null || true
|
|
echo "stopped with TERM (no window manager closed it)"
|
|
exit 0
|
|
fi
|
|
sleep 0.1
|
|
done
|
|
status=0
|
|
wait "$pid" || status=$?
|
|
echo "closed by the window manager, exit code $status"
|
|
exit "$status"
|