Pick fonts from a searchable list instead of typing the name

show_font_picker runs `wezterm ls-fonts --list-system` via
wezterm.run_child_process, parses out unique font family names, and
presents them through the existing fuzzy InputSelector so English/
Korean font menu entries no longer require typing an exact,
correctly-spelled font name. A "직접 입력..." choice at the top falls
back to the previous free-text prompt_font flow, also used
automatically if the font list can't be retrieved.

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

View File

@@ -293,6 +293,70 @@ local function prompt_font(window, pane, which)
) )
end end
-- `wezterm ls-fonts --list-system` 결과를 파싱해 설치된 폰트 이름 목록을 만든다
local function list_system_fonts()
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" })
if not ok or not stdout then
return nil
end
local seen = {}
local fonts = {}
for line in stdout:gmatch("[^\r\n]+") do
local name = line:match('^"([^"]+)"') or line:match("^%s*(.-)%s*$")
if name and name ~= "" and not seen[name] then
seen[name] = true
table.insert(fonts, name)
end
end
table.sort(fonts)
return fonts
end
local function show_font_picker(window, pane, which)
local primary, korean = get_current_fonts()
primary = primary or "JetBrains Mono"
korean = korean or "Noto Sans Mono CJK KR"
local fonts = list_system_fonts()
if not fonts or #fonts == 0 then
notify(window, "설치된 폰트 목록을 가져오지 못했습니다. 직접 입력으로 진행합니다")
prompt_font(window, pane, which)
return
end
local choices = { { label = "직접 입력...", id = "__manual__" } }
for _, name in ipairs(fonts) do
table.insert(choices, { label = name, id = name })
end
local current = which == "primary" and primary or korean
window:perform_action(
act.InputSelector({
title = (which == "primary" and "영어/기본 폰트" or "한글 폰트") .. " 선택 (현재: " .. current .. ")",
fuzzy = true,
choices = choices,
action = wezterm.action_callback(function(inner_window, inner_pane, id)
if not id then
return
end
if id == "__manual__" then
prompt_font(inner_window, inner_pane, which)
return
end
if which == "primary" then
set_fonts(inner_window, inner_pane, id, korean)
else
set_fonts(inner_window, inner_pane, primary, id)
end
end),
}),
pane
)
end
local function show_font_settings(window, pane) local function show_font_settings(window, pane)
window:perform_action( window:perform_action(
act.InputSelector({ act.InputSelector({
@@ -310,9 +374,9 @@ local function show_font_settings(window, pane)
if id == "font_size" then if id == "font_size" then
prompt_config_value(inner_window, inner_pane, "폰트 크기", "font_size", config.font_size, false) prompt_config_value(inner_window, inner_pane, "폰트 크기", "font_size", config.font_size, false)
elseif id == "font_primary" then elseif id == "font_primary" then
prompt_font(inner_window, inner_pane, "primary") show_font_picker(inner_window, inner_pane, "primary")
elseif id == "font_korean" then elseif id == "font_korean" then
prompt_font(inner_window, inner_pane, "korean") show_font_picker(inner_window, inner_pane, "korean")
elseif id == "line_height" then elseif id == "line_height" then
prompt_config_value(inner_window, inner_pane, "줄 높이", "line_height", config.line_height, false) prompt_config_value(inner_window, inner_pane, "줄 높이", "line_height", config.line_height, false)
elseif id == "color_scheme" then elseif id == "color_scheme" then