Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/ui/terminal/flatSurface.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import "@/test/dom";
import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { XTERM_THEME } from "@/lib/consts/themes";
import { xtermTheme } from "@/ui/terminal/xtermTheme";

const ROOT = join(import.meta.dir, "../../..");
const CHROME = readFileSync(join(ROOT, "src/ui/terminal/terminal.css"), "utf8");
const SURFACE = readFileSync(join(ROOT, "src/ui/terminal/xterm.css"), "utf8");

/** The rule that contains a selector; a comma-separated selector list shares one body. */
function ruleBody(source: string, selector: string): string {
const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const at = source.search(new RegExp(escaped));
const open = at === -1 ? -1 : source.indexOf("{", at);
const close = open === -1 ? -1 : source.indexOf("}", open);
return open === -1 || close === -1 ? "" : source.slice(open + 1, close);
}

/**
* The lighter ring came from two surfaces: the frame read `--panel` while the xterm body read
* `--bg`, and a border closed the outline. An emulator layer on a third colour would bring it back.
*/
describe("flat terminal surface", () => {
test("no terminal stylesheet paints a background on --bg", () => {
for (const source of [CHROME, SURFACE]) {
expect(source).not.toMatch(/background(?:-color)?:\s*var\(--bg\)/);
}
});

test("the header and status row draw no seam against the body", () => {
expect(ruleBody(CHROME, ".terminal-chrome")).not.toMatch(/border-/);
expect(ruleBody(CHROME, ".terminal-status")).not.toMatch(/border-/);
});

test("the emulator layers and the side-docked variant use the pane token", () => {
expect(ruleBody(SURFACE, ".terminal-surface")).toContain("var(--panel)");
expect(ruleBody(SURFACE, ".terminal .terminal-xterm")).toContain("var(--panel)");
expect(ruleBody(SURFACE, ".terminal .terminal-xterm .xterm .xterm-screen")).toContain(
"var(--panel)",
);
expect(ruleBody(SURFACE, ".terminal .terminal-xterm .xterm .xterm-viewport")).toContain(
"var(--panel)",
);
expect(ruleBody(CHROME, ".terminal.terminal-side")).toContain("var(--panel)");
});

test("the emulator paints the pane token, not its own palette background", () => {
const panel = "#123456";
document.documentElement.style.setProperty("--panel", panel);
const theme = xtermTheme();
expect(theme.background).toBe(panel);
expect(theme.foreground).toBe(XTERM_THEME.foreground);
});
});
3 changes: 1 addition & 2 deletions src/ui/terminal/terminal.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Terminal chrome: one quiet header row — tabs as labels, actions as icon buttons. */
/* The header, body and status row are one flat `--panel` surface: no rule draws their seam. */

.terminal-chrome {
display: flex;
Expand All @@ -7,7 +8,6 @@
flex: 0 0 auto;
height: 30px;
padding: 0 6px 0 8px;
border-bottom: 1px solid var(--line);
background: var(--panel);
}

Expand Down Expand Up @@ -161,7 +161,6 @@
gap: 10px;
height: 26px;
padding: 0 10px;
border-top: 1px solid var(--line);
background: var(--panel);
font-family: var(--mono);
font-size: 10.5px;
Expand Down
11 changes: 6 additions & 5 deletions src/ui/terminal/xterm.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
display: flex;
flex: 1 1 auto;
min-height: 0;
background: var(--bg);
background: var(--panel);
}

/* Beats `.terminal-body` in the shared sheet: the host carries the padding, xterm carries none. */
Expand All @@ -15,18 +15,19 @@
min-height: 0;
padding: 6px 10px 4px;
overflow: hidden;
background: var(--bg);
background: var(--panel);
}

.terminal-xterm .xterm {
height: 100%;
padding: 0;
background: var(--bg);
background: var(--panel);
}

/* Keep the viewport (the scrollable backing) on the app surface so nothing flashes black. */
/* The screen and the scrollable viewport stay on the pane surface: no second shade underneath. */
.terminal .terminal-xterm .xterm .xterm-screen,
.terminal .terminal-xterm .xterm .xterm-viewport {
background-color: var(--bg);
background-color: var(--panel);
}

/* Selection and cursor come from xtermTheme.ts; keep the selection layer above the canvas. */
Expand Down
4 changes: 2 additions & 2 deletions src/ui/terminal/xtermOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ITerminalOptions, Terminal } from "@xterm/xterm";

import type { TerminalCursorStyle } from "@/lib/settings/terminal";
import { MONO_STACK } from "@/lib/consts/terminal";
import { XTERM_THEME } from "@/ui/terminal/xtermTheme";
import { xtermTheme } from "@/ui/terminal/xtermTheme";

export { MONO_STACK, SCROLLBACK } from "@/lib/consts/terminal";

Expand All @@ -24,7 +24,7 @@ export type XtermAppearance = {

export function xtermOptions(appearance: XtermAppearance): ITerminalOptions {
return {
theme: XTERM_THEME,
theme: xtermTheme(),
fontFamily: xtermFontFamily(appearance.fontFamily),
fontSize: appearance.fontSize,
lineHeight: appearance.lineHeight,
Expand Down
13 changes: 11 additions & 2 deletions src/ui/terminal/xtermTheme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { XTERM_THEME as BASE_THEME, type TerminalPalette } from "@/lib/consts/themes";

/**
* xterm in Zed's One Dark, so the terminal matches the editor beside it.
*
* The palette itself lives in `@/lib/consts/themes` with the rest of the theme literals.
* The palette itself lives in `@/lib/consts/themes` with the rest of the theme literals. Its own
* background is a third shade, and xterm writes it onto the viewport as an inline style, so a CSS
* rule cannot flatten the pane. Read the pane token instead: the body, chrome and emulator then
* paint the same surface from one source.
*/
export { XTERM_THEME } from "@/lib/consts/themes";
export function xtermTheme(): TerminalPalette {
if (typeof document === "undefined") return BASE_THEME;
const panel = getComputedStyle(document.documentElement).getPropertyValue("--panel").trim();
return panel === "" ? BASE_THEME : { ...BASE_THEME, background: panel };
}
Loading