feat(web): bundle Fira Code Nerd Font for the terminal
Use Fira Code Nerd Font Mono in the monospace UI, including the terminal. The font carries Nerd Font glyphs for prompts and tools, and Fira Code's contextual ligatures apply in xterm's DOM renderer because it groups same-style cells into spans. The terminal waits for the regular and bold faces before opening so xterm measures cell widths with the final font.
This commit is contained in:
1 parent
05660a244b
commit
e579653f75
6 files changed
+155
-3
No files matched your search
@@ -24,6 +24,22 @@ function token(name: string): string {
|
||||
return getComputedStyle(document.documentElement).getPropertyValue(name).trim()
|
||||
}
|
||||
|
||||
function terminalFontSize(): number {
|
||||
return Number.parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--fs-code')) || 13
|
||||
}
|
||||
|
||||
async function loadTerminalFont(fontFamily: string, fontSize: number): Promise<void> {
|
||||
if (typeof document === 'undefined' || !document.fonts) return
|
||||
try {
|
||||
await Promise.all([
|
||||
document.fonts.load(`400 ${fontSize}px ${fontFamily}`),
|
||||
document.fonts.load(`700 ${fontSize}px ${fontFamily}`),
|
||||
])
|
||||
} catch {
|
||||
// The terminal falls back to the system monospace font.
|
||||
}
|
||||
}
|
||||
|
||||
function terminalTheme() {
|
||||
return {
|
||||
background: token('--surface-2'),
|
||||
@@ -172,11 +188,19 @@ onMounted(async () => {
|
||||
])
|
||||
if (!host.value) return
|
||||
|
||||
const fontFamily = getComputedStyle(document.documentElement).getPropertyValue('--font-mono').trim()
|
||||
const fontSize = terminalFontSize()
|
||||
await loadTerminalFont(fontFamily, fontSize)
|
||||
|
||||
term = new Terminal({
|
||||
convertEol: false,
|
||||
cursorBlink: true,
|
||||
fontFamily: getComputedStyle(document.documentElement).getPropertyValue('--font-mono').trim(),
|
||||
fontSize: Number.parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--fs-code')) || 13,
|
||||
fontFamily,
|
||||
fontSize,
|
||||
fontWeight: 400,
|
||||
fontWeightBold: 700,
|
||||
letterSpacing: 0,
|
||||
lineHeight: 1.2,
|
||||
scrollback: 3000,
|
||||
theme: terminalTheme(),
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user