Skip to content

Commit 9005cf2

Browse files
authored
runtime: fix ttyd font (#235)
## Summary - switch ttyd to embedded JetBrains Mono - set the font in ttyd's initial xterm options instead of sending fontFamily over client options - wait for the webfont before rendering ttyd to avoid bad initial glyph spacing ## Tests - nix build .#pwn-workspace-runtime - generated ttyd JavaScript parsed with node --check
1 parent a48ba75 commit 9005cf2

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

runtime/workspace/services/tty/default.nix

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ let
1616
1717
{
1818
printf '<style>\n'
19-
printf '@font-face{font-family:"DejaVu Sans Mono";src:url(data:font/ttf;base64,'
20-
base64 -w0 ${pkgs.dejavu_fonts}/share/fonts/truetype/DejaVuSansMono.ttf
21-
printf ') format("truetype");font-weight:400;font-style:normal;font-display:block;}\n'
19+
printf '@font-face{font-family:"JetBrains Mono";src:url(data:font/woff2;base64,'
20+
base64 -w0 ${pkgs.jetbrains-mono}/share/fonts/WOFF2/JetBrainsMono-Regular.woff2
21+
printf ') format("woff2");font-weight:400;font-style:normal;font-display:block;}\n'
2222
printf '</style>\n'
23+
printf '<script>\n'
24+
printf 'window.__workspaceReadyTerminalFont=function(){if(!document.fonts)return Promise.resolve();var font=Promise.all([document.fonts.load('"'"'13px "JetBrains Mono"'"'"'),document.fonts.ready]);var timeout=new Promise(function(resolve){setTimeout(resolve,1000)});return Promise.race([font,timeout]).catch(function(){})};\n'
25+
printf '</script>\n'
2326
} > font.html
2427
2528
perl -0pi -e 'open my $fh, "<", "font.html" or die $!; local $/; my $font = <$fh>; s#</head>#$font</head>#' index.html
29+
perl -0pi -e 's#fontFamily:"Consolas,Liberation Mono,Menlo,Courier,monospace"#fontFamily:"\\"JetBrains Mono\\", monospace"#' index.html
30+
perl -0pi -e 's#\Q(0,e.render)((0,e.h)(t.App,null),document.body)\E#(window.__workspaceReadyTerminalFont?window.__workspaceReadyTerminalFont():Promise.resolve()).then(function(){(0,e.render)((0,e.h)(t.App,null),document.body)})#' index.html
2631
2732
mkdir -p $out/share/workspace/ttyd
2833
cp index.html $out/share/workspace/ttyd/index.html
@@ -40,7 +45,6 @@ let
4045
--writable \
4146
-t disableLeaveAlert=true \
4247
-t disableResizeOverlay=true \
43-
-t 'fontFamily="DejaVu Sans Mono", monospace' \
4448
--cwd "$HOME" \
4549
"$SHELL" \
4650
--login

0 commit comments

Comments
 (0)