@kaynooo/cli-view 0.5.0 → 0.6.1
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/view.js +122 -305
- package/package.json +2 -2
package/dist/view.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#!/usr/bin/env -S bun --no-env-file
|
|
1
|
+
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/view.ts
|
|
5
|
-
import
|
|
5
|
+
import process16 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process10 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -31,266 +31,60 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
31
31
|
// ../kit/src/style.ts
|
|
32
32
|
import process6 from "process";
|
|
33
33
|
|
|
34
|
-
// ../../node_modules/.bun/@kaynooo+utils@
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
35
|
+
var G = /^[a-f0-9]+$/i;
|
|
36
|
+
function b(r) {
|
|
37
|
+
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
38
|
+
if (!G.test(e))
|
|
38
39
|
return [0, 0, 0];
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
return `#${(r << 24 | t << 16 | n << 8 | Math.round((a ?? 1) * 255)).toString(16).padStart(8, "0").toUpperCase()}`;
|
|
55
|
-
return `#${(r << 16 | t << 8 | n).toString(16).padStart(6, "0").toUpperCase()}`;
|
|
56
|
-
}
|
|
57
|
-
function R(s, r, t) {
|
|
58
|
-
s = (s % 360 + 360) % 360, t /= 100;
|
|
59
|
-
let n = r * Math.min(t, 1 - t) / 100, a = (b) => {
|
|
60
|
-
let o = (b + s / 30) % 12, y = t - n * Math.max(Math.min(o - 3, 9 - o, 1), -1);
|
|
61
|
-
return Math.round(255 * y);
|
|
62
|
-
};
|
|
63
|
-
return [a(0), a(8), a(4)];
|
|
64
|
-
}
|
|
65
|
-
function k(s) {
|
|
66
|
-
let [r, t, n] = s;
|
|
67
|
-
r /= 255, t /= 255, n /= 255;
|
|
68
|
-
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = 0, y = 0, c = (a + b) / 2;
|
|
69
|
-
if (a !== b) {
|
|
70
|
-
let u = a - b;
|
|
71
|
-
if (y = c > 0 && c < 1 ? u / (1 - Math.abs(2 * c - 1)) : 0, a === r)
|
|
72
|
-
o = (t - n) / u + (t < n ? 6 : 0);
|
|
73
|
-
else if (a === t)
|
|
74
|
-
o = (n - r) / u + 2;
|
|
75
|
-
else
|
|
76
|
-
o = (r - t) / u + 4;
|
|
77
|
-
o /= 6;
|
|
78
|
-
}
|
|
79
|
-
return [Math.round(o * 360), Math.round(y * 100), Math.round(c * 100)];
|
|
80
|
-
}
|
|
81
|
-
function H(s, r, t) {
|
|
82
|
-
s = (s % 360 + 360) % 360, r /= 100, t /= 100;
|
|
83
|
-
let n = (a) => {
|
|
84
|
-
let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
|
|
85
|
-
return Math.round(255 * o);
|
|
86
|
-
};
|
|
87
|
-
return [n(5), n(3), n(1)];
|
|
88
|
-
}
|
|
89
|
-
function f(s) {
|
|
90
|
-
let [r, t, n] = s;
|
|
91
|
-
r /= 255, t /= 255, n /= 255;
|
|
92
|
-
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = a - b, y = 0, c = a === 0 ? 0 : o / a, u = a;
|
|
93
|
-
if (o !== 0) {
|
|
94
|
-
if (a === r)
|
|
95
|
-
y = (t - n) / o + (t < n ? 6 : 0);
|
|
96
|
-
else if (a === t)
|
|
97
|
-
y = (n - r) / o + 2;
|
|
98
|
-
else
|
|
99
|
-
y = (r - t) / o + 4;
|
|
100
|
-
y /= 6;
|
|
101
|
-
}
|
|
102
|
-
return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
|
|
103
|
-
}
|
|
104
|
-
function O(s) {
|
|
105
|
-
let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
|
|
106
|
-
if (a === 1)
|
|
107
|
-
return [0, 0, 0, 100];
|
|
108
|
-
let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
|
|
109
|
-
return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
|
|
110
|
-
}
|
|
111
|
-
function v(s, r, t, n) {
|
|
112
|
-
return s /= 100, r /= 100, t /= 100, n /= 100, [Math.round(255 * (1 - s) * (1 - n)), Math.round(255 * (1 - r) * (1 - n)), Math.round(255 * (1 - t) * (1 - n))];
|
|
113
|
-
}
|
|
114
|
-
var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
115
|
-
var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
|
|
116
|
-
var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
|
|
117
|
-
function T(s) {
|
|
118
|
-
let r = m(s[0] / 255), t = m(s[1] / 255), n = m(s[2] / 255), a = Math.cbrt(0.4122214708 * r + 0.5363325363 * t + 0.0514459929 * n), b = Math.cbrt(0.2119034982 * r + 0.6806995451 * t + 0.1073969566 * n), o = Math.cbrt(0.0883024619 * r + 0.2817188376 * t + 0.6299787005 * n);
|
|
119
|
-
return [i(0.2104542553 * a + 0.793617785 * b - 0.0040720468 * o, 4), i(1.9779984951 * a - 2.428592205 * b + 0.4505937099 * o, 4), i(0.0259040371 * a + 0.7827717662 * b - 0.808675766 * o, 4)];
|
|
120
|
-
}
|
|
121
|
-
function M(s, r, t) {
|
|
122
|
-
let n = (s + 0.3963377774 * r + 0.2158037573 * t) ** 3, a = (s - 0.1055613458 * r - 0.0638541728 * t) ** 3, b = (s - 0.0894841775 * r - 1.291485548 * t) ** 3, o = p(4.0767416621 * n - 3.3077115913 * a + 0.2309699292 * b), y = p(-1.2684380046 * n + 2.6097574011 * a - 0.3413193965 * b), c = p(-0.0041960863 * n - 0.7034186147 * a + 1.707614701 * b), u = (h) => Math.min(255, Math.max(0, Math.round(h * 255)));
|
|
123
|
-
return [u(o), u(y), u(c)];
|
|
124
|
-
}
|
|
125
|
-
function d(s) {
|
|
126
|
-
let [r, t, n] = T(s), a = Math.sqrt(t * t + n * n), b = (Math.atan2(n, t) * 180 / Math.PI + 360) % 360;
|
|
127
|
-
return [i(r, 4), i(a, 4), i(b, 2)];
|
|
128
|
-
}
|
|
129
|
-
function C(s, r, t) {
|
|
130
|
-
let n = t * Math.PI / 180;
|
|
131
|
-
return M(s, r * Math.cos(n), r * Math.sin(n));
|
|
132
|
-
}
|
|
133
|
-
function l(s) {
|
|
134
|
-
let r = s / 255;
|
|
135
|
-
return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
class e {
|
|
139
|
-
r;
|
|
140
|
-
g;
|
|
141
|
-
b;
|
|
142
|
-
a;
|
|
143
|
-
constructor(s, r, t, n = 1) {
|
|
144
|
-
this.r = s, this.g = r, this.b = t, this.a = n;
|
|
145
|
-
}
|
|
146
|
-
static from(s, r) {
|
|
147
|
-
if (s === "hex") {
|
|
148
|
-
let [t, n, a, b] = x(r);
|
|
149
|
-
return new e(t, n, a, b);
|
|
150
|
-
}
|
|
151
|
-
if (s === "rgb") {
|
|
152
|
-
if (Array.isArray(r)) {
|
|
153
|
-
let [o, y, c, u] = r;
|
|
154
|
-
return new e(o, y, c, u);
|
|
155
|
-
}
|
|
156
|
-
let { r: t, g: n, b: a, a: b } = r;
|
|
157
|
-
return new e(t, n, a, b);
|
|
158
|
-
}
|
|
159
|
-
if (s === "hsl") {
|
|
160
|
-
let t, n, a, b;
|
|
161
|
-
if (Array.isArray(r))
|
|
162
|
-
[t, n, a, b] = r;
|
|
163
|
-
else
|
|
164
|
-
({ h: t, s: n, l: a, a: b } = r);
|
|
165
|
-
let [o, y, c] = R(t, n, a);
|
|
166
|
-
return new e(o, y, c, b);
|
|
167
|
-
}
|
|
168
|
-
if (s === "hsv") {
|
|
169
|
-
let t, n, a, b;
|
|
170
|
-
if (Array.isArray(r))
|
|
171
|
-
[t, n, a, b] = r;
|
|
172
|
-
else
|
|
173
|
-
({ h: t, s: n, v: a, a: b } = r);
|
|
174
|
-
let [o, y, c] = H(t, n, a);
|
|
175
|
-
return new e(o, y, c, b);
|
|
176
|
-
}
|
|
177
|
-
if (s === "cmyk") {
|
|
178
|
-
let t, n, a, b, o;
|
|
179
|
-
if (Array.isArray(r))
|
|
180
|
-
[t, n, a, b, o] = r;
|
|
181
|
-
else
|
|
182
|
-
({ c: t, m: n, y: a, k: b, a: o } = r);
|
|
183
|
-
let [y, c, u] = v(t, n, a, b);
|
|
184
|
-
return new e(y, c, u, o);
|
|
185
|
-
}
|
|
186
|
-
if (s === "oklch") {
|
|
187
|
-
let t, n, a, b;
|
|
188
|
-
if (Array.isArray(r))
|
|
189
|
-
[t, n, a, b] = r;
|
|
190
|
-
else
|
|
191
|
-
({ l: t, c: n, h: a, a: b } = r);
|
|
192
|
-
let [o, y, c] = C(t, n, a);
|
|
193
|
-
return new e(o, y, c, b);
|
|
194
|
-
}
|
|
195
|
-
if (s === "oklab") {
|
|
196
|
-
let t, n, a, b;
|
|
197
|
-
if (Array.isArray(r))
|
|
198
|
-
[t, n, a, b] = r;
|
|
199
|
-
else
|
|
200
|
-
({ l: t, a: n, b: a, alpha: b } = r);
|
|
201
|
-
let [o, y, c] = M(t, n, a);
|
|
202
|
-
return new e(o, y, c, b);
|
|
203
|
-
}
|
|
204
|
-
throw Error("Invalid input");
|
|
205
|
-
}
|
|
206
|
-
to(s) {
|
|
207
|
-
switch (s) {
|
|
208
|
-
case "rgb":
|
|
209
|
-
return [this.r, this.g, this.b];
|
|
210
|
-
case "rgba":
|
|
211
|
-
return [this.r, this.g, this.b, this.a];
|
|
212
|
-
case "hex":
|
|
213
|
-
return A([this.r, this.g, this.b]);
|
|
214
|
-
case "hexa":
|
|
215
|
-
return A([this.r, this.g, this.b, this.a]);
|
|
216
|
-
case "hsl":
|
|
217
|
-
return k([this.r, this.g, this.b]);
|
|
218
|
-
case "hsla":
|
|
219
|
-
return [...k([this.r, this.g, this.b]), this.a];
|
|
220
|
-
case "hsv":
|
|
221
|
-
return f([this.r, this.g, this.b]);
|
|
222
|
-
case "hsva":
|
|
223
|
-
return [...f([this.r, this.g, this.b]), this.a];
|
|
224
|
-
case "cmyk":
|
|
225
|
-
return O([this.r, this.g, this.b]);
|
|
226
|
-
case "cmyka":
|
|
227
|
-
return [...O([this.r, this.g, this.b]), this.a];
|
|
228
|
-
case "oklch":
|
|
229
|
-
return d([this.r, this.g, this.b]);
|
|
230
|
-
case "oklcha":
|
|
231
|
-
return [...d([this.r, this.g, this.b]), this.a];
|
|
232
|
-
case "oklab":
|
|
233
|
-
return T([this.r, this.g, this.b]);
|
|
234
|
-
case "oklaba":
|
|
235
|
-
return [...T([this.r, this.g, this.b]), this.a];
|
|
236
|
-
default:
|
|
237
|
-
return [this.r, this.g, this.b];
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
getLuminance() {
|
|
241
|
-
let s = l(this.r), r = l(this.g), t = l(this.b);
|
|
242
|
-
return 0.2126 * s + 0.7152 * r + 0.0722 * t;
|
|
243
|
-
}
|
|
244
|
-
contrastRatio(s) {
|
|
245
|
-
let r = this.getLuminance(), t = s.getLuminance(), [n, a] = r >= t ? [r, t] : [t, r];
|
|
246
|
-
return (n + 0.05) / (a + 0.05);
|
|
247
|
-
}
|
|
248
|
-
bestContrastForeground() {
|
|
249
|
-
let s = new e(255, 255, 255, 1), r = new e(0, 0, 0, 1), t = this.contrastRatio(s), n = this.contrastRatio(r);
|
|
250
|
-
return t >= n ? s : r;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
|
|
255
|
-
var r = 39;
|
|
256
|
-
var o = 49;
|
|
257
|
-
var f2 = "\x1B[";
|
|
258
|
-
var C2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, r], red: [31, r], green: [32, r], yellow: [33, r], blue: [34, r], magenta: [35, r], cyan: [36, r], white: [37, r], gray: [90, r], grey: [90, r], blackBright: [90, r], redBright: [91, r], greenBright: [92, r], yellowBright: [93, r], blueBright: [94, r], magentaBright: [95, r], cyanBright: [96, r], whiteBright: [97, r], bgBlack: [40, o], bgRed: [41, o], bgGreen: [42, o], bgYellow: [43, o], bgBlue: [44, o], bgMagenta: [45, o], bgCyan: [46, o], bgWhite: [47, o], bgBlackBright: [100, o], bgRedBright: [101, o], bgGreenBright: [102, o], bgYellowBright: [103, o], bgBlueBright: [104, o], bgMagentaBright: [105, o], bgCyanBright: [106, o], bgWhiteBright: [107, o], rgb: (i, n, a, l = "fg") => [`${l === "fg" ? 38 : 48};2;${i};${n};${a}`, l === "fg" ? r : o], hex: (i, n = "fg") => {
|
|
259
|
-
let [a, l, s] = e.from("hex", i).to("rgb");
|
|
260
|
-
return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
|
|
261
|
-
}, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
|
|
262
|
-
var b = new Set(["", "1", "2", "3", "true"]);
|
|
263
|
-
function h(i, n = globalThis.process?.env ?? {}) {
|
|
264
|
-
if (n.FORCE_COLOR !== undefined)
|
|
265
|
-
return b.has(n.FORCE_COLOR);
|
|
266
|
-
if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
|
|
40
|
+
if (e.length === 3 || e.length === 4)
|
|
41
|
+
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
42
|
+
if (e.length !== 6 && e.length !== 8)
|
|
43
|
+
throw Error(`Invalid hex color length: ${e.length}`);
|
|
44
|
+
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
45
|
+
}
|
|
46
|
+
var B = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
47
|
+
let [l, n, c] = b(r);
|
|
48
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
49
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
50
|
+
var h = new Set(["", "1", "2", "3", "true"]);
|
|
51
|
+
function C(r, e = globalThis.process?.env ?? {}) {
|
|
52
|
+
if (e.FORCE_COLOR !== undefined)
|
|
53
|
+
return h.has(e.FORCE_COLOR);
|
|
54
|
+
if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
|
|
267
55
|
return false;
|
|
268
|
-
return
|
|
269
|
-
}
|
|
270
|
-
function
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (
|
|
284
|
-
return
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
56
|
+
return r?.isTTY === true;
|
|
57
|
+
}
|
|
58
|
+
function f(r, e = []) {
|
|
59
|
+
let l = "", n = "";
|
|
60
|
+
for (let t = 0, i = e.length;t < i; t++)
|
|
61
|
+
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
62
|
+
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
63
|
+
return new Proxy(c, { get(t, i) {
|
|
64
|
+
let a = B[i];
|
|
65
|
+
if (Array.isArray(a)) {
|
|
66
|
+
let s = g.get(i);
|
|
67
|
+
if (s === undefined)
|
|
68
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
69
|
+
return s;
|
|
70
|
+
}
|
|
71
|
+
if (typeof a === "function")
|
|
72
|
+
return (...s) => {
|
|
73
|
+
let y = `${i}:${s.join(",")}`, u = g.get(y);
|
|
74
|
+
if (u === undefined) {
|
|
75
|
+
if (g.size >= 64)
|
|
76
|
+
g.clear();
|
|
77
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
78
|
+
}
|
|
79
|
+
return u;
|
|
80
|
+
};
|
|
81
|
+
throw Error(`Unknown style: ${String(i)}`);
|
|
288
82
|
} });
|
|
289
83
|
}
|
|
290
|
-
function
|
|
291
|
-
return
|
|
84
|
+
function Fe(r = {}) {
|
|
85
|
+
return f(r);
|
|
292
86
|
}
|
|
293
|
-
var
|
|
87
|
+
var o = Fe();
|
|
294
88
|
|
|
295
89
|
// ../kit/src/theme.ts
|
|
296
90
|
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
@@ -360,15 +154,15 @@ function gradientAt(theme, ratio) {
|
|
|
360
154
|
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
361
155
|
}
|
|
362
156
|
var DEFAULT = {
|
|
363
|
-
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
364
|
-
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
|
|
157
|
+
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
158
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
|
|
365
159
|
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
366
160
|
bins: {},
|
|
367
161
|
gradient: ["#c084fc", "#67e8f9"]
|
|
368
162
|
};
|
|
369
|
-
var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
370
|
-
var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
371
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
163
|
+
var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
164
|
+
var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
165
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
372
166
|
var PRESETS = {
|
|
373
167
|
default: {},
|
|
374
168
|
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
@@ -543,7 +337,7 @@ function takesControlCodes(stream, env = process6.env) {
|
|
|
543
337
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
544
338
|
}
|
|
545
339
|
function paint(stream, env = process6.env) {
|
|
546
|
-
return
|
|
340
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
547
341
|
}
|
|
548
342
|
function role(name, stream, env = process6.env) {
|
|
549
343
|
const colors = paint(stream, env);
|
|
@@ -587,18 +381,14 @@ var FULL_STOP = /\.$/;
|
|
|
587
381
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
588
382
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
589
383
|
}
|
|
590
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
591
|
-
return [usageLine(usage, colors),
|
|
384
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
385
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
592
386
|
`);
|
|
593
387
|
}
|
|
594
388
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
595
389
|
if (exits.length === 0)
|
|
596
390
|
return [];
|
|
597
|
-
|
|
598
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
599
|
-
}
|
|
600
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
601
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
391
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
602
392
|
}
|
|
603
393
|
function wantsHelpJson(env = process8.env) {
|
|
604
394
|
return env.KIT_HELP === "json";
|
|
@@ -898,21 +688,45 @@ function nearestOption(message, options, allowNegative) {
|
|
|
898
688
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
899
689
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
900
690
|
}
|
|
691
|
+
// ../kit/src/argv.ts
|
|
692
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
693
|
+
import { resolve as resolve3 } from "path";
|
|
694
|
+
import process11 from "process";
|
|
695
|
+
function commandLine() {
|
|
696
|
+
try {
|
|
697
|
+
return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
698
|
+
} catch {
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
function realPath(word) {
|
|
703
|
+
try {
|
|
704
|
+
return realpathSync(resolve3(word));
|
|
705
|
+
} catch {
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
710
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
711
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
712
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
713
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
714
|
+
}
|
|
901
715
|
// ../kit/src/progress.ts
|
|
902
716
|
var ESC = String.fromCharCode(27);
|
|
903
717
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
904
718
|
var RESET_STYLE = `${ESC}[0m`;
|
|
905
719
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
906
720
|
// ../kit/src/cli.ts
|
|
907
|
-
import { readFileSync as
|
|
721
|
+
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
908
722
|
import { dirname as dirname3, join as join5 } from "path";
|
|
909
|
-
import
|
|
723
|
+
import process13 from "process";
|
|
910
724
|
|
|
911
725
|
// ../kit/src/usage.ts
|
|
912
726
|
import { appendFileSync, mkdirSync } from "fs";
|
|
913
727
|
import { homedir as homedir3 } from "os";
|
|
914
728
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
915
|
-
import
|
|
729
|
+
import process12 from "process";
|
|
916
730
|
|
|
917
731
|
// ../kit/src/logs.ts
|
|
918
732
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -926,14 +740,14 @@ var usageError;
|
|
|
926
740
|
function noteUsageError(message) {
|
|
927
741
|
usageError = message;
|
|
928
742
|
}
|
|
929
|
-
function stateHome(env =
|
|
743
|
+
function stateHome(env = process12.env) {
|
|
930
744
|
const dir = env.XDG_STATE_HOME;
|
|
931
745
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
932
746
|
}
|
|
933
|
-
function usagePath(env =
|
|
747
|
+
function usagePath(env = process12.env) {
|
|
934
748
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
935
749
|
}
|
|
936
|
-
function usageRecorded(env =
|
|
750
|
+
function usageRecorded(env = process12.env) {
|
|
937
751
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
938
752
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
939
753
|
}
|
|
@@ -947,7 +761,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
947
761
|
usageError = undefined;
|
|
948
762
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
949
763
|
}
|
|
950
|
-
function recordUsage(entry, env =
|
|
764
|
+
function recordUsage(entry, env = process12.env) {
|
|
951
765
|
if (!usageRecorded(env))
|
|
952
766
|
return;
|
|
953
767
|
try {
|
|
@@ -965,8 +779,8 @@ var LEVEL_OPTIONS = {
|
|
|
965
779
|
};
|
|
966
780
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
967
781
|
function printError(prefix, message, hint, cause) {
|
|
968
|
-
const colors = paint(
|
|
969
|
-
const styled = takesControlCodes(
|
|
782
|
+
const colors = paint(process13.stderr);
|
|
783
|
+
const styled = takesControlCodes(process13.stderr);
|
|
970
784
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
971
785
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
972
786
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1010,24 +824,24 @@ function candidateLine(candidate) {
|
|
|
1010
824
|
}
|
|
1011
825
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
1012
826
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1013
|
-
|
|
827
|
+
const typed = [];
|
|
1014
828
|
let at = 0;
|
|
1015
829
|
while (at < before.length) {
|
|
1016
830
|
const word = before[at];
|
|
1017
831
|
if (word === "--") {
|
|
1018
|
-
|
|
832
|
+
typed.push(...before.slice(at + 1));
|
|
1019
833
|
break;
|
|
1020
834
|
}
|
|
1021
835
|
if (!word.startsWith("-"))
|
|
1022
|
-
|
|
836
|
+
typed.push(word);
|
|
1023
837
|
else if (takesValue(word))
|
|
1024
838
|
at++;
|
|
1025
839
|
at++;
|
|
1026
840
|
}
|
|
1027
841
|
const last = positionals.at(-1);
|
|
1028
|
-
if (
|
|
1029
|
-
return positionals[
|
|
1030
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
842
|
+
if (typed.length < positionals.length)
|
|
843
|
+
return { name: positionals[typed.length], typed };
|
|
844
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1031
845
|
}
|
|
1032
846
|
async function leafCandidates(run, words) {
|
|
1033
847
|
const completing = await completingOf(run);
|
|
@@ -1035,12 +849,12 @@ async function leafCandidates(run, words) {
|
|
|
1035
849
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1036
850
|
const flag = words.at(-2);
|
|
1037
851
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
852
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1038
853
|
if (option?.type === "string") {
|
|
1039
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
854
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1040
855
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1041
856
|
}
|
|
1042
|
-
const
|
|
1043
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
857
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1044
858
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1045
859
|
}
|
|
1046
860
|
async function printCandidates(found) {
|
|
@@ -1049,9 +863,13 @@ async function printCandidates(found) {
|
|
|
1049
863
|
return 0;
|
|
1050
864
|
}
|
|
1051
865
|
function packageVersion(entry = Bun.main) {
|
|
1052
|
-
|
|
866
|
+
let resolved = entry;
|
|
867
|
+
try {
|
|
868
|
+
resolved = realpathSync2(entry);
|
|
869
|
+
} catch {}
|
|
870
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1053
871
|
try {
|
|
1054
|
-
const { version } = JSON.parse(
|
|
872
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
1055
873
|
if (typeof version === "string")
|
|
1056
874
|
return version;
|
|
1057
875
|
} catch {}
|
|
@@ -1059,7 +877,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1059
877
|
return "0.0.0";
|
|
1060
878
|
}
|
|
1061
879
|
}
|
|
1062
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
880
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1063
881
|
if (argv[0] === COMPLETE)
|
|
1064
882
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1065
883
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1521,8 +1339,8 @@ ${theme.dim("\u2500".repeat(rule))}
|
|
|
1521
1339
|
}
|
|
1522
1340
|
|
|
1523
1341
|
// src/theme.ts
|
|
1524
|
-
import
|
|
1525
|
-
function themeFor(stream =
|
|
1342
|
+
import process15 from "process";
|
|
1343
|
+
function themeFor(stream = process15.stdout, env = process15.env) {
|
|
1526
1344
|
const colors = paint(stream, env);
|
|
1527
1345
|
const accent = role("accent", stream, env);
|
|
1528
1346
|
const path = role("path", stream, env);
|
|
@@ -1553,9 +1371,8 @@ var DIFF_FILE = /\.(?:diff|patch)$/i;
|
|
|
1553
1371
|
var USAGE = `view [options] [file]: shows a markdown file, a source file or a git diff in the colours of the other @kaynooo CLIs
|
|
1554
1372
|
|
|
1555
1373
|
A file, or what is piped on stdin (or - for stdin). A source file (ts, js, json, yaml, toml, py, sh, css, sql, rs, go and more) is highlighted behind line numbers, by its extension or --lang. A diff, a \`git log -p\` or a \`git show\` is recognised by its first line or a .diff or .patch name, anything else is markdown; --diff and --markdown force one. Code blocks in markdown are highlighted by their language.
|
|
1556
|
-
Lines wrap to the terminal width (80 when it is not a terminal) and a long output on a terminal goes through \`less -FRX\` unless --no-pager. No colour with NO_COLOR, a pipe or --plain
|
|
1557
|
-
|
|
1558
|
-
Exits 0 when it showed the text, 1 when there is nothing to show, 2 on a usage error or a file that is missing.`;
|
|
1374
|
+
Lines wrap to the terminal width (80 when it is not a terminal) and a long output on a terminal goes through \`less -FRX\` unless --no-pager. No colour with NO_COLOR, a pipe or --plain.`;
|
|
1375
|
+
var EXITS = [[0, "it showed the text"], [1, "there is nothing to show"], [2, "a usage error or a file that is missing"]];
|
|
1559
1376
|
var OPTIONS = {
|
|
1560
1377
|
diff: { type: "boolean", description: "show the text as a diff" },
|
|
1561
1378
|
markdown: { type: "boolean", description: "show the text as markdown" },
|
|
@@ -1574,11 +1391,11 @@ async function page(text) {
|
|
|
1574
1391
|
} catch {}
|
|
1575
1392
|
await pager.exited;
|
|
1576
1393
|
} catch {
|
|
1577
|
-
|
|
1394
|
+
process16.stdout.write(text);
|
|
1578
1395
|
}
|
|
1579
1396
|
}
|
|
1580
1397
|
async function main(args) {
|
|
1581
|
-
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[file]"], allowNegative: true, replaces: "cat, bat or less on a markdown file, delta on a diff", examples: ["view README.md", "git diff | view"] });
|
|
1398
|
+
const { values, positionals } = parse(args, USAGE, OPTIONS, { exits: EXITS, positionals: ["[file]"], allowNegative: true, replaces: "cat, bat or less on a markdown file, delta on a diff", examples: ["view README.md", "git diff | view"] });
|
|
1582
1399
|
if (positionals.length > 1)
|
|
1583
1400
|
badUsage("give one file");
|
|
1584
1401
|
if (values.diff === true && values.markdown === true)
|
|
@@ -1587,8 +1404,8 @@ async function main(args) {
|
|
|
1587
1404
|
const text = await readInput(path, { noStdin: "give a file, or pipe the text on stdin" });
|
|
1588
1405
|
if (text.trim() === "")
|
|
1589
1406
|
fail("nothing to show", 1);
|
|
1590
|
-
const width = wholeNumber(values.width, "width",
|
|
1591
|
-
const theme = themeFor(
|
|
1407
|
+
const width = wholeNumber(values.width, "width", process16.stdout.isTTY === true ? process16.stdout.columns || DEFAULT_WIDTH : DEFAULT_WIDTH, 20);
|
|
1408
|
+
const theme = themeFor(process16.stdout);
|
|
1592
1409
|
const language = values.lang === undefined ? languageOf(path) : languageOf(values.lang);
|
|
1593
1410
|
if (values.lang !== undefined && language === undefined)
|
|
1594
1411
|
badUsage(`unknown language ${values.lang}`);
|
|
@@ -1605,12 +1422,12 @@ async function main(args) {
|
|
|
1605
1422
|
printJson({ kind: isCode ? "code" : kind, language: isCode ? language ?? null : null, text: stripAnsi(render(themeFor({ isTTY: false }), values.lines ?? false)) });
|
|
1606
1423
|
return 0;
|
|
1607
1424
|
}
|
|
1608
|
-
const shown = render(theme, values.lines ??
|
|
1609
|
-
if (
|
|
1610
|
-
`).length > (
|
|
1425
|
+
const shown = render(theme, values.lines ?? process16.stdout.isTTY === true);
|
|
1426
|
+
if (process16.stdout.isTTY === true && values.pager !== false && shown.split(`
|
|
1427
|
+
`).length > (process16.stdout.rows || 24))
|
|
1611
1428
|
await page(shown);
|
|
1612
1429
|
else
|
|
1613
|
-
|
|
1430
|
+
process16.stdout.write(shown);
|
|
1614
1431
|
return 0;
|
|
1615
1432
|
}
|
|
1616
|
-
|
|
1433
|
+
process16.exitCode = await runMain({ name: "view", run: main });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-view",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.1",
|
|
5
5
|
"description": "view: markdown files and git diffs shown in the colours of the other @kaynooo CLIs, paged when long.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
"view": "$npm_execpath src/view.ts"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@kaynooo/cli-kit": "0.
|
|
38
|
+
"@kaynooo/cli-kit": "0.38.3"
|
|
39
39
|
}
|
|
40
40
|
}
|