Cache system font list to stop the font-picker flash

wezterm ls-fonts --list-system runs synchronously and blocks the UI
thread while it walks every installed font, which happens right after
the previous menu overlay closes -- during that gap the underlying
shell was briefly visible before the font picker rendered. Caching the
parsed result means the blocking call only happens once; gui-startup
also warms the cache immediately so even the first font settings visit
in a session is instant.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-18 01:38:36 +09:00
parent 05373fe335
commit 8afe869b02

View File

@@ -293,8 +293,15 @@ local function prompt_font(window, pane, which)
) )
end end
-- `wezterm ls-fonts --list-system` 결과를 파싱해 설치된 폰트 이름 목록을 만든다 -- `wezterm ls-fonts --list-system`는 동기(블로킹) 호출이라 매번 실행하면 메뉴 전환 사이에
-- 밑에 있던 셸이 잠깐 보이는 깜빡임이 생긴다. 한 번 조회한 결과를 캐싱해 재사용한다
local system_fonts_cache = nil
local function list_system_fonts() local function list_system_fonts()
if system_fonts_cache then
return system_fonts_cache
end
local exe = is_windows and (wezterm.executable_dir .. "\\wezterm.exe") or (wezterm.executable_dir .. "/wezterm") local exe = is_windows and (wezterm.executable_dir .. "\\wezterm.exe") or (wezterm.executable_dir .. "/wezterm")
local ok, stdout = wezterm.run_child_process({ exe, "ls-fonts", "--list-system" }) local ok, stdout = wezterm.run_child_process({ exe, "ls-fonts", "--list-system" })
if not ok or not stdout then if not ok or not stdout then
@@ -311,6 +318,7 @@ local function list_system_fonts()
end end
end end
table.sort(fonts) table.sort(fonts)
system_fonts_cache = fonts
return fonts return fonts
end end
@@ -749,6 +757,7 @@ end)
-- 시작 시 첫 화면으로 메인 메뉴를 띄워 설정과 연결 메뉴에 바로 접근합니다. -- 시작 시 첫 화면으로 메인 메뉴를 띄워 설정과 연결 메뉴에 바로 접근합니다.
wezterm.on("gui-startup", function(cmd) wezterm.on("gui-startup", function(cmd)
local tab, pane, window = wezterm.mux.spawn_window(cmd or {}) local tab, pane, window = wezterm.mux.spawn_window(cmd or {})
list_system_fonts() -- 폰트 목록을 미리 캐싱해서, 나중에 폰트 설정 메뉴에서 조회 지연으로 화면이 깜빡이지 않게 함
show_main_menu(window:gui_window(), pane) show_main_menu(window:gui_window(), pane)
end) end)