cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

main
012 / demos / lib / font-page
font-page 1.6K executable
1#!/bin/sh2# font-page OUT FONTDIR: writes ttyd's own page to OUT with JetBrains3# Mono added as a web font from FONTDIR's TTFs (e2e/testdata/fonts), for4# demos/lib/ttyd to serve with ttyd -I. VHS's browser draws with the5# fonts the system or the page gives it, so with the font in the page6# the recordings are drawn in it whether or not it is installed. The7# page comes from the ttyd in DEMOS_TTYD, so it always matches it.8set -eu9out=$1 fonts=$210log=$(mktemp)11"${DEMOS_TTYD:?set DEMOS_TTYD to the real ttyd}" -p 0 -i 127.0.0.1 true 2>"$log" &12pid=$!13trap 'kill $pid 2>/dev/null || true; rm -f "$log"' EXIT14port=15for _ in $(seq 50); do16 port=$(sed -n 's/.*Listening on port: \([0-9]*\).*/\1/p' "$log")17 [ -n "$port" ] && break18 sleep 0.119done20[ -n "$port" ] || { echo "font-page: ttyd didn't start"; cat "$log"; exit 1; }21page=$(curl -sf "http://127.0.0.1:$port/")22case $page in *"</head>"*) ;; *) echo "font-page: no </head> in ttyd's page"; exit 1 ;; esac2324face() { # weight style file25 printf '@font-face{font-family:"JetBrains Mono";font-weight:%s;font-style:%s;src:url(data:font/ttf;base64,' "$1" "$2"26 base64 <"$fonts/$3" | tr -d '\n'27 printf ') format("truetype")}'28}29{30 printf '%s' "${page%%</head>*}"31 printf '<style>'32 face 400 normal JetBrainsMono-Regular.ttf33 face 700 normal JetBrainsMono-Bold.ttf34 face 400 italic JetBrainsMono-Italic.ttf35 face 700 italic JetBrainsMono-BoldItalic.ttf36 printf '</style>'37 # Load every style now, before VHS measures the font.38 printf '<script>["16px","bold 16px","italic 16px","italic bold 16px"].forEach(function(f){document.fonts.load(f+" \\"JetBrains Mono\\"")})</script>'39 printf '</head>%s' "${page#*</head>}"40} >"$out"