Skip to content

fix(terminal): stop the bottom workbench terminal from painting black - #1104

Merged
Menghuan1918 merged 1 commit into
omdsh-dev:devfrom
WinterXMQ:fix/terminal-viewport-background
Nov 4, 2026
Merged

Menghuan1918 merged 1 commit into
omdsh-dev:devfrom
WinterXMQ:fix/terminal-viewport-background

Conversation

@WinterXMQ

@WinterXMQ WinterXMQ commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

问题

底部工作台的终端区域是一整块纯黑矩形,而它所在的 tab 条和面板都不是。看起来像是插件自己选了一块深色底,而不是终端透出面板表面。

两处独立原因,缺一不可。

1. CSS Modules 把 xterm 自己的类名也一起哈希了

原规则写的是:

.screen .xterm-viewport {
  background: var(--dsw-alias-bg-base);
}

编译产物却是:

.o8IiwG_screen .o8IiwG_xterm-viewport { ... }

而真实 DOM 里是 <div class="xterm-viewport">(xterm 自己生成,不带 hash)。这条规则从头到尾没有匹配到任何元素,所以无论怎么改颜色都毫无反应。

2. xterm 自带样式表硬编码黑底,且注入时机更晚

xterm 的 css/xterm.css 里有:

.xterm .xterm-viewport {
  /* On OS X this is required in order for the scroll bar to appear fully opaque */
  background-color: #000;
}

特异性 0,2,0。即便把选择器包上 :global(),.screen .xterm-viewport 也仍是 0,2,0 —— 与它相同。而 xterm 是在 open() 时才把这张样式表插进文档的,晚于本插件的模块 CSS,同特异性下源顺序后者胜,于是 xterm 赢。

改动

  • .screen :global(.xterm .xterm-viewport) { background: transparent }
    • :global() 修掉哈希导致的失配;
    • 多出一级 .xterm 把特异性抬到 0,3,0,压过 xterm 的 0,2,0,不依赖 !important。
  • .screen 自身不再画 --dsw-alias-bg-base(那是面板里的第二块底)。

Chromium 实测(我们的样式先注入、xterm.css 在 open() 时后注入,复现真实时序):

选择器 特异性 viewport 背景
.o8IiwG_screen .xterm-viewport 0,2,0 rgb(0, 0, 0) ❌ 仍是黑
.o8IiwG_screen .xterm .xterm-viewport 0,3,0 rgba(0, 0, 0, 0) ✅
同上 + !important 0,3,0 rgba(0, 0, 0, 0) ✅(!important 非必需)

实测无效、因此没有采用的写法

  • !important:提高特异性已经足够。
  • xterm 的 allowTransparency: true:在 xterm 6.0.0 默认使用的 DOM 渲染器下,它对 .xterm-viewport 的内联背景没有任何影响(实测两档结果相同),故未纳入本 PR。

效果

修复前:终端是一块纯黑矩形。

修复后:终端与工作台同色,只留下文字与光标。

paste_image

验证

  • pnpm typecheck 通过。
  • pnpm build 通过;产物确认选择器为 .o8IiwG_screen .xterm .xterm-viewport{background:0 0}。
  • 本地以 link: 方式挂载到 desktop profile,刷新后终端黑底消失、文字与光标正常。
  • 未改动 host 半、未加依赖/路由、未改会话格式、未新增轮询。

范围

仅 src/client/terminal.module.css 与 CHANGELOG.md。dev 上工作台与 tab 条的背景(另一处皮肤色差问题)不在本 PR 内。


The terminal area was a solid black rectangle inside a panel that was not,
which read as a surface the plugin had chosen rather than the emulator
showing through.

Two independent causes, both needed:

1. CSS Modules hashed xterm's own class names. `.screen .xterm-viewport`
   compiled to `.o8IiwG_screen .o8IiwG_xterm-viewport`, while the real DOM
   carries xterm's unhashed `.xterm-viewport` — the rule never matched
   anything. Wrapped in `:global()`.

2. xterm.css ships `.xterm .xterm-viewport { background-color: #000 }` and
   injects that sheet when `open()` runs, after this module. Matching its
   specificity (0,2,0) therefore loses on source order every time, so the
   selector climbs to 0,3,0 with the extra `.xterm`. Measured in Chromium:
   0,2,0 leaves `rgb(0, 0, 0)`, 0,3,0 resolves to `rgba(0, 0, 0, 0)`.

`.screen` itself also stops painting `--dsw-alias-bg-base`, which was a second
surface inside the panel.

No `!important` (outranking by specificity is enough) and no
`allowTransparency` (measured no effect on the viewport background under the
DOM renderer xterm 6 uses by default).
@Menghuan1918
Menghuan1918 merged commit 4b61d68 into omdsh-dev:dev Nov 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants