You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Wezterm配置Lua文件中字号设置与声音提示铃失效问题求助

Wezterm配置Lua文件中字号设置与声音提示铃失效问题求助

问题描述

我目前在用Garuda Linux搭配XFCE桌面,终端用的是Wezterm,最近在折腾它的Lua配置文件,但遇到了两个头疼的问题:

  • 不管我设置多大的字号,Wezterm完全没反应
  • 明明写了禁用提示音的配置,可是声音还是会响

我翻了一遍官方文档,还是没找到问题出在哪,不管是直接给解决方案,还是告诉我哪篇文档能解决这个问题,都非常感谢!

我的配置代码如下:

local config = {}

font_size = 50.0

local cfg_misc = {
    window_close_confirmation = "NeverPrompt",
    automatically_reload_config = false,
    -- Disable all noises
    audible_bell = "Disabled",
}

config.colors = {
    --Default text color
    foreground = '#00ff00',
    --Default Background color
    background = '#000000',
    --Override the cell background color when current cell is occupied by
    --the cursor and the cursor style is set to Block
    cursor_bg = '#00ff00',
    --Overrides the text color when the current cell is occupied by the
    --cursor
    cursor_fg = '#000000',
    --Background color for selected text
    selection_bg = '#00ff00',
    --Foreground color for selected text
    selection_fg = '#000000'
}

--This is on line number 32
config.font =
wezterm.font( 'Classic Console Neue' )

return config

解决方案

你的问题根源很清晰:配置项没有正确关联到Wezterm会读取的config对象上,Wezterm只会识别config表内的配置,其他全局变量或独立表不会生效。具体修复点如下:

  1. 修复字号不生效问题
    你把font_size定义成了全局变量,Wezterm根本读取不到这个值。只需要把它挂载到config对象上即可:
-- 原来的写法:font_size = 50.0
config.font_size = 50.0
  1. 修复提示音未禁用问题
    你创建了cfg_misc表存放杂项配置,但没有把这些配置合并到config里,自然不会生效。有两种处理方式:
  • 直接把配置项写到config中:
    config.window_close_confirmation = "NeverPrompt"
    config.automatically_reload_config = false
    config.audible_bell = "Disabled"
    
  • 如果你想保持配置分模块的结构,可以用循环把cfg_misc的内容合并到config
    for key, value in pairs(cfg_misc) do
        config[key] = value
    end
    
  1. 小优化:字体配置的换行问题
    你的config.font配置换行了,虽然Lua允许这种写法,但为了可读性,建议写成一行:
config.font = wezterm.font('Classic Console Neue')

修复后的完整配置

local config = {}

-- 字号配置
config.font_size = 50.0

-- 杂项配置
local cfg_misc = {
    window_close_confirmation = "NeverPrompt",
    automatically_reload_config = false,
    audible_bell = "Disabled",
}
-- 合并到config
for key, value in pairs(cfg_misc) do
    config[key] = value
end

-- 颜色配置
config.colors = {
    foreground = '#00ff00',
    background = '#000000',
    cursor_bg = '#00ff00',
    cursor_fg = '#000000',
    selection_bg = '#00ff00',
    selection_fg = '#000000'
}

-- 字体配置
config.font = wezterm.font('Classic Console Neue')

return config

修改完成后,你可以用快捷键Ctrl+Shift+R重新加载配置,或者重启Wezterm,就能看到字号生效、提示音被禁用了。

备注:内容来源于stack exchange,提问作者The ScaryJello

火山引擎 最新活动