@kaynooo/cli-view 0.7.1 → 0.7.3
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 +2 -1
- package/dist/view.js +318 -129
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -19,4 +19,5 @@ The text is a file, or what is piped on stdin. A diff is recognised by its first
|
|
|
19
19
|
|
|
20
20
|
Code blocks in markdown are highlighted by their language too. The highlighting is a light tokenizer, not a parser: it gets comments, strings, numbers and keywords right for the common languages, and leaves a language it does not know uncoloured.
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
Lines wrap to `COLUMNS`, or 80 when the output is not a terminal. A long output on a terminal goes through `$PAGER`, or `less -FRX` when it is unset or `less`. In a diff the code is highlighted by the file's extension and the changed words of a paired removed and added line are reversed. A source file is recognised by its extension or `--lang`, and more languages than the table lists are known.
|
package/dist/view.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
var __esm = (fn, res, err) => () => {
|
|
4
|
+
if (fn)
|
|
5
|
+
try {
|
|
6
|
+
res = fn(fn = 0);
|
|
7
|
+
} catch (e) {
|
|
8
|
+
err = [e];
|
|
9
|
+
}
|
|
10
|
+
if (err)
|
|
11
|
+
throw err[0];
|
|
12
|
+
return res;
|
|
13
|
+
};
|
|
12
14
|
|
|
13
15
|
// ../kit/src/mode.ts
|
|
14
16
|
import process2 from "process";
|
|
15
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
16
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
17
17
|
function isSet(value) {
|
|
18
18
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
19
19
|
}
|
|
@@ -27,12 +27,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
27
27
|
return "terminal";
|
|
28
28
|
return isSet(env.CI) ? "ci" : "pipe";
|
|
29
29
|
}
|
|
30
|
+
var MODES, AGENT_VARIABLES;
|
|
31
|
+
var init_mode = __esm(() => {
|
|
32
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
33
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
34
|
+
});
|
|
30
35
|
|
|
31
|
-
//
|
|
32
|
-
import process6 from "process";
|
|
33
|
-
|
|
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
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
36
37
|
function b(r) {
|
|
37
38
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
38
39
|
if (!G.test(e))
|
|
@@ -43,11 +44,6 @@ function b(r) {
|
|
|
43
44
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
44
45
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
45
46
|
}
|
|
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
47
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
52
48
|
if (e.FORCE_COLOR !== undefined)
|
|
53
49
|
return h.has(e.FORCE_COLOR);
|
|
@@ -84,13 +80,21 @@ function f(r, e = []) {
|
|
|
84
80
|
function Fe(r = {}) {
|
|
85
81
|
return f(r);
|
|
86
82
|
}
|
|
87
|
-
var
|
|
83
|
+
var G, B, h, o;
|
|
84
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
85
|
+
G = /^[a-f0-9]+$/i;
|
|
86
|
+
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") => {
|
|
87
|
+
let [l, n, c] = b(r);
|
|
88
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
89
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
90
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
91
|
+
o = Fe();
|
|
92
|
+
});
|
|
88
93
|
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
import process5 from "process";
|
|
94
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
95
|
+
var init_colors = __esm(() => {
|
|
96
|
+
init_chunk_x450vn3m();
|
|
97
|
+
});
|
|
94
98
|
|
|
95
99
|
// ../kit/src/config.ts
|
|
96
100
|
import { existsSync } from "fs";
|
|
@@ -106,6 +110,9 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
106
110
|
return;
|
|
107
111
|
}
|
|
108
112
|
}
|
|
113
|
+
var init_config = __esm(() => {
|
|
114
|
+
init_args();
|
|
115
|
+
});
|
|
109
116
|
|
|
110
117
|
// ../kit/src/user-config.ts
|
|
111
118
|
import { homedir } from "os";
|
|
@@ -118,13 +125,17 @@ function configBase(where = {}) {
|
|
|
118
125
|
function userConfigPath(bin, where = {}) {
|
|
119
126
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
120
127
|
}
|
|
128
|
+
var init_user_config = () => {};
|
|
121
129
|
|
|
122
130
|
// ../kit/src/theme.ts
|
|
131
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
132
|
+
import { homedir as homedir2 } from "os";
|
|
133
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
134
|
+
import process5 from "process";
|
|
123
135
|
function toLinear(channel) {
|
|
124
136
|
const value = channel / 255;
|
|
125
137
|
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
126
138
|
}
|
|
127
|
-
var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055)));
|
|
128
139
|
function toOklab(hex) {
|
|
129
140
|
const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
|
|
130
141
|
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
@@ -139,7 +150,6 @@ function fromOklab([lightness, a, b]) {
|
|
|
139
150
|
const channels = [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s];
|
|
140
151
|
return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
|
|
141
152
|
}
|
|
142
|
-
var ENDS = new Map;
|
|
143
153
|
function gradientAt(theme, ratio) {
|
|
144
154
|
if (theme.gradient === undefined)
|
|
145
155
|
return;
|
|
@@ -153,33 +163,11 @@ function gradientAt(theme, ratio) {
|
|
|
153
163
|
const [from, to] = ends;
|
|
154
164
|
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
155
165
|
}
|
|
156
|
-
var DEFAULT = {
|
|
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" },
|
|
159
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
160
|
-
bins: {},
|
|
161
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
162
|
-
};
|
|
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: "|" };
|
|
166
|
-
var PRESETS = {
|
|
167
|
-
default: {},
|
|
168
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
169
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
170
|
-
ascii: { glyphs: ASCII }
|
|
171
|
-
};
|
|
172
|
-
var STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
173
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
174
|
-
var CONTROL = /\p{Cc}/u;
|
|
175
|
-
var MAX_FILE_BYTES = 64 * 1024;
|
|
176
|
-
var SPACES = /\s+/;
|
|
177
166
|
function isColorSpec(spec) {
|
|
178
167
|
if (typeof spec === "number")
|
|
179
168
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
180
169
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
181
170
|
}
|
|
182
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
183
171
|
function cubeLevel(channel) {
|
|
184
172
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
185
173
|
}
|
|
@@ -284,7 +272,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
284
272
|
function endsWalk(home) {
|
|
285
273
|
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
286
274
|
}
|
|
287
|
-
var warned = new Set;
|
|
288
275
|
function warnOnce(message) {
|
|
289
276
|
if (warned.has(message))
|
|
290
277
|
return;
|
|
@@ -321,8 +308,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
321
308
|
}
|
|
322
309
|
return { theme, sources, preset };
|
|
323
310
|
}
|
|
324
|
-
var current;
|
|
325
|
-
var currentKey = "";
|
|
326
311
|
function activeTheme() {
|
|
327
312
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
328
313
|
if (current === undefined || key !== currentKey) {
|
|
@@ -331,8 +316,38 @@ function activeTheme() {
|
|
|
331
316
|
}
|
|
332
317
|
return current;
|
|
333
318
|
}
|
|
319
|
+
var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055))), ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
320
|
+
var init_theme = __esm(() => {
|
|
321
|
+
init_config();
|
|
322
|
+
init_user_config();
|
|
323
|
+
ENDS = new Map;
|
|
324
|
+
DEFAULT = {
|
|
325
|
+
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" },
|
|
326
|
+
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" },
|
|
327
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
328
|
+
bins: {},
|
|
329
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
330
|
+
};
|
|
331
|
+
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" };
|
|
332
|
+
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" };
|
|
333
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
334
|
+
PRESETS = {
|
|
335
|
+
default: {},
|
|
336
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
337
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
338
|
+
ascii: { glyphs: ASCII }
|
|
339
|
+
};
|
|
340
|
+
STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
341
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
342
|
+
CONTROL = /\p{Cc}/u;
|
|
343
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
344
|
+
SPACES = /\s+/;
|
|
345
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
346
|
+
warned = new Set;
|
|
347
|
+
});
|
|
334
348
|
|
|
335
349
|
// ../kit/src/style.ts
|
|
350
|
+
import process6 from "process";
|
|
336
351
|
function takesControlCodes(stream, env = process6.env) {
|
|
337
352
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
338
353
|
}
|
|
@@ -343,22 +358,28 @@ function role(name, stream, env = process6.env) {
|
|
|
343
358
|
const colors = paint(stream, env);
|
|
344
359
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
345
360
|
}
|
|
346
|
-
var STATUS_WORDS = {
|
|
347
|
-
passed: ["passed", "success", "succeeded", "ok"],
|
|
348
|
-
failed: ["failed", "failure", "error", "errored"],
|
|
349
|
-
running: ["running", "in_progress", "started", "holding"],
|
|
350
|
-
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
351
|
-
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
352
|
-
};
|
|
353
|
-
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
354
361
|
function link(text, url, stream, env = process6.env) {
|
|
355
362
|
if (takesControlCodes(stream, env))
|
|
356
363
|
return `\x1B]8;;${url}\x1B\\${text}\x1B]8;;\x1B\\`;
|
|
357
364
|
return text === url ? text : `${text} (${url})`;
|
|
358
365
|
}
|
|
366
|
+
var STATUS_WORDS, STATUS_OF;
|
|
367
|
+
var init_style = __esm(() => {
|
|
368
|
+
init_colors();
|
|
369
|
+
init_mode();
|
|
370
|
+
init_theme();
|
|
371
|
+
STATUS_WORDS = {
|
|
372
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
373
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
374
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
375
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
376
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
377
|
+
};
|
|
378
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
379
|
+
});
|
|
359
380
|
|
|
360
381
|
// ../kit/src/format.ts
|
|
361
|
-
|
|
382
|
+
import process7 from "process";
|
|
362
383
|
function formatSeconds(total) {
|
|
363
384
|
let rest = Math.max(0, Math.round(total));
|
|
364
385
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -379,7 +400,6 @@ function upTo(text, separator) {
|
|
|
379
400
|
const end = text.indexOf(separator);
|
|
380
401
|
return end === -1 ? text : text.slice(0, end);
|
|
381
402
|
}
|
|
382
|
-
var ESCAPE = String.fromCharCode(27);
|
|
383
403
|
function textWidth(text) {
|
|
384
404
|
return Bun.stringWidth(text);
|
|
385
405
|
}
|
|
@@ -389,14 +409,38 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
|
|
|
389
409
|
function printJson(value) {
|
|
390
410
|
console.log(jsonText(value));
|
|
391
411
|
}
|
|
412
|
+
var UNITS, ESCAPE;
|
|
413
|
+
var init_format = __esm(() => {
|
|
414
|
+
init_mode();
|
|
415
|
+
init_style();
|
|
416
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
417
|
+
ESCAPE = String.fromCharCode(27);
|
|
418
|
+
});
|
|
392
419
|
|
|
393
420
|
// ../kit/src/help.ts
|
|
394
421
|
import process8 from "process";
|
|
395
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
396
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
397
|
-
var FULL_STOP = /\.$/;
|
|
398
422
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
399
|
-
|
|
423
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
424
|
+
`);
|
|
425
|
+
const blank = lines.indexOf("");
|
|
426
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
427
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
428
|
+
const colon = synopses[0].indexOf(": ");
|
|
429
|
+
const inline = synopses[0].slice(colon + 2);
|
|
430
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
431
|
+
if (colon !== -1)
|
|
432
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
433
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
434
|
+
`)}`;
|
|
435
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
436
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
437
|
+
return [head, ...lead, ...rest].join(`
|
|
438
|
+
`);
|
|
439
|
+
}
|
|
440
|
+
function prose(line, colors) {
|
|
441
|
+
if (colors.cyan("x") === "x")
|
|
442
|
+
return line;
|
|
443
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
400
444
|
}
|
|
401
445
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
402
446
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -431,7 +475,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
431
475
|
return [];
|
|
432
476
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
433
477
|
}
|
|
434
|
-
var MAX_INLINE_CHOICES = 24;
|
|
435
478
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
436
479
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
437
480
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -446,9 +489,17 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
446
489
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
447
490
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
448
491
|
}
|
|
492
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
493
|
+
var init_help = __esm(() => {
|
|
494
|
+
init_mode();
|
|
495
|
+
init_style();
|
|
496
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
497
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
498
|
+
FULL_STOP = /\.$/;
|
|
499
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
500
|
+
});
|
|
449
501
|
|
|
450
502
|
// ../kit/src/text.ts
|
|
451
|
-
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
452
503
|
function stripAnsi(text) {
|
|
453
504
|
return text.replace(ANSI, "");
|
|
454
505
|
}
|
|
@@ -477,9 +528,13 @@ function closest(name, names) {
|
|
|
477
528
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
478
529
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
479
530
|
}
|
|
531
|
+
var ANSI;
|
|
532
|
+
var init_text = __esm(() => {
|
|
533
|
+
ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
534
|
+
});
|
|
535
|
+
|
|
480
536
|
// ../kit/src/input.ts
|
|
481
537
|
import process9 from "process";
|
|
482
|
-
var WHOLE = /^\d+$/;
|
|
483
538
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
484
539
|
if (value === undefined)
|
|
485
540
|
return fallback;
|
|
@@ -499,40 +554,25 @@ async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
|
499
554
|
fail(`no file ${path}`);
|
|
500
555
|
return file.text();
|
|
501
556
|
}
|
|
557
|
+
var WHOLE;
|
|
558
|
+
var init_input = __esm(() => {
|
|
559
|
+
init_args();
|
|
560
|
+
WHOLE = /^\d+$/;
|
|
561
|
+
});
|
|
502
562
|
|
|
503
563
|
// ../kit/src/args.ts
|
|
504
|
-
|
|
564
|
+
import process10 from "process";
|
|
565
|
+
import { parseArgs } from "util";
|
|
505
566
|
function jsonOption(holds) {
|
|
506
567
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
507
568
|
}
|
|
508
|
-
class Exit extends Error {
|
|
509
|
-
code;
|
|
510
|
-
hint;
|
|
511
|
-
constructor(message, code, hint) {
|
|
512
|
-
super(message);
|
|
513
|
-
this.code = code;
|
|
514
|
-
this.hint = hint;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
569
|
function fail(message, code = 2, hint) {
|
|
518
570
|
throw new Exit(message, code, hint);
|
|
519
571
|
}
|
|
520
|
-
|
|
521
|
-
class UsageError extends Exit {
|
|
522
|
-
constructor(message, hint) {
|
|
523
|
-
super(message, 2, hint);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
572
|
function badUsage(message) {
|
|
527
573
|
throw new UsageError(message);
|
|
528
574
|
}
|
|
529
575
|
|
|
530
|
-
class HelpShown extends Exit {
|
|
531
|
-
constructor() {
|
|
532
|
-
super("help shown", 0);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
|
|
536
576
|
class Completing {
|
|
537
577
|
options;
|
|
538
578
|
positionals;
|
|
@@ -543,11 +583,6 @@ class Completing {
|
|
|
543
583
|
this.candidates = candidates;
|
|
544
584
|
}
|
|
545
585
|
}
|
|
546
|
-
var completion = { active: false };
|
|
547
|
-
var OUTPUT_OPTIONS = {
|
|
548
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
549
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
550
|
-
};
|
|
551
586
|
function applyOutput(color, plain, env = process10.env) {
|
|
552
587
|
const when = plain === true ? "never" : color ?? "auto";
|
|
553
588
|
if (when === "auto")
|
|
@@ -701,7 +736,6 @@ function parseError(error) {
|
|
|
701
736
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
702
737
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
703
738
|
}
|
|
704
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
705
739
|
function nearestOption(message, options, allowNegative) {
|
|
706
740
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
707
741
|
if (typed === undefined)
|
|
@@ -717,6 +751,61 @@ function nearestOption(message, options, allowNegative) {
|
|
|
717
751
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
718
752
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
719
753
|
}
|
|
754
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
755
|
+
var init_args = __esm(() => {
|
|
756
|
+
init_format();
|
|
757
|
+
init_help();
|
|
758
|
+
init_text();
|
|
759
|
+
init_help();
|
|
760
|
+
init_input();
|
|
761
|
+
DASHES = /^-+/;
|
|
762
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
763
|
+
Exit = class Exit extends Error {
|
|
764
|
+
code;
|
|
765
|
+
hint;
|
|
766
|
+
[EXIT] = true;
|
|
767
|
+
constructor(message, code, hint) {
|
|
768
|
+
super(message);
|
|
769
|
+
this.code = code;
|
|
770
|
+
this.hint = hint;
|
|
771
|
+
}
|
|
772
|
+
static [Symbol.hasInstance](value) {
|
|
773
|
+
if (this !== Exit)
|
|
774
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
775
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
UsageError = class UsageError extends Exit {
|
|
779
|
+
constructor(message, hint) {
|
|
780
|
+
super(message, 2, hint);
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
HelpShown = class HelpShown extends Exit {
|
|
784
|
+
constructor() {
|
|
785
|
+
super("help shown", 0);
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
completion = { active: false };
|
|
789
|
+
OUTPUT_OPTIONS = {
|
|
790
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
791
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
792
|
+
};
|
|
793
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
// ../kit/src/folders.ts
|
|
797
|
+
var SKIPPED_FOLDERS;
|
|
798
|
+
var init_folders = __esm(() => {
|
|
799
|
+
init_user_config();
|
|
800
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
801
|
+
});
|
|
802
|
+
|
|
803
|
+
// src/view.ts
|
|
804
|
+
import process18 from "process";
|
|
805
|
+
|
|
806
|
+
// ../kit/src/index.ts
|
|
807
|
+
init_args();
|
|
808
|
+
|
|
720
809
|
// ../kit/src/argv.ts
|
|
721
810
|
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
722
811
|
import { resolve as resolve3 } from "path";
|
|
@@ -741,15 +830,73 @@ function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), scr
|
|
|
741
830
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
742
831
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
743
832
|
}
|
|
833
|
+
// ../kit/src/chart.ts
|
|
834
|
+
init_format();
|
|
835
|
+
init_mode();
|
|
836
|
+
init_style();
|
|
837
|
+
init_theme();
|
|
838
|
+
// ../kit/src/ci.ts
|
|
839
|
+
init_args();
|
|
840
|
+
init_format();
|
|
841
|
+
|
|
744
842
|
// ../kit/src/progress.ts
|
|
843
|
+
init_format();
|
|
844
|
+
init_style();
|
|
845
|
+
init_theme();
|
|
745
846
|
var ESC = String.fromCharCode(27);
|
|
746
847
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
747
848
|
var RESET_STYLE = `${ESC}[0m`;
|
|
748
849
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
850
|
+
|
|
851
|
+
// ../kit/src/ci.ts
|
|
852
|
+
init_style();
|
|
853
|
+
|
|
854
|
+
// ../kit/src/tool.ts
|
|
855
|
+
init_format();
|
|
749
856
|
// ../kit/src/cli.ts
|
|
857
|
+
init_args();
|
|
750
858
|
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
751
859
|
import { dirname as dirname3, join as join5 } from "path";
|
|
752
|
-
import
|
|
860
|
+
import process15 from "process";
|
|
861
|
+
|
|
862
|
+
// ../kit/src/askpass.ts
|
|
863
|
+
import process12 from "process";
|
|
864
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
865
|
+
async function askpassClient(argv) {
|
|
866
|
+
const socketPath = process12.env[SOCKET_VARIABLE];
|
|
867
|
+
if (socketPath === undefined)
|
|
868
|
+
return;
|
|
869
|
+
const request = { prompt: argv[0] ?? "", ...process12.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
870
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
871
|
+
let received = "";
|
|
872
|
+
try {
|
|
873
|
+
await Bun.connect({
|
|
874
|
+
unix: socketPath,
|
|
875
|
+
socket: {
|
|
876
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
877
|
+
`),
|
|
878
|
+
data: (_, chunk) => {
|
|
879
|
+
received += chunk.toString();
|
|
880
|
+
},
|
|
881
|
+
close: () => resolve(received),
|
|
882
|
+
error: () => resolve("")
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
} catch {
|
|
886
|
+
return 1;
|
|
887
|
+
}
|
|
888
|
+
const reply = await promise;
|
|
889
|
+
if (reply === "")
|
|
890
|
+
return 1;
|
|
891
|
+
const { answer } = JSON.parse(reply);
|
|
892
|
+
if (request.notice === true)
|
|
893
|
+
return 0;
|
|
894
|
+
if (answer === undefined)
|
|
895
|
+
return 1;
|
|
896
|
+
process12.stdout.write(`${answer}
|
|
897
|
+
`);
|
|
898
|
+
return 0;
|
|
899
|
+
}
|
|
753
900
|
|
|
754
901
|
// ../kit/src/completions.ts
|
|
755
902
|
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
@@ -812,28 +959,34 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
|
812
959
|
}
|
|
813
960
|
|
|
814
961
|
// ../kit/src/notify.ts
|
|
815
|
-
|
|
962
|
+
init_format();
|
|
963
|
+
init_mode();
|
|
964
|
+
import process13 from "process";
|
|
816
965
|
var NOTIFY_AFTER_MS = 1e4;
|
|
817
966
|
var CANCELLED = 130;
|
|
818
967
|
function base64(text) {
|
|
819
968
|
return Buffer.from(text).toString("base64");
|
|
820
969
|
}
|
|
821
|
-
function notification(title, body, env =
|
|
822
|
-
const id = `kit${
|
|
970
|
+
function notification(title, body, env = process13.env) {
|
|
971
|
+
const id = `kit${process13.pid}`;
|
|
823
972
|
const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
|
|
824
973
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
825
974
|
}
|
|
826
|
-
function notifyEnd(command, code, ms, { stream =
|
|
975
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
827
976
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
828
977
|
return;
|
|
829
978
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
830
979
|
}
|
|
831
980
|
|
|
981
|
+
// ../kit/src/cli.ts
|
|
982
|
+
init_style();
|
|
983
|
+
init_text();
|
|
984
|
+
|
|
832
985
|
// ../kit/src/usage.ts
|
|
833
986
|
import { appendFileSync, mkdirSync } from "fs";
|
|
834
987
|
import { homedir as homedir3 } from "os";
|
|
835
988
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
836
|
-
import
|
|
989
|
+
import process14 from "process";
|
|
837
990
|
|
|
838
991
|
// ../kit/src/logs.ts
|
|
839
992
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -847,14 +1000,14 @@ var usageError;
|
|
|
847
1000
|
function noteUsageError(message) {
|
|
848
1001
|
usageError = message;
|
|
849
1002
|
}
|
|
850
|
-
function stateHome(env =
|
|
1003
|
+
function stateHome(env = process14.env) {
|
|
851
1004
|
const dir = env.XDG_STATE_HOME;
|
|
852
1005
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
853
1006
|
}
|
|
854
|
-
function usagePath(env =
|
|
1007
|
+
function usagePath(env = process14.env) {
|
|
855
1008
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
856
1009
|
}
|
|
857
|
-
function usageRecorded(env =
|
|
1010
|
+
function usageRecorded(env = process14.env) {
|
|
858
1011
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
859
1012
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
860
1013
|
}
|
|
@@ -863,12 +1016,12 @@ function flagNames(argv) {
|
|
|
863
1016
|
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
864
1017
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
865
1018
|
}
|
|
866
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
1019
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
867
1020
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
868
1021
|
usageError = undefined;
|
|
869
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1022
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
870
1023
|
}
|
|
871
|
-
function recordUsage(entry, env =
|
|
1024
|
+
function recordUsage(entry, env = process14.env) {
|
|
872
1025
|
if (!usageRecorded(env))
|
|
873
1026
|
return;
|
|
874
1027
|
try {
|
|
@@ -890,8 +1043,8 @@ var TOP_OPTIONS = {
|
|
|
890
1043
|
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
891
1044
|
};
|
|
892
1045
|
function printError(prefix, message, hint, cause) {
|
|
893
|
-
const colors = paint(
|
|
894
|
-
const styled = takesControlCodes(
|
|
1046
|
+
const colors = paint(process15.stderr);
|
|
1047
|
+
const styled = takesControlCodes(process15.stderr);
|
|
895
1048
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
896
1049
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
897
1050
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1002,6 +1155,9 @@ function packageVersion(entry = Bun.main) {
|
|
|
1002
1155
|
}
|
|
1003
1156
|
}
|
|
1004
1157
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1158
|
+
const answered = await askpassClient(argv);
|
|
1159
|
+
if (answered !== undefined)
|
|
1160
|
+
return answered;
|
|
1005
1161
|
if (argv[0] === COMPLETE)
|
|
1006
1162
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1007
1163
|
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
@@ -1020,19 +1176,52 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1020
1176
|
notifyEnd(name, code, performance.now() - started);
|
|
1021
1177
|
if (usage !== false) {
|
|
1022
1178
|
try {
|
|
1023
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1179
|
+
recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
|
|
1024
1180
|
} catch {}
|
|
1025
1181
|
}
|
|
1026
1182
|
return code;
|
|
1027
1183
|
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1184
|
+
|
|
1185
|
+
// ../kit/src/index.ts
|
|
1186
|
+
init_config();
|
|
1187
|
+
|
|
1188
|
+
// ../kit/src/excerpt.ts
|
|
1189
|
+
init_text();
|
|
1190
|
+
|
|
1191
|
+
// ../kit/src/index.ts
|
|
1192
|
+
init_folders();
|
|
1193
|
+
init_format();
|
|
1194
|
+
|
|
1195
|
+
// ../kit/src/git.ts
|
|
1196
|
+
init_args();
|
|
1197
|
+
// ../kit/src/limit.ts
|
|
1198
|
+
init_args();
|
|
1199
|
+
|
|
1200
|
+
// ../kit/src/index.ts
|
|
1201
|
+
init_mode();
|
|
1202
|
+
|
|
1203
|
+
// ../kit/src/report.ts
|
|
1204
|
+
init_style();
|
|
1205
|
+
init_text();
|
|
1030
1206
|
// ../kit/src/secrets.ts
|
|
1031
1207
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1032
1208
|
// ../kit/src/sessions.ts
|
|
1033
1209
|
var {Glob } = globalThis.Bun;
|
|
1034
1210
|
var SESSION_FILES = new Glob("*.json");
|
|
1035
1211
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1212
|
+
|
|
1213
|
+
// ../kit/src/index.ts
|
|
1214
|
+
init_style();
|
|
1215
|
+
init_text();
|
|
1216
|
+
init_theme();
|
|
1217
|
+
init_user_config();
|
|
1218
|
+
|
|
1219
|
+
// ../kit/src/watch.ts
|
|
1220
|
+
init_args();
|
|
1221
|
+
init_input();
|
|
1222
|
+
init_style();
|
|
1223
|
+
// ../kit/src/workspace-root.ts
|
|
1224
|
+
init_user_config();
|
|
1036
1225
|
// src/code.ts
|
|
1037
1226
|
var WORD_START = /[a-z_$]/i;
|
|
1038
1227
|
var WORD = /^[\w$-]+/;
|
|
@@ -1564,8 +1753,8 @@ ${theme.dim("\u2500".repeat(rule))}
|
|
|
1564
1753
|
}
|
|
1565
1754
|
|
|
1566
1755
|
// src/theme.ts
|
|
1567
|
-
import
|
|
1568
|
-
function themeFor(stream =
|
|
1756
|
+
import process17 from "process";
|
|
1757
|
+
function themeFor(stream = process17.stdout, env = process17.env) {
|
|
1569
1758
|
const colors = paint(stream, env);
|
|
1570
1759
|
const accent = role("accent", stream, env);
|
|
1571
1760
|
const path = role("path", stream, env);
|
|
@@ -1596,8 +1785,8 @@ var MARKDOWN_FILE = /\.(?:md|markdown|mdx)$/i;
|
|
|
1596
1785
|
var DIFF_FILE = /\.(?:diff|patch)$/i;
|
|
1597
1786
|
var USAGE = `view [options] [file]: shows a markdown file, a source file or a git diff in the colours of the other @kaynooo CLIs
|
|
1598
1787
|
|
|
1599
|
-
A file, or what is piped on stdin (or - for stdin). A source file
|
|
1600
|
-
Lines wrap to the terminal width
|
|
1788
|
+
A file, or what is piped on stdin (or - for stdin). A source file 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, and anything else is markdown; --diff and --markdown force one.
|
|
1789
|
+
Lines wrap to the terminal width and a long output on a terminal goes through $PAGER, unless --no-pager. No colour with NO_COLOR, a pipe or --plain.`;
|
|
1601
1790
|
var EXITS = [[0, "it showed the text"], [1, "there is nothing to show"], [2, "a usage error or a file that is missing"]];
|
|
1602
1791
|
var OPTIONS = {
|
|
1603
1792
|
diff: { type: "boolean", description: "show the text as a diff" },
|
|
@@ -1612,7 +1801,7 @@ function columnsOf(variable) {
|
|
|
1612
1801
|
const columns = Number(variable);
|
|
1613
1802
|
return Number.isInteger(columns) && columns >= 20 ? columns : DEFAULT_WIDTH;
|
|
1614
1803
|
}
|
|
1615
|
-
function pagerCommand(pager =
|
|
1804
|
+
function pagerCommand(pager = process18.env.PAGER) {
|
|
1616
1805
|
return pager === undefined || pager.trim() === "" || pager.trim() === "less" ? ["less", "-FRX"] : ["sh", "-c", pager];
|
|
1617
1806
|
}
|
|
1618
1807
|
async function page(text) {
|
|
@@ -1624,7 +1813,7 @@ async function page(text) {
|
|
|
1624
1813
|
} catch {}
|
|
1625
1814
|
await pager.exited;
|
|
1626
1815
|
} catch {
|
|
1627
|
-
|
|
1816
|
+
process18.stdout.write(text);
|
|
1628
1817
|
}
|
|
1629
1818
|
}
|
|
1630
1819
|
async function main(args) {
|
|
@@ -1637,8 +1826,8 @@ async function main(args) {
|
|
|
1637
1826
|
const text = await readInput(path, { noStdin: "give a file, or pipe the text on stdin" });
|
|
1638
1827
|
if (text.trim() === "")
|
|
1639
1828
|
fail("nothing to show", 1);
|
|
1640
|
-
const width = wholeNumber(values.width, "width",
|
|
1641
|
-
const theme = themeFor(
|
|
1829
|
+
const width = wholeNumber(values.width, "width", process18.stdout.isTTY === true ? process18.stdout.columns || DEFAULT_WIDTH : columnsOf(process18.env.COLUMNS), 20);
|
|
1830
|
+
const theme = themeFor(process18.stdout);
|
|
1642
1831
|
const language = values.lang === undefined ? languageOf(path) : languageOf(values.lang);
|
|
1643
1832
|
if (values.lang !== undefined && language === undefined)
|
|
1644
1833
|
badUsage(`unknown language ${values.lang}`);
|
|
@@ -1655,12 +1844,12 @@ async function main(args) {
|
|
|
1655
1844
|
printJson({ kind: isCode ? "code" : kind, language: isCode ? language ?? null : null, text: stripAnsi(render(themeFor({ isTTY: false }), values.lines ?? false)) });
|
|
1656
1845
|
return 0;
|
|
1657
1846
|
}
|
|
1658
|
-
const shown = render(theme, values.lines ??
|
|
1659
|
-
if (
|
|
1660
|
-
`).length > (
|
|
1847
|
+
const shown = render(theme, values.lines ?? process18.stdout.isTTY === true);
|
|
1848
|
+
if (process18.stdout.isTTY === true && values.pager !== false && shown.split(`
|
|
1849
|
+
`).length > (process18.stdout.rows || 24))
|
|
1661
1850
|
await page(shown);
|
|
1662
1851
|
else
|
|
1663
|
-
|
|
1852
|
+
process18.stdout.write(shown);
|
|
1664
1853
|
return 0;
|
|
1665
1854
|
}
|
|
1666
|
-
|
|
1855
|
+
process18.exitCode = await runMain({ name: "view", run: main });
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-view",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.3",
|
|
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",
|
|
8
|
-
"homepage": "https://
|
|
8
|
+
"homepage": "https://github.com/Kayno0o/cli/tree/main/packages/view#readme",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://
|
|
11
|
+
"url": "git+https://github.com/Kayno0o/cli.git",
|
|
12
12
|
"directory": "packages/view"
|
|
13
13
|
},
|
|
14
|
-
"bugs": "https://
|
|
14
|
+
"bugs": "https://github.com/Kayno0o/cli/issues",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"cli",
|
|
17
17
|
"markdown",
|
|
@@ -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.46.0"
|
|
39
39
|
}
|
|
40
40
|
}
|