feat(settings): Color Scheme › Console Colors for the terminal's ANSI colors (#2751)

Settings › Editor › Color Scheme gets a Console Colors page, as in IntelliJ IDEA: the console background and the 16 ANSI colors, used by the terminal and consoles. A light IDE theme no longer forces a light terminal. IDEA's CONSOLE_* keys from .icls schemes and IntelliJ theme imports set the same colors.

Closes #2698

Co-authored-by: GGVidal <[email protected]>
Цей коміт міститься в:
Gabriel Gondim authored and GitHub committed 2026-11-11 23:40:04 +08:00
1 джерело 86f69b7fca
коміт b06f2e27ea
12 files changed
+238 -47

No files matched your search

+19
Переглянути файл
@@ -168,6 +168,25 @@ describe("color schemes", () => {
expect(pythonItalic).toContain("--syn-python-static-italic: italic !important");
});
it("mirrors Console Colors ANSI overrides to the terminal palette (#2698)", () => {
expect(ATTRIBUTES.filter((a) => a.path[0] === "Console Colors")).toHaveLength(17);
const root = document.documentElement;
root.dataset.theme = "light";
const css = schemeCss(
"theme-default",
{
light: {
ansiRed: { foreground: "#aa0000" },
consoleBackground: { background: "#101010" },
},
},
root,
);
expect(css).toContain("--ansi-red: #aa0000 !important");
expect(css).toContain("--terminal-ansi-red: #aa0000 !important");
expect(css).toContain("--bg-console: #101010 !important");
});
it("leaves selected text in syntax colours until a selection foreground is set (#2446)", () => {
expect(ATTRIBUTES.find((a) => a.id === "selectionForeground")).toMatchObject({
name: "Selection foreground",
+31 -2
Переглянути файл
@@ -135,6 +135,26 @@ const BASE_ATTRIBUTES: readonly AttributeDef[] = [
{ id: "inlineValue", name: "Inline debugger values", path: ["Debugger"], fg: "--syn-inline-value" },
{ id: "breakpointLine", name: "Breakpoint line", path: ["Debugger"], bg: "--bg-breakpoint-line" },
// Console / terminal: IDEA's Console Colors (background + 16 ANSI). `--ansi-*` is mirrored
// to `--terminal-ansi-*` in overrideDeclarations so the terminal picks up edits.
{ id: "consoleBackground", name: "Console background", path: ["Console Colors"], bg: "--bg-console" },
{ id: "ansiBlack", name: "Black", path: ["Console Colors"], fg: "--ansi-black" },
{ id: "ansiRed", name: "Red", path: ["Console Colors"], fg: "--ansi-red" },
{ id: "ansiGreen", name: "Green", path: ["Console Colors"], fg: "--ansi-green" },
{ id: "ansiYellow", name: "Yellow", path: ["Console Colors"], fg: "--ansi-yellow" },
{ id: "ansiBlue", name: "Blue", path: ["Console Colors"], fg: "--ansi-blue" },
{ id: "ansiMagenta", name: "Magenta", path: ["Console Colors"], fg: "--ansi-magenta" },
{ id: "ansiCyan", name: "Cyan", path: ["Console Colors"], fg: "--ansi-cyan" },
{ id: "ansiWhite", name: "White", path: ["Console Colors"], fg: "--ansi-white" },
{ id: "ansiBrightBlack", name: "Dark gray", path: ["Console Colors"], fg: "--ansi-bright-black" },
{ id: "ansiBrightRed", name: "Bright red", path: ["Console Colors"], fg: "--ansi-bright-red" },
{ id: "ansiBrightGreen", name: "Bright green", path: ["Console Colors"], fg: "--ansi-bright-green" },
{ id: "ansiBrightYellow", name: "Bright yellow", path: ["Console Colors"], fg: "--ansi-bright-yellow" },
{ id: "ansiBrightBlue", name: "Bright blue", path: ["Console Colors"], fg: "--ansi-bright-blue" },
{ id: "ansiBrightMagenta", name: "Bright magenta", path: ["Console Colors"], fg: "--ansi-bright-magenta" },
{ id: "ansiBrightCyan", name: "Bright cyan", path: ["Console Colors"], fg: "--ansi-bright-cyan" },
{ id: "ansiBrightWhite", name: "Bright white", path: ["Console Colors"], fg: "--ansi-bright-white" },
syn("keyword", "Keyword", [LD], "keyword"),
syn("identifier", "Identifiers › Local variable", [LD], "variable"),
syn("parameter", "Identifiers › Parameter", [LD], "param"),
@@ -405,7 +425,11 @@ export function overrideDeclarations(
if (attr.language !== language) continue;
const o = overrides[attr.id];
if (!o) continue;
if (setOrCleared(o.foreground) && attr.fg) out.push([attr.fg, o.foreground]);
if (setOrCleared(o.foreground) && attr.fg) {
out.push([attr.fg, o.foreground]);
// Terminal prefers `--terminal-ansi-*`; keep it in sync with console `--ansi-*`.
if (attr.fg.startsWith("--ansi-")) out.push([`--terminal-ansi-${attr.fg.slice("--ansi-".length)}`, o.foreground]);
}
if (setOrCleared(o.background) && attr.bg) out.push([attr.bg, o.background]);
if (setOrCleared(o.effectColor) && attr.effect) out.push([attr.effect, o.effectColor]);
if (attr.effect && setOrCleared(o.effectColor)) {
@@ -556,7 +580,12 @@ export function schemeCss(
const pluginTheme = !!el?.dataset.pluginTheme && id === setting;
if (id !== themeScheme(root) || pluginTheme) {
const tokens = resolvedSchemeTokens(id, valid);
for (const [k, v] of tokens) if (SCHEME_VARS.has(k) || k.startsWith("--syn-")) decls.push([k, v]);
for (const [k, v] of tokens)
if (SCHEME_VARS.has(k) || k.startsWith("--syn-")) {
decls.push([k, v]);
// Terminal reads `--terminal-ansi-*`; keep it aligned with console `--ansi-*`.
if (k.startsWith("--ansi-")) decls.push([`--terminal-ansi-${k.slice("--ansi-".length)}`, v]);
}
// The editor surface follows the scheme, not the island colour of the UI theme.
const bg = tokens.get("--bg-editor") ?? tokens.get("--bg-island");
if (bg) decls.push(["--bg-editor", bg], ["--bg-editor-gutter", tokens.get("--bg-editor-gutter") ?? bg]);
+2 -1
Переглянути файл
@@ -211,7 +211,8 @@ describe(".icls schemes", () => {
expect(scheme.attributes.gutter?.background).toBe("#212121");
expect(scheme.attributes.lineNumber?.foreground).toBe("#424242");
expect(scheme.attributes.selection?.background).toBe("#353535");
expect([applied, skipped]).toEqual([12, 3]);
expect(scheme.attributes.consoleBackground?.background).toBe("#212121");
expect([applied, skipped]).toEqual([13, 2]);
});
it.each([
+21
Переглянути файл
@@ -233,7 +233,28 @@ const COLOR_NAMES: Record<string, [string, "foreground" | "background"]> = {
INDENT_GUIDE: ["indentGuide", "foreground"],
RIGHT_MARGIN_COLOR: ["rightMargin", "foreground"],
METHOD_SEPARATORS_COLOR: ["methodSeparator", "foreground"],
CONSOLE_BACKGROUND_KEY: ["consoleBackground", "background"],
};
Object.assign(ATTRIBUTE_NAMES, {
CONSOLE_BLACK_OUTPUT: "ansiBlack",
CONSOLE_RED_OUTPUT: "ansiRed",
CONSOLE_GREEN_OUTPUT: "ansiGreen",
CONSOLE_YELLOW_OUTPUT: "ansiYellow",
CONSOLE_BLUE_OUTPUT: "ansiBlue",
CONSOLE_MAGENTA_OUTPUT: "ansiMagenta",
CONSOLE_CYAN_OUTPUT: "ansiCyan",
CONSOLE_GRAY_OUTPUT: "ansiWhite",
CONSOLE_DARKGRAY_OUTPUT: "ansiBrightBlack",
CONSOLE_RED_BRIGHT_OUTPUT: "ansiBrightRed",
CONSOLE_GREEN_BRIGHT_OUTPUT: "ansiBrightGreen",
CONSOLE_YELLOW_BRIGHT_OUTPUT: "ansiBrightYellow",
CONSOLE_BLUE_BRIGHT_OUTPUT: "ansiBrightBlue",
CONSOLE_MAGENTA_BRIGHT_OUTPUT: "ansiBrightMagenta",
CONSOLE_CYAN_BRIGHT_OUTPUT: "ansiBrightCyan",
CONSOLE_WHITE_OUTPUT: "ansiBrightWhite",
});
// Preserve editor attributes without a standard exchange name on our own round trip.
for (const attr of ATTRIBUTES)
if (!Object.values(ATTRIBUTE_NAMES).includes(attr.id)) ATTRIBUTE_NAMES[`OPENIDEA_${attr.id}`] = attr.id;
+14
Переглянути файл
@@ -1,10 +1,24 @@
{
"Black": "Black",
"Bright blue": "Bright blue",
"Bright cyan": "Bright cyan",
"Bright green": "Bright green",
"Bright magenta": "Bright magenta",
"Bright red": "Bright red",
"Bright white": "Bright white",
"Bright yellow": "Bright yellow",
"Console Colors": "Console Colors",
"Console background": "Console background",
"Cyan": "Cyan",
"Dark gray": "Dark gray",
"Magenta": "Magenta",
"The program ended by itself, so no garbage collection ran before the profile was written: objects that were already unreachable may show as live.": "The program ended by itself, so no garbage collection ran before the profile was written: objects that were already unreachable may show as live.",
"No garbage collection finished before the program stopped (the JVM's attach listener did not answer in time or was not reachable): objects that were already unreachable may show as live.": "No garbage collection finished before the program stopped (the JVM's attach listener did not answer in time or was not reachable): objects that were already unreachable may show as live.",
"Profile Allocations": "Profile Allocations",
"Profile Live Objects": "Profile Live Objects",
"Allocations": "Allocations",
"Live Objects": "Live Objects",
"White": "White",
"allocated": "allocated",
"{size} allocated": "{size} allocated",
"1 live sample (≈ 512 KB)": "1 live sample (≈ 512 KB)",
+14
Переглянути файл
@@ -1,10 +1,24 @@
{
"Black": "黑色",
"Bright blue": "亮蓝色",
"Bright cyan": "亮青色",
"Bright green": "亮绿色",
"Bright magenta": "亮品红色",
"Bright red": "亮红色",
"Bright white": "亮白色",
"Bright yellow": "亮黄色",
"Console Colors": "控制台颜色",
"Console background": "控制台背景",
"Cyan": "青色",
"Dark gray": "深灰色",
"Magenta": "品红色",
"The program ended by itself, so no garbage collection ran before the profile was written: objects that were already unreachable may show as live.": "程序自行结束,因此在写入分析结果前没有执行垃圾回收:本已不可达的对象可能显示为存活。",
"No garbage collection finished before the program stopped (the JVM's attach listener did not answer in time or was not reachable): objects that were already unreachable may show as live.": "程序停止前没有完成垃圾回收(JVM 的 attach 监听器未及时响应或无法访问):本已不可达的对象可能显示为存活。",
"Profile Allocations": "分析内存分配",
"Profile Live Objects": "分析存活对象",
"Allocations": "内存分配",
"Live Objects": "存活对象",
"White": "白色",
"allocated": "已分配",
"{size} allocated": "已分配 {size}",
"1 live sample (≈ 512 KB)": "1 个存活样本(≈ 512 KB)",