Add separate English/Korean font selection to font settings menu
config.font is set via wezterm.font_with_fallback({ primary, korean }),
a multi-line block that the existing single-line set_config_value
can't touch. Added get_current_fonts (reads both font names straight
out of the config file text, for display) and set_fonts (replaces the
whole font_with_fallback body in one shot, lazy-matched between the
"{" and the closing "})"), plus two new font settings menu entries
("영어 폰트" / "한글 폰트") that prompt for one name at a time while
keeping the other font unchanged.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
78
wezterm.lua
78
wezterm.lua
@@ -221,6 +221,78 @@ local function prompt_config_value(window, pane, title, key, initial_value, quot
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- config.font = wezterm.font_with_fallback({ "영어 폰트", "한글 폰트" }) 블록에서
|
||||||
|
-- 현재 지정된 두 폰트 이름을 읽어온다 (설정 파일 텍스트 기준, 실행 중인 config 객체가 아님)
|
||||||
|
local function get_current_fonts()
|
||||||
|
local text = read_config_text()
|
||||||
|
if not text then
|
||||||
|
return nil, nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local block = text:match("config%.font = wezterm%.font_with_fallback%(%{(.-)%}%)")
|
||||||
|
if not block then
|
||||||
|
return nil, nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local fonts = {}
|
||||||
|
for f in block:gmatch('"([^"]*)"') do
|
||||||
|
table.insert(fonts, f)
|
||||||
|
end
|
||||||
|
return fonts[1], fonts[2]
|
||||||
|
end
|
||||||
|
|
||||||
|
local function set_fonts(window, pane, primary, korean)
|
||||||
|
local text, err = read_config_text()
|
||||||
|
if not text then
|
||||||
|
notify(window, err)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local new_block = string.format('\n\t%q, -- 영어/기본 폰트\n\t%q, -- 한글 폰트\n', primary, korean)
|
||||||
|
local safe_block = new_block:gsub("%%", "%%%%")
|
||||||
|
local updated, count = text:gsub("(config%.font = wezterm%.font_with_fallback%(%{).-(%}%))", "%1" .. safe_block .. "%2", 1)
|
||||||
|
|
||||||
|
if count == 0 then
|
||||||
|
notify(window, "config.font 설정을 찾지 못했습니다")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local ok, write_err = write_config_text(updated)
|
||||||
|
if not ok then
|
||||||
|
notify(window, write_err)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
notify(window, "폰트 저장됨: 영어=" .. primary .. ", 한글=" .. korean)
|
||||||
|
window:perform_action(act.ReloadConfiguration, pane)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function prompt_font(window, pane, which)
|
||||||
|
local primary, korean = get_current_fonts()
|
||||||
|
primary = primary or "JetBrains Mono"
|
||||||
|
korean = korean or "Noto Sans Mono CJK KR"
|
||||||
|
|
||||||
|
local current = which == "primary" and primary or korean
|
||||||
|
local title = (which == "primary" and "영어/기본 폰트" or "한글 폰트") .. " (현재: " .. current .. ")"
|
||||||
|
|
||||||
|
window:perform_action(
|
||||||
|
act.PromptInputLine({
|
||||||
|
description = title,
|
||||||
|
action = wezterm.action_callback(function(cb_window, cb_pane, line)
|
||||||
|
if not line or line == "" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if which == "primary" then
|
||||||
|
set_fonts(cb_window, cb_pane, line, korean)
|
||||||
|
else
|
||||||
|
set_fonts(cb_window, cb_pane, primary, line)
|
||||||
|
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({
|
||||||
@@ -228,6 +300,8 @@ local function show_font_settings(window, pane)
|
|||||||
fuzzy = true,
|
fuzzy = true,
|
||||||
choices = {
|
choices = {
|
||||||
{ label = "폰트 크기", id = "font_size" },
|
{ label = "폰트 크기", id = "font_size" },
|
||||||
|
{ label = "영어 폰트", id = "font_primary" },
|
||||||
|
{ label = "한글 폰트", id = "font_korean" },
|
||||||
{ label = "줄 높이", id = "line_height" },
|
{ label = "줄 높이", id = "line_height" },
|
||||||
{ label = "색상 테마", id = "color_scheme" },
|
{ label = "색상 테마", id = "color_scheme" },
|
||||||
{ label = "창 투명도", id = "opacity" },
|
{ label = "창 투명도", id = "opacity" },
|
||||||
@@ -235,6 +309,10 @@ local function show_font_settings(window, pane)
|
|||||||
action = wezterm.action_callback(function(inner_window, inner_pane, id)
|
action = wezterm.action_callback(function(inner_window, inner_pane, id)
|
||||||
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
|
||||||
|
prompt_font(inner_window, inner_pane, "primary")
|
||||||
|
elseif id == "font_korean" then
|
||||||
|
prompt_font(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
|
||||||
|
|||||||
Reference in New Issue
Block a user