colorino 0.3.2 → 0.4.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 -12
- package/dist/browser.d.cts +3 -3
- package/dist/browser.d.mts +3 -3
- package/dist/browser.d.ts +3 -3
- package/dist/browser.mjs +17 -6
- package/dist/node.cjs +58 -110
- package/dist/node.d.cts +3 -3
- package/dist/node.d.mts +3 -3
- package/dist/node.d.ts +3 -3
- package/dist/node.mjs +42 -95
- package/dist/shared/{colorino.iQv4mlpl.mjs → colorino.B16XJPJ-.mjs} +80 -12
- package/dist/shared/{colorino.gkk2eRGY.cjs → colorino.BUBv72sF.cjs} +81 -13
- package/dist/shared/{colorino.Ddpe9uIB.d.cts → colorino.ODiKA7Gy.d.cts} +12 -12
- package/dist/shared/{colorino.Ddpe9uIB.d.mts → colorino.ODiKA7Gy.d.mts} +12 -12
- package/dist/shared/{colorino.Ddpe9uIB.d.ts → colorino.ODiKA7Gy.d.ts} +12 -12
- package/package.json +4 -4
package/dist/node.cjs
CHANGED
|
@@ -1,83 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const determineBaseTheme = require('./shared/colorino.BUBv72sF.cjs');
|
|
4
|
+
const node_url = require('node:url');
|
|
5
|
+
const node_child_process = require('node:child_process');
|
|
6
|
+
const node_path = require('node:path');
|
|
4
7
|
const neverthrow = require('neverthrow');
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
constructor(_stdin, _stdout, _timeout = 300, _cacheTtl = 36e5) {
|
|
8
|
-
this._stdin = _stdin;
|
|
9
|
-
this._stdout = _stdout;
|
|
10
|
-
this._timeout = _timeout;
|
|
11
|
-
this._cacheTtl = _cacheTtl;
|
|
12
|
-
}
|
|
13
|
-
cachedResult;
|
|
14
|
-
cacheTimestamp;
|
|
15
|
-
async query() {
|
|
16
|
-
if (!this._stdout.isTTY || typeof this._stdin.setRawMode !== "function") {
|
|
17
|
-
return neverthrow.err(new theme.OscQueryError("Not a TTY environment"));
|
|
18
|
-
}
|
|
19
|
-
const now = Date.now();
|
|
20
|
-
if (this.cachedResult !== void 0 && this.cacheTimestamp !== void 0 && now - this.cacheTimestamp < this._cacheTtl) {
|
|
21
|
-
return this.cachedResult;
|
|
22
|
-
}
|
|
23
|
-
const result = await this._performQuery();
|
|
24
|
-
this.cachedResult = result;
|
|
25
|
-
this.cacheTimestamp = now;
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
async _performQuery() {
|
|
29
|
-
return new Promise((resolve) => {
|
|
30
|
-
const originalRawMode = this._stdin.isRaw;
|
|
31
|
-
let buffer = "";
|
|
32
|
-
let isResolved = false;
|
|
33
|
-
const cleanup = () => {
|
|
34
|
-
if (isResolved) return;
|
|
35
|
-
isResolved = true;
|
|
36
|
-
clearTimeout(timer);
|
|
37
|
-
this._stdin.removeListener("data", onData);
|
|
38
|
-
this._stdin.setRawMode(originalRawMode);
|
|
39
|
-
};
|
|
40
|
-
const onData = (chunk) => {
|
|
41
|
-
buffer += chunk.toString();
|
|
42
|
-
const parseResult = this._parseResponse(buffer);
|
|
43
|
-
if (parseResult.isOk()) {
|
|
44
|
-
cleanup();
|
|
45
|
-
resolve(parseResult);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const timer = setTimeout(() => {
|
|
49
|
-
cleanup();
|
|
50
|
-
resolve(
|
|
51
|
-
neverthrow.err(new theme.OscQueryError("OSC query timeout - terminal did not respond"))
|
|
52
|
-
);
|
|
53
|
-
}, this._timeout);
|
|
54
|
-
this._stdin.setRawMode(true);
|
|
55
|
-
this._stdin.on("data", onData);
|
|
56
|
-
this._stdout.write("\x1B]11;?\x1B\\");
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
_parseResponse(response) {
|
|
60
|
-
const rgbMatch = response.match(
|
|
61
|
-
/rgb:([0-9a-f]{2,4})\/([0-9a-f]{2,4})\/([0-9a-f]{2,4})/i
|
|
62
|
-
);
|
|
63
|
-
if (!rgbMatch) {
|
|
64
|
-
return neverthrow.err(new theme.OscQueryError("No valid OSC response found in buffer"));
|
|
65
|
-
}
|
|
66
|
-
const red = this._normalizeHex(rgbMatch[1]);
|
|
67
|
-
const green = this._normalizeHex(rgbMatch[2]);
|
|
68
|
-
const blue = this._normalizeHex(rgbMatch[3]);
|
|
69
|
-
const luminance = this._calculateLuminance(red, green, blue);
|
|
70
|
-
return neverthrow.ok(luminance < 0.5 ? "dark" : "light");
|
|
71
|
-
}
|
|
72
|
-
_normalizeHex(hexValue) {
|
|
73
|
-
const normalized = hexValue.padEnd(4, "0").slice(0, 2);
|
|
74
|
-
return parseInt(normalized, 16);
|
|
75
|
-
}
|
|
76
|
-
_calculateLuminance(red, green, blue) {
|
|
77
|
-
return (0.299 * red + 0.587 * green + 0.114 * blue) / 255;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
9
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
81
10
|
class NodeColorSupportDetector {
|
|
82
11
|
constructor(_process, overrideTheme) {
|
|
83
12
|
this._process = _process;
|
|
@@ -92,12 +21,6 @@ class NodeColorSupportDetector {
|
|
|
92
21
|
this._envWtSession = processEnv["WT_SESSION"];
|
|
93
22
|
this._isTTY = !!_process.stdout.isTTY;
|
|
94
23
|
this._overrideTheme = overrideTheme;
|
|
95
|
-
if (!this._overrideTheme && this._isTTY && typeof this._process.stdin.setRawMode === "function") {
|
|
96
|
-
this._querier = new OscThemeQuerier(
|
|
97
|
-
this._process.stdin,
|
|
98
|
-
this._process.stdout
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
24
|
}
|
|
102
25
|
_envForceColor;
|
|
103
26
|
_envTerm;
|
|
@@ -107,79 +30,104 @@ class NodeColorSupportDetector {
|
|
|
107
30
|
_envCliColorForce;
|
|
108
31
|
_envWtSession;
|
|
109
32
|
_isTTY;
|
|
110
|
-
_querier;
|
|
111
33
|
_overrideTheme;
|
|
112
34
|
isNodeEnv() {
|
|
113
35
|
return typeof this._process !== "undefined";
|
|
114
36
|
}
|
|
115
37
|
getColorLevel() {
|
|
116
38
|
if (this._envNoColor !== void 0) {
|
|
117
|
-
return
|
|
39
|
+
return determineBaseTheme.ColorLevel.NO_COLOR;
|
|
118
40
|
}
|
|
119
41
|
if (this._envForceColor !== void 0) {
|
|
120
42
|
if (this._envForceColor === "0" || this._envForceColor === "false") {
|
|
121
|
-
return
|
|
43
|
+
return determineBaseTheme.ColorLevel.NO_COLOR;
|
|
122
44
|
}
|
|
123
45
|
if (this._envForceColor === "1" || this._envForceColor === "true") {
|
|
124
|
-
return
|
|
46
|
+
return determineBaseTheme.ColorLevel.ANSI;
|
|
125
47
|
}
|
|
126
48
|
const level = parseInt(this._envForceColor, 10);
|
|
127
49
|
if (level >= 0 && level <= 3) {
|
|
128
50
|
return level;
|
|
129
51
|
}
|
|
130
|
-
return
|
|
52
|
+
return determineBaseTheme.ColorLevel.ANSI;
|
|
131
53
|
}
|
|
132
54
|
const isForced = this._envCliColorForce !== void 0 && this._envCliColorForce !== "0";
|
|
133
55
|
if (!this._isTTY && !isForced) {
|
|
134
|
-
return
|
|
56
|
+
return determineBaseTheme.ColorLevel.NO_COLOR;
|
|
135
57
|
}
|
|
136
58
|
if (this._envTerm === "dumb") {
|
|
137
|
-
return
|
|
59
|
+
return determineBaseTheme.ColorLevel.NO_COLOR;
|
|
138
60
|
}
|
|
139
61
|
if (this._envColorTerm === "truecolor" || this._envColorTerm === "24bit") {
|
|
140
|
-
return
|
|
62
|
+
return determineBaseTheme.ColorLevel.TRUECOLOR;
|
|
141
63
|
}
|
|
142
64
|
if (this._envWtSession !== void 0) {
|
|
143
|
-
return
|
|
65
|
+
return determineBaseTheme.ColorLevel.TRUECOLOR;
|
|
144
66
|
}
|
|
145
67
|
if (this._envTerm) {
|
|
146
|
-
if (/^xterm-kitty$/.test(this._envTerm) || /^xterm-ghostty$/.test(this._envTerm) || /^wezterm$/.test(this._envTerm) ||
|
|
147
|
-
return
|
|
68
|
+
if (/^xterm-kitty$/.test(this._envTerm) || /^xterm-ghostty$/.test(this._envTerm) || /^wezterm$/.test(this._envTerm) || this._envTerm.endsWith("-truecolor")) {
|
|
69
|
+
return determineBaseTheme.ColorLevel.TRUECOLOR;
|
|
148
70
|
}
|
|
149
71
|
if (/-256(color)?$/i.test(this._envTerm)) {
|
|
150
|
-
return
|
|
72
|
+
return determineBaseTheme.ColorLevel.ANSI256;
|
|
151
73
|
}
|
|
152
74
|
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(
|
|
153
75
|
this._envTerm
|
|
154
76
|
)) {
|
|
155
|
-
return
|
|
77
|
+
return determineBaseTheme.ColorLevel.ANSI;
|
|
156
78
|
}
|
|
157
79
|
}
|
|
158
80
|
if (this._envColorTerm) {
|
|
159
|
-
return
|
|
81
|
+
return determineBaseTheme.ColorLevel.ANSI;
|
|
160
82
|
}
|
|
161
83
|
if (this._envCliColor !== void 0 && this._envCliColor !== "0") {
|
|
162
|
-
return
|
|
84
|
+
return determineBaseTheme.ColorLevel.ANSI;
|
|
163
85
|
}
|
|
164
|
-
return this._isTTY || isForced ?
|
|
86
|
+
return this._isTTY || isForced ? determineBaseTheme.ColorLevel.ANSI : determineBaseTheme.ColorLevel.NO_COLOR;
|
|
165
87
|
}
|
|
166
|
-
|
|
167
|
-
if (this._overrideTheme)
|
|
168
|
-
|
|
88
|
+
getTheme() {
|
|
89
|
+
if (this._overrideTheme) return this._overrideTheme;
|
|
90
|
+
if (!this.isNodeEnv() || !this._isTTY) return "unknown";
|
|
91
|
+
const __dirname = node_path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('node.cjs', document.baseURI).href))));
|
|
92
|
+
const scriptPath = node_path.join(__dirname, "./run-osc-querier.js");
|
|
93
|
+
const spawnResult = neverthrow.Result.fromThrowable(
|
|
94
|
+
() => node_child_process.spawnSync(process.execPath, [scriptPath], {
|
|
95
|
+
stdio: ["inherit", "pipe", "pipe"],
|
|
96
|
+
timeout: 1e3,
|
|
97
|
+
encoding: "utf-8"
|
|
98
|
+
}),
|
|
99
|
+
(error) => error
|
|
100
|
+
)();
|
|
101
|
+
if (spawnResult.isErr()) {
|
|
102
|
+
return "unknown";
|
|
169
103
|
}
|
|
170
|
-
|
|
104
|
+
const processOutput = spawnResult.value;
|
|
105
|
+
if (processOutput.status !== 0 || processOutput.error) {
|
|
171
106
|
return "unknown";
|
|
172
107
|
}
|
|
173
|
-
const
|
|
174
|
-
|
|
108
|
+
const output = processOutput.stdout?.trim();
|
|
109
|
+
if (output === "dark") return "dark";
|
|
110
|
+
if (output === "light") return "light";
|
|
111
|
+
return "unknown";
|
|
175
112
|
}
|
|
176
113
|
}
|
|
177
114
|
|
|
178
|
-
function createColorino(palette, options = {}) {
|
|
179
|
-
const validator = new
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
115
|
+
function createColorino(palette = {}, options = {}) {
|
|
116
|
+
const validator = new determineBaseTheme.InputValidator();
|
|
117
|
+
let detectorThemeOverride;
|
|
118
|
+
if (options.theme === "dark" || options.theme === "light") {
|
|
119
|
+
detectorThemeOverride = options.theme;
|
|
120
|
+
}
|
|
121
|
+
const nodeDetector = new NodeColorSupportDetector(
|
|
122
|
+
process,
|
|
123
|
+
detectorThemeOverride
|
|
124
|
+
);
|
|
125
|
+
const detectedTerminalTheme = nodeDetector.getTheme();
|
|
126
|
+
const themeOpt = options.theme ?? "auto";
|
|
127
|
+
const baseThemeName = determineBaseTheme.determineBaseTheme(themeOpt, detectedTerminalTheme);
|
|
128
|
+
const basePalette = determineBaseTheme.themePalettes[baseThemeName];
|
|
129
|
+
const finalPalette = { ...basePalette, ...palette };
|
|
130
|
+
return new determineBaseTheme.Colorino(
|
|
183
131
|
finalPalette,
|
|
184
132
|
validator,
|
|
185
133
|
void 0,
|
|
@@ -189,7 +137,7 @@ function createColorino(palette, options = {}) {
|
|
|
189
137
|
options
|
|
190
138
|
);
|
|
191
139
|
}
|
|
192
|
-
const colorino = createColorino(
|
|
140
|
+
const colorino = createColorino();
|
|
193
141
|
|
|
194
142
|
exports.colorino = colorino;
|
|
195
143
|
exports.createColorino = createColorino;
|
package/dist/node.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.
|
|
2
|
-
export { L as LogLevel, T as
|
|
1
|
+
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.ODiKA7Gy.cjs';
|
|
2
|
+
export { L as LogLevel, T as ThemeName } from './shared/colorino.ODiKA7Gy.cjs';
|
|
3
3
|
import 'neverthrow';
|
|
4
4
|
|
|
5
|
-
declare function createColorino(palette
|
|
5
|
+
declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
6
6
|
|
|
7
7
|
declare const colorino: Colorino;
|
|
8
8
|
|
package/dist/node.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.
|
|
2
|
-
export { L as LogLevel, T as
|
|
1
|
+
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.ODiKA7Gy.mjs';
|
|
2
|
+
export { L as LogLevel, T as ThemeName } from './shared/colorino.ODiKA7Gy.mjs';
|
|
3
3
|
import 'neverthrow';
|
|
4
4
|
|
|
5
|
-
declare function createColorino(palette
|
|
5
|
+
declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
6
6
|
|
|
7
7
|
declare const colorino: Colorino;
|
|
8
8
|
|
package/dist/node.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.
|
|
2
|
-
export { L as LogLevel, T as
|
|
1
|
+
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.ODiKA7Gy.js';
|
|
2
|
+
export { L as LogLevel, T as ThemeName } from './shared/colorino.ODiKA7Gy.js';
|
|
3
3
|
import 'neverthrow';
|
|
4
4
|
|
|
5
|
-
declare function createColorino(palette
|
|
5
|
+
declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
6
6
|
|
|
7
7
|
declare const colorino: Colorino;
|
|
8
8
|
|
package/dist/node.mjs
CHANGED
|
@@ -1,80 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this._stdin = _stdin;
|
|
7
|
-
this._stdout = _stdout;
|
|
8
|
-
this._timeout = _timeout;
|
|
9
|
-
this._cacheTtl = _cacheTtl;
|
|
10
|
-
}
|
|
11
|
-
cachedResult;
|
|
12
|
-
cacheTimestamp;
|
|
13
|
-
async query() {
|
|
14
|
-
if (!this._stdout.isTTY || typeof this._stdin.setRawMode !== "function") {
|
|
15
|
-
return err(new OscQueryError("Not a TTY environment"));
|
|
16
|
-
}
|
|
17
|
-
const now = Date.now();
|
|
18
|
-
if (this.cachedResult !== void 0 && this.cacheTimestamp !== void 0 && now - this.cacheTimestamp < this._cacheTtl) {
|
|
19
|
-
return this.cachedResult;
|
|
20
|
-
}
|
|
21
|
-
const result = await this._performQuery();
|
|
22
|
-
this.cachedResult = result;
|
|
23
|
-
this.cacheTimestamp = now;
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
async _performQuery() {
|
|
27
|
-
return new Promise((resolve) => {
|
|
28
|
-
const originalRawMode = this._stdin.isRaw;
|
|
29
|
-
let buffer = "";
|
|
30
|
-
let isResolved = false;
|
|
31
|
-
const cleanup = () => {
|
|
32
|
-
if (isResolved) return;
|
|
33
|
-
isResolved = true;
|
|
34
|
-
clearTimeout(timer);
|
|
35
|
-
this._stdin.removeListener("data", onData);
|
|
36
|
-
this._stdin.setRawMode(originalRawMode);
|
|
37
|
-
};
|
|
38
|
-
const onData = (chunk) => {
|
|
39
|
-
buffer += chunk.toString();
|
|
40
|
-
const parseResult = this._parseResponse(buffer);
|
|
41
|
-
if (parseResult.isOk()) {
|
|
42
|
-
cleanup();
|
|
43
|
-
resolve(parseResult);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const timer = setTimeout(() => {
|
|
47
|
-
cleanup();
|
|
48
|
-
resolve(
|
|
49
|
-
err(new OscQueryError("OSC query timeout - terminal did not respond"))
|
|
50
|
-
);
|
|
51
|
-
}, this._timeout);
|
|
52
|
-
this._stdin.setRawMode(true);
|
|
53
|
-
this._stdin.on("data", onData);
|
|
54
|
-
this._stdout.write("\x1B]11;?\x1B\\");
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
_parseResponse(response) {
|
|
58
|
-
const rgbMatch = response.match(
|
|
59
|
-
/rgb:([0-9a-f]{2,4})\/([0-9a-f]{2,4})\/([0-9a-f]{2,4})/i
|
|
60
|
-
);
|
|
61
|
-
if (!rgbMatch) {
|
|
62
|
-
return err(new OscQueryError("No valid OSC response found in buffer"));
|
|
63
|
-
}
|
|
64
|
-
const red = this._normalizeHex(rgbMatch[1]);
|
|
65
|
-
const green = this._normalizeHex(rgbMatch[2]);
|
|
66
|
-
const blue = this._normalizeHex(rgbMatch[3]);
|
|
67
|
-
const luminance = this._calculateLuminance(red, green, blue);
|
|
68
|
-
return ok(luminance < 0.5 ? "dark" : "light");
|
|
69
|
-
}
|
|
70
|
-
_normalizeHex(hexValue) {
|
|
71
|
-
const normalized = hexValue.padEnd(4, "0").slice(0, 2);
|
|
72
|
-
return parseInt(normalized, 16);
|
|
73
|
-
}
|
|
74
|
-
_calculateLuminance(red, green, blue) {
|
|
75
|
-
return (0.299 * red + 0.587 * green + 0.114 * blue) / 255;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
1
|
+
import { C as ColorLevel, d as determineBaseTheme, t as themePalettes, a as Colorino, I as InputValidator } from './shared/colorino.B16XJPJ-.mjs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { Result } from 'neverthrow';
|
|
78
6
|
|
|
79
7
|
class NodeColorSupportDetector {
|
|
80
8
|
constructor(_process, overrideTheme) {
|
|
@@ -90,12 +18,6 @@ class NodeColorSupportDetector {
|
|
|
90
18
|
this._envWtSession = processEnv["WT_SESSION"];
|
|
91
19
|
this._isTTY = !!_process.stdout.isTTY;
|
|
92
20
|
this._overrideTheme = overrideTheme;
|
|
93
|
-
if (!this._overrideTheme && this._isTTY && typeof this._process.stdin.setRawMode === "function") {
|
|
94
|
-
this._querier = new OscThemeQuerier(
|
|
95
|
-
this._process.stdin,
|
|
96
|
-
this._process.stdout
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
21
|
}
|
|
100
22
|
_envForceColor;
|
|
101
23
|
_envTerm;
|
|
@@ -105,7 +27,6 @@ class NodeColorSupportDetector {
|
|
|
105
27
|
_envCliColorForce;
|
|
106
28
|
_envWtSession;
|
|
107
29
|
_isTTY;
|
|
108
|
-
_querier;
|
|
109
30
|
_overrideTheme;
|
|
110
31
|
isNodeEnv() {
|
|
111
32
|
return typeof this._process !== "undefined";
|
|
@@ -141,7 +62,7 @@ class NodeColorSupportDetector {
|
|
|
141
62
|
return ColorLevel.TRUECOLOR;
|
|
142
63
|
}
|
|
143
64
|
if (this._envTerm) {
|
|
144
|
-
if (/^xterm-kitty$/.test(this._envTerm) || /^xterm-ghostty$/.test(this._envTerm) || /^wezterm$/.test(this._envTerm) ||
|
|
65
|
+
if (/^xterm-kitty$/.test(this._envTerm) || /^xterm-ghostty$/.test(this._envTerm) || /^wezterm$/.test(this._envTerm) || this._envTerm.endsWith("-truecolor")) {
|
|
145
66
|
return ColorLevel.TRUECOLOR;
|
|
146
67
|
}
|
|
147
68
|
if (/-256(color)?$/i.test(this._envTerm)) {
|
|
@@ -161,22 +82,48 @@ class NodeColorSupportDetector {
|
|
|
161
82
|
}
|
|
162
83
|
return this._isTTY || isForced ? ColorLevel.ANSI : ColorLevel.NO_COLOR;
|
|
163
84
|
}
|
|
164
|
-
|
|
165
|
-
if (this._overrideTheme)
|
|
166
|
-
|
|
85
|
+
getTheme() {
|
|
86
|
+
if (this._overrideTheme) return this._overrideTheme;
|
|
87
|
+
if (!this.isNodeEnv() || !this._isTTY) return "unknown";
|
|
88
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
89
|
+
const scriptPath = join(__dirname, "./run-osc-querier.js");
|
|
90
|
+
const spawnResult = Result.fromThrowable(
|
|
91
|
+
() => spawnSync(process.execPath, [scriptPath], {
|
|
92
|
+
stdio: ["inherit", "pipe", "pipe"],
|
|
93
|
+
timeout: 1e3,
|
|
94
|
+
encoding: "utf-8"
|
|
95
|
+
}),
|
|
96
|
+
(error) => error
|
|
97
|
+
)();
|
|
98
|
+
if (spawnResult.isErr()) {
|
|
99
|
+
return "unknown";
|
|
167
100
|
}
|
|
168
|
-
|
|
101
|
+
const processOutput = spawnResult.value;
|
|
102
|
+
if (processOutput.status !== 0 || processOutput.error) {
|
|
169
103
|
return "unknown";
|
|
170
104
|
}
|
|
171
|
-
const
|
|
172
|
-
|
|
105
|
+
const output = processOutput.stdout?.trim();
|
|
106
|
+
if (output === "dark") return "dark";
|
|
107
|
+
if (output === "light") return "light";
|
|
108
|
+
return "unknown";
|
|
173
109
|
}
|
|
174
110
|
}
|
|
175
111
|
|
|
176
|
-
function createColorino(palette, options = {}) {
|
|
112
|
+
function createColorino(palette = {}, options = {}) {
|
|
177
113
|
const validator = new InputValidator();
|
|
178
|
-
|
|
179
|
-
|
|
114
|
+
let detectorThemeOverride;
|
|
115
|
+
if (options.theme === "dark" || options.theme === "light") {
|
|
116
|
+
detectorThemeOverride = options.theme;
|
|
117
|
+
}
|
|
118
|
+
const nodeDetector = new NodeColorSupportDetector(
|
|
119
|
+
process,
|
|
120
|
+
detectorThemeOverride
|
|
121
|
+
);
|
|
122
|
+
const detectedTerminalTheme = nodeDetector.getTheme();
|
|
123
|
+
const themeOpt = options.theme ?? "auto";
|
|
124
|
+
const baseThemeName = determineBaseTheme(themeOpt, detectedTerminalTheme);
|
|
125
|
+
const basePalette = themePalettes[baseThemeName];
|
|
126
|
+
const finalPalette = { ...basePalette, ...palette };
|
|
180
127
|
return new Colorino(
|
|
181
128
|
finalPalette,
|
|
182
129
|
validator,
|
|
@@ -187,6 +134,6 @@ function createColorino(palette, options = {}) {
|
|
|
187
134
|
options
|
|
188
135
|
);
|
|
189
136
|
}
|
|
190
|
-
const colorino = createColorino(
|
|
137
|
+
const colorino = createColorino();
|
|
191
138
|
|
|
192
139
|
export { colorino, createColorino };
|
|
@@ -173,12 +173,6 @@ class ColorinoError extends Error {
|
|
|
173
173
|
Object.setPrototypeOf(this, ColorinoError.prototype);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
-
class OscQueryError extends Error {
|
|
177
|
-
constructor(message) {
|
|
178
|
-
super(message);
|
|
179
|
-
this.name = "OscQueryError";
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
176
|
|
|
183
177
|
class InputValidator {
|
|
184
178
|
validateHex(hex) {
|
|
@@ -201,13 +195,87 @@ class InputValidator {
|
|
|
201
195
|
}
|
|
202
196
|
}
|
|
203
197
|
|
|
204
|
-
const
|
|
198
|
+
const catppuccinMochaPalette = {
|
|
199
|
+
log: "#cdd6f4",
|
|
200
|
+
// Text
|
|
201
|
+
info: "#89b4fa",
|
|
202
|
+
// Blue
|
|
203
|
+
warn: "#f9e2af",
|
|
204
|
+
// Yellow
|
|
205
|
+
error: "#f38ba8",
|
|
206
|
+
// Red
|
|
207
|
+
debug: "#a6adc8",
|
|
208
|
+
// Subtext0
|
|
209
|
+
trace: "#9399b2"
|
|
210
|
+
// Subtext1
|
|
211
|
+
};
|
|
212
|
+
const catppuccinLattePalette = {
|
|
213
|
+
log: "#4c4f69",
|
|
214
|
+
// Text
|
|
215
|
+
info: "#1e66f5",
|
|
216
|
+
// Blue
|
|
217
|
+
warn: "#df8e1d",
|
|
218
|
+
// Yellow
|
|
219
|
+
error: "#d20f39",
|
|
220
|
+
// Red
|
|
221
|
+
debug: "#7c7f93",
|
|
222
|
+
// Subtext0
|
|
223
|
+
trace: "#8c8fa1"
|
|
224
|
+
// Subtext1
|
|
225
|
+
};
|
|
226
|
+
const draculaPalette = {
|
|
205
227
|
log: "#f8f8f2",
|
|
206
|
-
|
|
228
|
+
// Foreground
|
|
229
|
+
info: "#8be9fd",
|
|
230
|
+
// Cyan
|
|
231
|
+
warn: "#f1fa8c",
|
|
232
|
+
// Yellow
|
|
207
233
|
error: "#ff5555",
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
234
|
+
// Red
|
|
235
|
+
debug: "#bd93f9",
|
|
236
|
+
// Purple
|
|
237
|
+
trace: "#6272a4"
|
|
238
|
+
// Comment
|
|
239
|
+
};
|
|
240
|
+
const githubLightPalette = {
|
|
241
|
+
log: "#24292e",
|
|
242
|
+
// Text
|
|
243
|
+
info: "#0366d6",
|
|
244
|
+
// Blue
|
|
245
|
+
warn: "#f9a002",
|
|
246
|
+
// Yellow
|
|
247
|
+
error: "#d73a49",
|
|
248
|
+
// Red
|
|
249
|
+
debug: "#586069",
|
|
250
|
+
// Gray
|
|
251
|
+
trace: "#6a737d"
|
|
252
|
+
// Gray-light
|
|
211
253
|
};
|
|
212
254
|
|
|
213
|
-
|
|
255
|
+
const themePalettes = {
|
|
256
|
+
"catppuccin-mocha": catppuccinMochaPalette,
|
|
257
|
+
"catppuccin-latte": catppuccinLattePalette,
|
|
258
|
+
dracula: draculaPalette,
|
|
259
|
+
"github-light": githubLightPalette
|
|
260
|
+
};
|
|
261
|
+
const defaultDarkTheme = "catppuccin-mocha";
|
|
262
|
+
const defaultLightTheme = "github-light";
|
|
263
|
+
function isThemeName(theme) {
|
|
264
|
+
return theme in themePalettes;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function determineBaseTheme(themeOpt, detectedBrowserTheme) {
|
|
268
|
+
let baseThemeName;
|
|
269
|
+
if (isThemeName(themeOpt)) {
|
|
270
|
+
baseThemeName = themeOpt;
|
|
271
|
+
} else if (themeOpt === "light") {
|
|
272
|
+
baseThemeName = defaultLightTheme;
|
|
273
|
+
} else if (themeOpt === "dark") {
|
|
274
|
+
baseThemeName = defaultDarkTheme;
|
|
275
|
+
} else {
|
|
276
|
+
baseThemeName = detectedBrowserTheme === "light" ? defaultLightTheme : defaultDarkTheme;
|
|
277
|
+
}
|
|
278
|
+
return baseThemeName;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export { ColorLevel as C, InputValidator as I, Colorino as a, determineBaseTheme as d, themePalettes as t };
|
|
@@ -175,12 +175,6 @@ class ColorinoError extends Error {
|
|
|
175
175
|
Object.setPrototypeOf(this, ColorinoError.prototype);
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
-
class OscQueryError extends Error {
|
|
179
|
-
constructor(message) {
|
|
180
|
-
super(message);
|
|
181
|
-
this.name = "OscQueryError";
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
178
|
|
|
185
179
|
class InputValidator {
|
|
186
180
|
validateHex(hex) {
|
|
@@ -203,17 +197,91 @@ class InputValidator {
|
|
|
203
197
|
}
|
|
204
198
|
}
|
|
205
199
|
|
|
206
|
-
const
|
|
200
|
+
const catppuccinMochaPalette = {
|
|
201
|
+
log: "#cdd6f4",
|
|
202
|
+
// Text
|
|
203
|
+
info: "#89b4fa",
|
|
204
|
+
// Blue
|
|
205
|
+
warn: "#f9e2af",
|
|
206
|
+
// Yellow
|
|
207
|
+
error: "#f38ba8",
|
|
208
|
+
// Red
|
|
209
|
+
debug: "#a6adc8",
|
|
210
|
+
// Subtext0
|
|
211
|
+
trace: "#9399b2"
|
|
212
|
+
// Subtext1
|
|
213
|
+
};
|
|
214
|
+
const catppuccinLattePalette = {
|
|
215
|
+
log: "#4c4f69",
|
|
216
|
+
// Text
|
|
217
|
+
info: "#1e66f5",
|
|
218
|
+
// Blue
|
|
219
|
+
warn: "#df8e1d",
|
|
220
|
+
// Yellow
|
|
221
|
+
error: "#d20f39",
|
|
222
|
+
// Red
|
|
223
|
+
debug: "#7c7f93",
|
|
224
|
+
// Subtext0
|
|
225
|
+
trace: "#8c8fa1"
|
|
226
|
+
// Subtext1
|
|
227
|
+
};
|
|
228
|
+
const draculaPalette = {
|
|
207
229
|
log: "#f8f8f2",
|
|
208
|
-
|
|
230
|
+
// Foreground
|
|
231
|
+
info: "#8be9fd",
|
|
232
|
+
// Cyan
|
|
233
|
+
warn: "#f1fa8c",
|
|
234
|
+
// Yellow
|
|
209
235
|
error: "#ff5555",
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
236
|
+
// Red
|
|
237
|
+
debug: "#bd93f9",
|
|
238
|
+
// Purple
|
|
239
|
+
trace: "#6272a4"
|
|
240
|
+
// Comment
|
|
241
|
+
};
|
|
242
|
+
const githubLightPalette = {
|
|
243
|
+
log: "#24292e",
|
|
244
|
+
// Text
|
|
245
|
+
info: "#0366d6",
|
|
246
|
+
// Blue
|
|
247
|
+
warn: "#f9a002",
|
|
248
|
+
// Yellow
|
|
249
|
+
error: "#d73a49",
|
|
250
|
+
// Red
|
|
251
|
+
debug: "#586069",
|
|
252
|
+
// Gray
|
|
253
|
+
trace: "#6a737d"
|
|
254
|
+
// Gray-light
|
|
213
255
|
};
|
|
214
256
|
|
|
257
|
+
const themePalettes = {
|
|
258
|
+
"catppuccin-mocha": catppuccinMochaPalette,
|
|
259
|
+
"catppuccin-latte": catppuccinLattePalette,
|
|
260
|
+
dracula: draculaPalette,
|
|
261
|
+
"github-light": githubLightPalette
|
|
262
|
+
};
|
|
263
|
+
const defaultDarkTheme = "catppuccin-mocha";
|
|
264
|
+
const defaultLightTheme = "github-light";
|
|
265
|
+
function isThemeName(theme) {
|
|
266
|
+
return theme in themePalettes;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function determineBaseTheme(themeOpt, detectedBrowserTheme) {
|
|
270
|
+
let baseThemeName;
|
|
271
|
+
if (isThemeName(themeOpt)) {
|
|
272
|
+
baseThemeName = themeOpt;
|
|
273
|
+
} else if (themeOpt === "light") {
|
|
274
|
+
baseThemeName = defaultLightTheme;
|
|
275
|
+
} else if (themeOpt === "dark") {
|
|
276
|
+
baseThemeName = defaultDarkTheme;
|
|
277
|
+
} else {
|
|
278
|
+
baseThemeName = detectedBrowserTheme === "light" ? defaultLightTheme : defaultDarkTheme;
|
|
279
|
+
}
|
|
280
|
+
return baseThemeName;
|
|
281
|
+
}
|
|
282
|
+
|
|
215
283
|
exports.ColorLevel = ColorLevel;
|
|
216
284
|
exports.Colorino = Colorino;
|
|
217
285
|
exports.InputValidator = InputValidator;
|
|
218
|
-
exports.
|
|
219
|
-
exports.
|
|
286
|
+
exports.determineBaseTheme = determineBaseTheme;
|
|
287
|
+
exports.themePalettes = themePalettes;
|