- SidebarPrefs 新增 terminalFontFamily(空 = 跟随主题等宽字体)/ terminalFontSize(9–32,默认 13),PrefsSchema 与 parsePrefs 同步校验 - 声明式设置 API 扩展:SidebarSettingToggle 支持 type: 'switch' | 'text' | 'number'(缺省 switch,向后兼容)+ min/max/placeholder/unit - 终端卡片齿轮弹窗新增「终端字体」「终端字号」两行:blur/Enter 提交、number 钳制、提交失败回滚草稿 - TerminalView 经 store 订阅实时应用字体(options + re-fit + resize),懒加载 chunk 无新增依赖 - 新增 resolveTerminalFont 纯函数(回退链:用户字体 → 主题 token → 内置等宽栈)并单测 - 版本 0.11.0,README/AGENTS.md/设计文档同步
43 lines
2.0 KiB
TypeScript
43 lines
2.0 KiB
TypeScript
/**
|
||
* Terminal font resolution tests: the custom font prefs (side card settings,
|
||
* terminal card) resolve into xterm options with a strict fallback chain —
|
||
* user family > theme code font > the built-in monospace stack, and the size
|
||
* clamped into the 9–32 contract.
|
||
*/
|
||
import { describe, expect, it } from 'vitest'
|
||
import { SIDEBAR_PREFS_DEFAULTS, clampTerminalFontSize, TERMINAL_FONT_SIZE_MAX, TERMINAL_FONT_SIZE_MIN } from '../src/prefs-shared.ts'
|
||
import { DEFAULT_TERMINAL_FONT_FAMILY, resolveTerminalFont } from '../src/client/terminal-font.ts'
|
||
|
||
describe('clampTerminalFontSize', () => {
|
||
it('rounds and clamps into the 9–32 contract', () => {
|
||
expect(clampTerminalFontSize(13)).toBe(13)
|
||
expect(clampTerminalFontSize(15.6)).toBe(16)
|
||
expect(clampTerminalFontSize(5)).toBe(TERMINAL_FONT_SIZE_MIN)
|
||
expect(clampTerminalFontSize(40)).toBe(TERMINAL_FONT_SIZE_MAX)
|
||
})
|
||
})
|
||
|
||
describe('resolveTerminalFont', () => {
|
||
it('falls back to the theme code font when the family pref is empty', () => {
|
||
const { fontFamily, fontSize } = resolveTerminalFont(SIDEBAR_PREFS_DEFAULTS, 'var-theme-font')
|
||
expect(fontFamily).toBe('var-theme-font')
|
||
expect(fontSize).toBe(13)
|
||
})
|
||
|
||
it('falls back to the built-in monospace stack when neither the pref nor the theme provides one', () => {
|
||
expect(resolveTerminalFont(SIDEBAR_PREFS_DEFAULTS, undefined).fontFamily).toBe(DEFAULT_TERMINAL_FONT_FAMILY)
|
||
// A whitespace-only pref counts as empty (theme default).
|
||
expect(resolveTerminalFont({ ...SIDEBAR_PREFS_DEFAULTS, terminalFontFamily: ' ' }, undefined).fontFamily)
|
||
.toBe(DEFAULT_TERMINAL_FONT_FAMILY)
|
||
})
|
||
|
||
it('prefers the custom family verbatim and clamps the size', () => {
|
||
const { fontFamily, fontSize } = resolveTerminalFont(
|
||
{ ...SIDEBAR_PREFS_DEFAULTS, terminalFontFamily: '"JetBrains Mono", monospace', terminalFontSize: 40 },
|
||
'var-theme-font',
|
||
)
|
||
expect(fontFamily).toBe('"JetBrains Mono", monospace')
|
||
expect(fontSize).toBe(TERMINAL_FONT_SIZE_MAX)
|
||
})
|
||
})
|