icoa-cli 2.19.24 → 2.19.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/theme.js +28 -13
- package/package.json +1 -1
package/dist/lib/theme.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
// Unified Darcula terminal theme — works
|
|
2
|
-
//
|
|
1
|
+
// Unified Darcula terminal theme — works across macOS Terminal.app, iTerm2,
|
|
2
|
+
// GNOME Terminal, Konsole, Windows Terminal (cmd/PowerShell/WSL).
|
|
3
3
|
//
|
|
4
|
-
//
|
|
4
|
+
// Three mechanisms are combined so every modern terminal gets the best it can:
|
|
5
5
|
//
|
|
6
6
|
// 1. OSC 10/11/12 sets the terminal's *default* fg/bg/cursor colors.
|
|
7
7
|
// Honored by iTerm2, GNOME Terminal, Konsole, Windows Terminal → lossless
|
|
8
|
-
// background, no scrollback or resize artifacts. Ignored by
|
|
9
|
-
// Terminal.app.
|
|
8
|
+
// background, no scrollback or resize artifacts. Ignored by Terminal.app.
|
|
10
9
|
//
|
|
11
|
-
// 2. SGR 38/48 + \x1b[2J paints
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
10
|
+
// 2. SGR 38;2/48;2 + \x1b[2J paints with 24-bit truecolor Darcula on every
|
|
11
|
+
// terminal that supports truecolor. This is the default path.
|
|
12
|
+
//
|
|
13
|
+
// 3. SGR 38;5/48;5 + \x1b[2J paints with 256-color approximation on macOS
|
|
14
|
+
// Terminal.app. Terminal.app does NOT support truecolor SGR and mis-parses
|
|
15
|
+
// `\x1b[48;2;43;43;43m` as a sequence of 16-color codes — the trailing
|
|
16
|
+
// `43` becomes ANSI "bg yellow", which is why v2.19.23/24 rendered with a
|
|
17
|
+
// yellow background there. Color 235 ≈ #262626 (dark gray, ~#2B2B2B) and
|
|
18
|
+
// color 250 ≈ #BCBCBC (light gray, ~#A9B7C6) are close enough.
|
|
15
19
|
//
|
|
16
20
|
// Legacy cmd.exe (pre-Win10 1809) can't run Node 22 anyway, so no separate
|
|
17
21
|
// fallback path is needed.
|
|
@@ -21,10 +25,14 @@ const OSC_INIT = '\x1b]10;#A9B7C6\x07' + // default fg
|
|
|
21
25
|
const OSC_RESET = '\x1b]110\x07' + // reset default fg
|
|
22
26
|
'\x1b]111\x07' + // reset default bg
|
|
23
27
|
'\x1b]112\x07'; // reset cursor color
|
|
24
|
-
const
|
|
28
|
+
const SGR_INIT_TRUECOLOR = '\x1b[38;2;169;183;198m' + // fg #A9B7C6
|
|
25
29
|
'\x1b[48;2;43;43;43m' + // bg #2B2B2B
|
|
26
|
-
'\x1b[2J' +
|
|
27
|
-
'\x1b[H';
|
|
30
|
+
'\x1b[2J' +
|
|
31
|
+
'\x1b[H';
|
|
32
|
+
const SGR_INIT_256 = '\x1b[38;5;250m' + // fg ≈ #BCBCBC
|
|
33
|
+
'\x1b[48;5;235m' + // bg ≈ #262626
|
|
34
|
+
'\x1b[2J' +
|
|
35
|
+
'\x1b[H';
|
|
28
36
|
const SGR_RESET = '\x1b[0m\x1b[2J\x1b[H';
|
|
29
37
|
function supportsAnsi() {
|
|
30
38
|
if (!process.stdout.isTTY)
|
|
@@ -43,13 +51,20 @@ function supportsAnsi() {
|
|
|
43
51
|
function isIcoaTerminal() {
|
|
44
52
|
return process.env.ICOA_TERMINAL === '1';
|
|
45
53
|
}
|
|
54
|
+
// macOS Terminal.app does not implement SGR truecolor (\x1b[38;2;… / \x1b[48;2;…)
|
|
55
|
+
// and mis-parses those sequences as 16-color codes, producing e.g. a yellow bg.
|
|
56
|
+
// Detect it and fall back to 256-color SGR which Terminal.app handles correctly.
|
|
57
|
+
function isAppleTerminal() {
|
|
58
|
+
return process.env.TERM_PROGRAM === 'Apple_Terminal';
|
|
59
|
+
}
|
|
46
60
|
let armed = false;
|
|
47
61
|
export function setTerminalTheme() {
|
|
48
62
|
if (!supportsAnsi())
|
|
49
63
|
return;
|
|
50
64
|
if (isIcoaTerminal())
|
|
51
65
|
return; // host is already Darcula; nothing to do
|
|
52
|
-
|
|
66
|
+
const sgr = isAppleTerminal() ? SGR_INIT_256 : SGR_INIT_TRUECOLOR;
|
|
67
|
+
process.stdout.write(OSC_INIT + sgr);
|
|
53
68
|
if (!armed) {
|
|
54
69
|
armed = true;
|
|
55
70
|
// Belt-and-braces cleanup on every exit path. Without these, Ctrl+C leaves
|