colorino 0.3.3 → 0.5.0
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/README.md +148 -81
- package/dist/browser.cjs +23 -13
- package/dist/browser.d.cts +3 -4
- package/dist/browser.d.mts +3 -4
- package/dist/browser.d.ts +3 -4
- package/dist/browser.mjs +17 -7
- package/dist/node.cjs +94 -79
- package/dist/node.d.cts +3 -4
- package/dist/node.d.mts +3 -4
- package/dist/node.d.ts +3 -4
- package/dist/node.mjs +75 -60
- package/dist/shared/colorino.B1MNcUze.d.cts +455 -0
- package/dist/shared/colorino.B1MNcUze.d.mts +455 -0
- package/dist/shared/colorino.B1MNcUze.d.ts +455 -0
- package/dist/shared/colorino.B9WUj1qg.cjs +777 -0
- package/dist/shared/colorino.CsFoITs1.mjs +768 -0
- package/package.json +16 -13
- package/dist/shared/colorino.Ddpe9uIB.d.cts +0 -89
- package/dist/shared/colorino.Ddpe9uIB.d.mts +0 -89
- package/dist/shared/colorino.Ddpe9uIB.d.ts +0 -89
- package/dist/shared/colorino.gkk2eRGY.cjs +0 -219
- package/dist/shared/colorino.iQv4mlpl.mjs +0 -213
package/dist/node.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const neverthrow = require('neverthrow');
|
|
3
|
+
const determineBaseTheme = require('./shared/colorino.B9WUj1qg.cjs');
|
|
5
4
|
|
|
6
5
|
class OscThemeQuerier {
|
|
7
6
|
constructor(_stdin, _stdout, _timeout = 300, _cacheTtl = 36e5) {
|
|
@@ -10,64 +9,67 @@ class OscThemeQuerier {
|
|
|
10
9
|
this._timeout = _timeout;
|
|
11
10
|
this._cacheTtl = _cacheTtl;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
_cachedResult;
|
|
13
|
+
_cacheTimestamp;
|
|
14
|
+
query() {
|
|
16
15
|
if (!this._stdout.isTTY || typeof this._stdin.setRawMode !== "function") {
|
|
17
|
-
return
|
|
16
|
+
return determineBaseTheme.err(new determineBaseTheme.OscQueryError("Not a TTY environment"));
|
|
18
17
|
}
|
|
19
18
|
const now = Date.now();
|
|
20
|
-
if (this.
|
|
21
|
-
return this.
|
|
19
|
+
if (this._cachedResult !== void 0 && this._cacheTimestamp !== void 0 && now - this._cacheTimestamp < this._cacheTtl) {
|
|
20
|
+
return this._cachedResult;
|
|
22
21
|
}
|
|
23
|
-
const result =
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
22
|
+
const result = this._performQuery();
|
|
23
|
+
this._cachedResult = result;
|
|
24
|
+
this._cacheTimestamp = now;
|
|
26
25
|
return result;
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
const onData = (chunk) => {
|
|
27
|
+
_performQuery() {
|
|
28
|
+
const originalRawMode = this._stdin.isRaw;
|
|
29
|
+
let buffer = "";
|
|
30
|
+
this._stdin.setRawMode(true);
|
|
31
|
+
this._stdin.resume();
|
|
32
|
+
this._stdout.write("\x1B]11;?\x1B\\");
|
|
33
|
+
const startTime = Date.now();
|
|
34
|
+
const pollInterval = 10;
|
|
35
|
+
while (Date.now() - startTime < this._timeout) {
|
|
36
|
+
const chunk = this._stdin.read();
|
|
37
|
+
if (chunk !== null) {
|
|
41
38
|
buffer += chunk.toString();
|
|
42
39
|
const parseResult = this._parseResponse(buffer);
|
|
43
40
|
if (parseResult.isOk()) {
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
this._cleanup(originalRawMode);
|
|
42
|
+
return parseResult;
|
|
46
43
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
}
|
|
45
|
+
this._sleepSync(pollInterval);
|
|
46
|
+
}
|
|
47
|
+
this._cleanup(originalRawMode);
|
|
48
|
+
return determineBaseTheme.err(
|
|
49
|
+
new determineBaseTheme.OscQueryError("OSC query timeout - terminal did not respond")
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
_cleanup(originalRawMode) {
|
|
53
|
+
this._stdin.setRawMode(originalRawMode);
|
|
54
|
+
this._stdin.pause();
|
|
55
|
+
}
|
|
56
|
+
_sleepSync(ms) {
|
|
57
|
+
const buffer = new SharedArrayBuffer(4);
|
|
58
|
+
const view = new Int32Array(buffer);
|
|
59
|
+
Atomics.wait(view, 0, 0, ms);
|
|
58
60
|
}
|
|
59
61
|
_parseResponse(response) {
|
|
60
62
|
const rgbMatch = response.match(
|
|
61
63
|
/rgb:([0-9a-f]{2,4})\/([0-9a-f]{2,4})\/([0-9a-f]{2,4})/i
|
|
62
64
|
);
|
|
63
65
|
if (!rgbMatch) {
|
|
64
|
-
return
|
|
66
|
+
return determineBaseTheme.err(new determineBaseTheme.OscQueryError("No valid OSC response found in buffer"));
|
|
65
67
|
}
|
|
66
68
|
const red = this._normalizeHex(rgbMatch[1]);
|
|
67
69
|
const green = this._normalizeHex(rgbMatch[2]);
|
|
68
70
|
const blue = this._normalizeHex(rgbMatch[3]);
|
|
69
71
|
const luminance = this._calculateLuminance(red, green, blue);
|
|
70
|
-
return
|
|
72
|
+
return determineBaseTheme.ok(luminance < 0.5 ? "dark" : "light");
|
|
71
73
|
}
|
|
72
74
|
_normalizeHex(hexValue) {
|
|
73
75
|
const normalized = hexValue.padEnd(4, "0").slice(0, 2);
|
|
@@ -81,7 +83,10 @@ class OscThemeQuerier {
|
|
|
81
83
|
class NodeColorSupportDetector {
|
|
82
84
|
constructor(_process, overrideTheme) {
|
|
83
85
|
this._process = _process;
|
|
84
|
-
if (!this.isNodeEnv())
|
|
86
|
+
if (!this.isNodeEnv()) {
|
|
87
|
+
this._theme = "unknown";
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
85
90
|
const processEnv = _process.env;
|
|
86
91
|
this._envForceColor = processEnv["FORCE_COLOR"];
|
|
87
92
|
this._envNoColor = processEnv["NO_COLOR"];
|
|
@@ -91,13 +96,20 @@ class NodeColorSupportDetector {
|
|
|
91
96
|
this._envCliColorForce = processEnv["CLICOLOR_FORCE"];
|
|
92
97
|
this._envWtSession = processEnv["WT_SESSION"];
|
|
93
98
|
this._isTTY = !!_process.stdout.isTTY;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
if (overrideTheme !== void 0) {
|
|
100
|
+
this._theme = overrideTheme;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (!this._isTTY) {
|
|
104
|
+
this._theme = "unknown";
|
|
105
|
+
return;
|
|
100
106
|
}
|
|
107
|
+
const querier = new OscThemeQuerier(
|
|
108
|
+
_process.stdin,
|
|
109
|
+
_process.stdout
|
|
110
|
+
);
|
|
111
|
+
const result = querier.query();
|
|
112
|
+
this._theme = result.isOk() ? result.value : "unknown";
|
|
101
113
|
}
|
|
102
114
|
_envForceColor;
|
|
103
115
|
_envTerm;
|
|
@@ -107,79 +119,82 @@ class NodeColorSupportDetector {
|
|
|
107
119
|
_envCliColorForce;
|
|
108
120
|
_envWtSession;
|
|
109
121
|
_isTTY;
|
|
110
|
-
|
|
111
|
-
_overrideTheme;
|
|
122
|
+
_theme;
|
|
112
123
|
isNodeEnv() {
|
|
113
124
|
return typeof this._process !== "undefined";
|
|
114
125
|
}
|
|
126
|
+
getTheme() {
|
|
127
|
+
return this._theme;
|
|
128
|
+
}
|
|
115
129
|
getColorLevel() {
|
|
116
130
|
if (this._envNoColor !== void 0) {
|
|
117
|
-
return
|
|
131
|
+
return determineBaseTheme.ColorLevel.NO_COLOR;
|
|
118
132
|
}
|
|
119
133
|
if (this._envForceColor !== void 0) {
|
|
120
134
|
if (this._envForceColor === "0" || this._envForceColor === "false") {
|
|
121
|
-
return
|
|
135
|
+
return determineBaseTheme.ColorLevel.NO_COLOR;
|
|
122
136
|
}
|
|
123
137
|
if (this._envForceColor === "1" || this._envForceColor === "true") {
|
|
124
|
-
return
|
|
138
|
+
return determineBaseTheme.ColorLevel.ANSI;
|
|
125
139
|
}
|
|
126
140
|
const level = parseInt(this._envForceColor, 10);
|
|
127
141
|
if (level >= 0 && level <= 3) {
|
|
128
142
|
return level;
|
|
129
143
|
}
|
|
130
|
-
return
|
|
144
|
+
return determineBaseTheme.ColorLevel.ANSI;
|
|
131
145
|
}
|
|
132
146
|
const isForced = this._envCliColorForce !== void 0 && this._envCliColorForce !== "0";
|
|
133
147
|
if (!this._isTTY && !isForced) {
|
|
134
|
-
return
|
|
148
|
+
return determineBaseTheme.ColorLevel.NO_COLOR;
|
|
135
149
|
}
|
|
136
150
|
if (this._envTerm === "dumb") {
|
|
137
|
-
return
|
|
151
|
+
return determineBaseTheme.ColorLevel.NO_COLOR;
|
|
138
152
|
}
|
|
139
153
|
if (this._envColorTerm === "truecolor" || this._envColorTerm === "24bit") {
|
|
140
|
-
return
|
|
154
|
+
return determineBaseTheme.ColorLevel.TRUECOLOR;
|
|
141
155
|
}
|
|
142
156
|
if (this._envWtSession !== void 0) {
|
|
143
|
-
return
|
|
157
|
+
return determineBaseTheme.ColorLevel.TRUECOLOR;
|
|
144
158
|
}
|
|
145
159
|
if (this._envTerm) {
|
|
146
|
-
if (/^xterm-kitty$/.test(this._envTerm) || /^xterm-ghostty$/.test(this._envTerm) || /^wezterm$/.test(this._envTerm) ||
|
|
147
|
-
return
|
|
160
|
+
if (/^xterm-kitty$/.test(this._envTerm) || /^xterm-ghostty$/.test(this._envTerm) || /^wezterm$/.test(this._envTerm) || this._envTerm.endsWith("-truecolor")) {
|
|
161
|
+
return determineBaseTheme.ColorLevel.TRUECOLOR;
|
|
148
162
|
}
|
|
149
163
|
if (/-256(color)?$/i.test(this._envTerm)) {
|
|
150
|
-
return
|
|
164
|
+
return determineBaseTheme.ColorLevel.ANSI256;
|
|
151
165
|
}
|
|
152
166
|
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(
|
|
153
167
|
this._envTerm
|
|
154
168
|
)) {
|
|
155
|
-
return
|
|
169
|
+
return determineBaseTheme.ColorLevel.ANSI;
|
|
156
170
|
}
|
|
157
171
|
}
|
|
158
172
|
if (this._envColorTerm) {
|
|
159
|
-
return
|
|
173
|
+
return determineBaseTheme.ColorLevel.ANSI;
|
|
160
174
|
}
|
|
161
175
|
if (this._envCliColor !== void 0 && this._envCliColor !== "0") {
|
|
162
|
-
return
|
|
176
|
+
return determineBaseTheme.ColorLevel.ANSI;
|
|
163
177
|
}
|
|
164
|
-
return this._isTTY || isForced ?
|
|
165
|
-
}
|
|
166
|
-
async getTheme() {
|
|
167
|
-
if (this._overrideTheme) {
|
|
168
|
-
return this._overrideTheme;
|
|
169
|
-
}
|
|
170
|
-
if (!this.isNodeEnv() || !this._isTTY || !this._querier) {
|
|
171
|
-
return "unknown";
|
|
172
|
-
}
|
|
173
|
-
const result = await this._querier.query();
|
|
174
|
-
return result.unwrapOr("unknown");
|
|
178
|
+
return this._isTTY || isForced ? determineBaseTheme.ColorLevel.ANSI : determineBaseTheme.ColorLevel.NO_COLOR;
|
|
175
179
|
}
|
|
176
180
|
}
|
|
177
181
|
|
|
178
|
-
function createColorino(palette, options = {}) {
|
|
179
|
-
const validator = new
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
182
|
+
function createColorino(palette = {}, options = {}) {
|
|
183
|
+
const validator = new determineBaseTheme.InputValidator();
|
|
184
|
+
let detectorThemeOverride;
|
|
185
|
+
if (options.theme === "dark" || options.theme === "light") {
|
|
186
|
+
detectorThemeOverride = options.theme;
|
|
187
|
+
}
|
|
188
|
+
const nodeDetector = new NodeColorSupportDetector(
|
|
189
|
+
process,
|
|
190
|
+
detectorThemeOverride
|
|
191
|
+
);
|
|
192
|
+
const detectedTerminalTheme = nodeDetector.getTheme();
|
|
193
|
+
const themeOpt = options.theme ?? "auto";
|
|
194
|
+
const baseThemeName = determineBaseTheme.determineBaseTheme(themeOpt, detectedTerminalTheme);
|
|
195
|
+
const basePalette = determineBaseTheme.themePalettes[baseThemeName];
|
|
196
|
+
const finalPalette = { ...basePalette, ...palette };
|
|
197
|
+
return new determineBaseTheme.Colorino(
|
|
183
198
|
finalPalette,
|
|
184
199
|
validator,
|
|
185
200
|
void 0,
|
|
@@ -189,7 +204,7 @@ function createColorino(palette, options = {}) {
|
|
|
189
204
|
options
|
|
190
205
|
);
|
|
191
206
|
}
|
|
192
|
-
const colorino = createColorino(
|
|
207
|
+
const colorino = createColorino();
|
|
193
208
|
|
|
194
209
|
exports.colorino = colorino;
|
|
195
210
|
exports.createColorino = createColorino;
|
package/dist/node.d.cts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.
|
|
2
|
-
export { L as LogLevel, T as
|
|
3
|
-
import 'neverthrow';
|
|
1
|
+
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.B1MNcUze.cjs';
|
|
2
|
+
export { L as LogLevel, T as ThemeName } from './shared/colorino.B1MNcUze.cjs';
|
|
4
3
|
|
|
5
|
-
declare function createColorino(palette
|
|
4
|
+
declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
6
5
|
|
|
7
6
|
declare const colorino: Colorino;
|
|
8
7
|
|
package/dist/node.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.
|
|
2
|
-
export { L as LogLevel, T as
|
|
3
|
-
import 'neverthrow';
|
|
1
|
+
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.B1MNcUze.mjs';
|
|
2
|
+
export { L as LogLevel, T as ThemeName } from './shared/colorino.B1MNcUze.mjs';
|
|
4
3
|
|
|
5
|
-
declare function createColorino(palette
|
|
4
|
+
declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
6
5
|
|
|
7
6
|
declare const colorino: Colorino;
|
|
8
7
|
|
package/dist/node.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.
|
|
2
|
-
export { L as LogLevel, T as
|
|
3
|
-
import 'neverthrow';
|
|
1
|
+
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.B1MNcUze.js';
|
|
2
|
+
export { L as LogLevel, T as ThemeName } from './shared/colorino.B1MNcUze.js';
|
|
4
3
|
|
|
5
|
-
declare function createColorino(palette
|
|
4
|
+
declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
6
5
|
|
|
7
6
|
declare const colorino: Colorino;
|
|
8
7
|
|
package/dist/node.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { O as OscQueryError, C as ColorLevel, d as
|
|
2
|
-
import { err, ok } from 'neverthrow';
|
|
1
|
+
import { e as err, O as OscQueryError, o as ok, C as ColorLevel, d as determineBaseTheme, t as themePalettes, a as Colorino, I as InputValidator } from './shared/colorino.CsFoITs1.mjs';
|
|
3
2
|
|
|
4
3
|
class OscThemeQuerier {
|
|
5
4
|
constructor(_stdin, _stdout, _timeout = 300, _cacheTtl = 36e5) {
|
|
@@ -8,51 +7,54 @@ class OscThemeQuerier {
|
|
|
8
7
|
this._timeout = _timeout;
|
|
9
8
|
this._cacheTtl = _cacheTtl;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
_cachedResult;
|
|
11
|
+
_cacheTimestamp;
|
|
12
|
+
query() {
|
|
14
13
|
if (!this._stdout.isTTY || typeof this._stdin.setRawMode !== "function") {
|
|
15
14
|
return err(new OscQueryError("Not a TTY environment"));
|
|
16
15
|
}
|
|
17
16
|
const now = Date.now();
|
|
18
|
-
if (this.
|
|
19
|
-
return this.
|
|
17
|
+
if (this._cachedResult !== void 0 && this._cacheTimestamp !== void 0 && now - this._cacheTimestamp < this._cacheTtl) {
|
|
18
|
+
return this._cachedResult;
|
|
20
19
|
}
|
|
21
|
-
const result =
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
20
|
+
const result = this._performQuery();
|
|
21
|
+
this._cachedResult = result;
|
|
22
|
+
this._cacheTimestamp = now;
|
|
24
23
|
return result;
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
const onData = (chunk) => {
|
|
25
|
+
_performQuery() {
|
|
26
|
+
const originalRawMode = this._stdin.isRaw;
|
|
27
|
+
let buffer = "";
|
|
28
|
+
this._stdin.setRawMode(true);
|
|
29
|
+
this._stdin.resume();
|
|
30
|
+
this._stdout.write("\x1B]11;?\x1B\\");
|
|
31
|
+
const startTime = Date.now();
|
|
32
|
+
const pollInterval = 10;
|
|
33
|
+
while (Date.now() - startTime < this._timeout) {
|
|
34
|
+
const chunk = this._stdin.read();
|
|
35
|
+
if (chunk !== null) {
|
|
39
36
|
buffer += chunk.toString();
|
|
40
37
|
const parseResult = this._parseResponse(buffer);
|
|
41
38
|
if (parseResult.isOk()) {
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
this._cleanup(originalRawMode);
|
|
40
|
+
return parseResult;
|
|
44
41
|
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
}
|
|
43
|
+
this._sleepSync(pollInterval);
|
|
44
|
+
}
|
|
45
|
+
this._cleanup(originalRawMode);
|
|
46
|
+
return err(
|
|
47
|
+
new OscQueryError("OSC query timeout - terminal did not respond")
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
_cleanup(originalRawMode) {
|
|
51
|
+
this._stdin.setRawMode(originalRawMode);
|
|
52
|
+
this._stdin.pause();
|
|
53
|
+
}
|
|
54
|
+
_sleepSync(ms) {
|
|
55
|
+
const buffer = new SharedArrayBuffer(4);
|
|
56
|
+
const view = new Int32Array(buffer);
|
|
57
|
+
Atomics.wait(view, 0, 0, ms);
|
|
56
58
|
}
|
|
57
59
|
_parseResponse(response) {
|
|
58
60
|
const rgbMatch = response.match(
|
|
@@ -79,7 +81,10 @@ class OscThemeQuerier {
|
|
|
79
81
|
class NodeColorSupportDetector {
|
|
80
82
|
constructor(_process, overrideTheme) {
|
|
81
83
|
this._process = _process;
|
|
82
|
-
if (!this.isNodeEnv())
|
|
84
|
+
if (!this.isNodeEnv()) {
|
|
85
|
+
this._theme = "unknown";
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
83
88
|
const processEnv = _process.env;
|
|
84
89
|
this._envForceColor = processEnv["FORCE_COLOR"];
|
|
85
90
|
this._envNoColor = processEnv["NO_COLOR"];
|
|
@@ -89,13 +94,20 @@ class NodeColorSupportDetector {
|
|
|
89
94
|
this._envCliColorForce = processEnv["CLICOLOR_FORCE"];
|
|
90
95
|
this._envWtSession = processEnv["WT_SESSION"];
|
|
91
96
|
this._isTTY = !!_process.stdout.isTTY;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
if (overrideTheme !== void 0) {
|
|
98
|
+
this._theme = overrideTheme;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (!this._isTTY) {
|
|
102
|
+
this._theme = "unknown";
|
|
103
|
+
return;
|
|
98
104
|
}
|
|
105
|
+
const querier = new OscThemeQuerier(
|
|
106
|
+
_process.stdin,
|
|
107
|
+
_process.stdout
|
|
108
|
+
);
|
|
109
|
+
const result = querier.query();
|
|
110
|
+
this._theme = result.isOk() ? result.value : "unknown";
|
|
99
111
|
}
|
|
100
112
|
_envForceColor;
|
|
101
113
|
_envTerm;
|
|
@@ -105,11 +117,13 @@ class NodeColorSupportDetector {
|
|
|
105
117
|
_envCliColorForce;
|
|
106
118
|
_envWtSession;
|
|
107
119
|
_isTTY;
|
|
108
|
-
|
|
109
|
-
_overrideTheme;
|
|
120
|
+
_theme;
|
|
110
121
|
isNodeEnv() {
|
|
111
122
|
return typeof this._process !== "undefined";
|
|
112
123
|
}
|
|
124
|
+
getTheme() {
|
|
125
|
+
return this._theme;
|
|
126
|
+
}
|
|
113
127
|
getColorLevel() {
|
|
114
128
|
if (this._envNoColor !== void 0) {
|
|
115
129
|
return ColorLevel.NO_COLOR;
|
|
@@ -141,7 +155,7 @@ class NodeColorSupportDetector {
|
|
|
141
155
|
return ColorLevel.TRUECOLOR;
|
|
142
156
|
}
|
|
143
157
|
if (this._envTerm) {
|
|
144
|
-
if (/^xterm-kitty$/.test(this._envTerm) || /^xterm-ghostty$/.test(this._envTerm) || /^wezterm$/.test(this._envTerm) ||
|
|
158
|
+
if (/^xterm-kitty$/.test(this._envTerm) || /^xterm-ghostty$/.test(this._envTerm) || /^wezterm$/.test(this._envTerm) || this._envTerm.endsWith("-truecolor")) {
|
|
145
159
|
return ColorLevel.TRUECOLOR;
|
|
146
160
|
}
|
|
147
161
|
if (/-256(color)?$/i.test(this._envTerm)) {
|
|
@@ -161,22 +175,23 @@ class NodeColorSupportDetector {
|
|
|
161
175
|
}
|
|
162
176
|
return this._isTTY || isForced ? ColorLevel.ANSI : ColorLevel.NO_COLOR;
|
|
163
177
|
}
|
|
164
|
-
async getTheme() {
|
|
165
|
-
if (this._overrideTheme) {
|
|
166
|
-
return this._overrideTheme;
|
|
167
|
-
}
|
|
168
|
-
if (!this.isNodeEnv() || !this._isTTY || !this._querier) {
|
|
169
|
-
return "unknown";
|
|
170
|
-
}
|
|
171
|
-
const result = await this._querier.query();
|
|
172
|
-
return result.unwrapOr("unknown");
|
|
173
|
-
}
|
|
174
178
|
}
|
|
175
179
|
|
|
176
|
-
function createColorino(palette, options = {}) {
|
|
180
|
+
function createColorino(palette = {}, options = {}) {
|
|
177
181
|
const validator = new InputValidator();
|
|
178
|
-
|
|
179
|
-
|
|
182
|
+
let detectorThemeOverride;
|
|
183
|
+
if (options.theme === "dark" || options.theme === "light") {
|
|
184
|
+
detectorThemeOverride = options.theme;
|
|
185
|
+
}
|
|
186
|
+
const nodeDetector = new NodeColorSupportDetector(
|
|
187
|
+
process,
|
|
188
|
+
detectorThemeOverride
|
|
189
|
+
);
|
|
190
|
+
const detectedTerminalTheme = nodeDetector.getTheme();
|
|
191
|
+
const themeOpt = options.theme ?? "auto";
|
|
192
|
+
const baseThemeName = determineBaseTheme(themeOpt, detectedTerminalTheme);
|
|
193
|
+
const basePalette = themePalettes[baseThemeName];
|
|
194
|
+
const finalPalette = { ...basePalette, ...palette };
|
|
180
195
|
return new Colorino(
|
|
181
196
|
finalPalette,
|
|
182
197
|
validator,
|
|
@@ -187,6 +202,6 @@ function createColorino(palette, options = {}) {
|
|
|
187
202
|
options
|
|
188
203
|
);
|
|
189
204
|
}
|
|
190
|
-
const colorino = createColorino(
|
|
205
|
+
const colorino = createColorino();
|
|
191
206
|
|
|
192
207
|
export { colorino, createColorino };
|