自定义终端主题里的 terminal:background 不生效——终端背景被强制同步成界面主色
Author: MrcoolfuyuCreated Sep 15, 2026Updated Sep 15, 2026
Electerm Version and download file extension(Electerm版本和下载文件后缀)
electerm-5.5.6-win-x64-portable.tar.gz
Platform detail (平台详情)
Windows11
What steps will reproduce the bug?(重现问题的详细步骤)
在新建或编辑自定义终端主题时,设置 terminal:background(例如想设成黑色 #000000)完全没有效果。终端内容区的背景永远是界面主题的 main 颜色,所以终端背景无法独立于界面其它部分单独配置成深色。 其它终端颜色键(foreground、black、selectionBackground、cursor 等)都能正常生效——只有 background 是坏的。
复现步骤
- 设置 → 主题 → 新建 / 导入一个主题。
- 在主题文本里设置: terminal:background=#000000 terminal:foreground=#ffffff (界面颜色 main 保持默认浅色,例如 #f7f7f7)
- 保存并应用该主题。
- 关闭并重新连接一个终端标签页(已打开的标签页不会热更新 xterm 配色)。
What should have happened?(期望的结果)
终端内容区应使用所配置的 terminal:background 颜色(黑色),上层显示 terminal:foreground 的文字(白色)——并且与界面 main 颜色相互独立
实际行为
- foreground、black、selectionBackground 都正确生效了。
- 终端背景仍然是界面 main 颜色(#f7f7f7 浅色),所以 terminal:background 实际上是个废键。
Additional information(其他任何相关信息)
实证(来自对 app.asar 和本地 SQLite electerm.db 的排查)
- 存储的真实值——保存一个 terminal:background=#000000 的主题后,数据库 terminalThemes 表里的行内容为: "themeConfig": { "background": "#f7f7f7", "foreground": "#ffffff", "selectionBackground": "#264f78", "black": "#666666" } 注意 foreground / black / selectionBackground 都正确写入了,唯独 background 被重置回 #f7f7f7(== main)。这证明在保存时存在一次覆盖。
- 保存处理函数强制同步——全程序唯一一处对 themeConfig.background 赋值,会把它覆盖成界面主色: c.uiThemeConfig.main !== c.themeConfig.background && (c.themeConfig.background = c.uiThemeConfig.main);
- 渲染时再次被替换——终端主题构造器 dm() 直接丢弃了 background: function dm(e = {}, rendererType, visibleBg) { return { ...e, background: rendererType === 'webGL' && sm(visibleBg) ? visibleBg : 'rgba(0,0,0,0)' } } 在默认的 DOM 渲染器下,这会让背景变成完全透明,所以最终可见的颜色其实来自容器 CSS: .term-wrap { background: var(--main); } 也就是界面 main 颜色。结论:终端区域背景在设计上 = 界面主色。 修复建议
- 删除(或改为条件式 / 可由用户覆盖)保存处理函数里那句强制的 themeConfig.background = uiThemeConfig.main 同步。
- 渲染器应尊重 themeConfig.background,而不是一律把它改成透明,除非用户显式选择了透明终端。
临时规避方案(供遇到此问题的其它用户参考) 在修复之前,想要深色终端背景只能二选一:
- 把界面 main 颜色设成深色(但整个界面也会一起变暗),或
- 通过 设置 → 自定义CSS 注入自定义样式: .term-wrap, .terminal-normal-buffer { background: #000000 !important; } (必须使用 DOM 渲染器而非 webgl 才会生效。)
Source: electerm/electerm