@kaynooo/cli-view 0.7.0 → 0.7.4
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 +434 -140
- 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,25 +110,35 @@ 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";
|
|
112
|
-
import { join as join2 } from "path";
|
|
119
|
+
import { isAbsolute, join as join2 } from "path";
|
|
113
120
|
import process4 from "process";
|
|
121
|
+
function xdgFolder(value, fallback) {
|
|
122
|
+
return value !== undefined && isAbsolute(value) ? value : fallback;
|
|
123
|
+
}
|
|
114
124
|
function configBase(where = {}) {
|
|
115
125
|
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
116
|
-
return xdg
|
|
126
|
+
return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
|
|
117
127
|
}
|
|
118
128
|
function userConfigPath(bin, where = {}) {
|
|
119
129
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
120
130
|
}
|
|
131
|
+
var init_user_config = () => {};
|
|
121
132
|
|
|
122
133
|
// ../kit/src/theme.ts
|
|
134
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
135
|
+
import { homedir as homedir2 } from "os";
|
|
136
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
137
|
+
import process5 from "process";
|
|
123
138
|
function toLinear(channel) {
|
|
124
139
|
const value = channel / 255;
|
|
125
140
|
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
126
141
|
}
|
|
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
142
|
function toOklab(hex) {
|
|
129
143
|
const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
|
|
130
144
|
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
@@ -139,7 +153,6 @@ function fromOklab([lightness, a, b]) {
|
|
|
139
153
|
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
154
|
return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
|
|
141
155
|
}
|
|
142
|
-
var ENDS = new Map;
|
|
143
156
|
function gradientAt(theme, ratio) {
|
|
144
157
|
if (theme.gradient === undefined)
|
|
145
158
|
return;
|
|
@@ -153,33 +166,11 @@ function gradientAt(theme, ratio) {
|
|
|
153
166
|
const [from, to] = ends;
|
|
154
167
|
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
155
168
|
}
|
|
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
169
|
function isColorSpec(spec) {
|
|
178
170
|
if (typeof spec === "number")
|
|
179
171
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
180
172
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
181
173
|
}
|
|
182
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
183
174
|
function cubeLevel(channel) {
|
|
184
175
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
185
176
|
}
|
|
@@ -284,7 +275,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
284
275
|
function endsWalk(home) {
|
|
285
276
|
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
286
277
|
}
|
|
287
|
-
var warned = new Set;
|
|
288
278
|
function warnOnce(message) {
|
|
289
279
|
if (warned.has(message))
|
|
290
280
|
return;
|
|
@@ -321,8 +311,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
321
311
|
}
|
|
322
312
|
return { theme, sources, preset };
|
|
323
313
|
}
|
|
324
|
-
var current;
|
|
325
|
-
var currentKey = "";
|
|
326
314
|
function activeTheme() {
|
|
327
315
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
328
316
|
if (current === undefined || key !== currentKey) {
|
|
@@ -331,8 +319,38 @@ function activeTheme() {
|
|
|
331
319
|
}
|
|
332
320
|
return current;
|
|
333
321
|
}
|
|
322
|
+
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 = "";
|
|
323
|
+
var init_theme = __esm(() => {
|
|
324
|
+
init_config();
|
|
325
|
+
init_user_config();
|
|
326
|
+
ENDS = new Map;
|
|
327
|
+
DEFAULT = {
|
|
328
|
+
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" },
|
|
329
|
+
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" },
|
|
330
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
331
|
+
bins: {},
|
|
332
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
333
|
+
};
|
|
334
|
+
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" };
|
|
335
|
+
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" };
|
|
336
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
337
|
+
PRESETS = {
|
|
338
|
+
default: {},
|
|
339
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
340
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
341
|
+
ascii: { glyphs: ASCII }
|
|
342
|
+
};
|
|
343
|
+
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"]);
|
|
344
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
345
|
+
CONTROL = /\p{Cc}/u;
|
|
346
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
347
|
+
SPACES = /\s+/;
|
|
348
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
349
|
+
warned = new Set;
|
|
350
|
+
});
|
|
334
351
|
|
|
335
352
|
// ../kit/src/style.ts
|
|
353
|
+
import process6 from "process";
|
|
336
354
|
function takesControlCodes(stream, env = process6.env) {
|
|
337
355
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
338
356
|
}
|
|
@@ -343,22 +361,28 @@ function role(name, stream, env = process6.env) {
|
|
|
343
361
|
const colors = paint(stream, env);
|
|
344
362
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
345
363
|
}
|
|
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
364
|
function link(text, url, stream, env = process6.env) {
|
|
355
365
|
if (takesControlCodes(stream, env))
|
|
356
366
|
return `\x1B]8;;${url}\x1B\\${text}\x1B]8;;\x1B\\`;
|
|
357
367
|
return text === url ? text : `${text} (${url})`;
|
|
358
368
|
}
|
|
369
|
+
var STATUS_WORDS, STATUS_OF;
|
|
370
|
+
var init_style = __esm(() => {
|
|
371
|
+
init_colors();
|
|
372
|
+
init_mode();
|
|
373
|
+
init_theme();
|
|
374
|
+
STATUS_WORDS = {
|
|
375
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
376
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
377
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
378
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
379
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
380
|
+
};
|
|
381
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
382
|
+
});
|
|
359
383
|
|
|
360
384
|
// ../kit/src/format.ts
|
|
361
|
-
|
|
385
|
+
import process7 from "process";
|
|
362
386
|
function formatSeconds(total) {
|
|
363
387
|
let rest = Math.max(0, Math.round(total));
|
|
364
388
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -379,7 +403,6 @@ function upTo(text, separator) {
|
|
|
379
403
|
const end = text.indexOf(separator);
|
|
380
404
|
return end === -1 ? text : text.slice(0, end);
|
|
381
405
|
}
|
|
382
|
-
var ESCAPE = String.fromCharCode(27);
|
|
383
406
|
function textWidth(text) {
|
|
384
407
|
return Bun.stringWidth(text);
|
|
385
408
|
}
|
|
@@ -389,14 +412,38 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
|
|
|
389
412
|
function printJson(value) {
|
|
390
413
|
console.log(jsonText(value));
|
|
391
414
|
}
|
|
415
|
+
var UNITS, ESCAPE;
|
|
416
|
+
var init_format = __esm(() => {
|
|
417
|
+
init_mode();
|
|
418
|
+
init_style();
|
|
419
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
420
|
+
ESCAPE = String.fromCharCode(27);
|
|
421
|
+
});
|
|
392
422
|
|
|
393
423
|
// ../kit/src/help.ts
|
|
394
424
|
import process8 from "process";
|
|
395
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
396
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
397
|
-
var FULL_STOP = /\.$/;
|
|
398
425
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
399
|
-
|
|
426
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
427
|
+
`);
|
|
428
|
+
const blank = lines.indexOf("");
|
|
429
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
430
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
431
|
+
const colon = synopses[0].indexOf(": ");
|
|
432
|
+
const inline = synopses[0].slice(colon + 2);
|
|
433
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
434
|
+
if (colon !== -1)
|
|
435
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
436
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
437
|
+
`)}`;
|
|
438
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
439
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
440
|
+
return [head, ...lead, ...rest].join(`
|
|
441
|
+
`);
|
|
442
|
+
}
|
|
443
|
+
function prose(line, colors) {
|
|
444
|
+
if (colors.cyan("x") === "x")
|
|
445
|
+
return line;
|
|
446
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
400
447
|
}
|
|
401
448
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
402
449
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -431,7 +478,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
431
478
|
return [];
|
|
432
479
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
433
480
|
}
|
|
434
|
-
var MAX_INLINE_CHOICES = 24;
|
|
435
481
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
436
482
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
437
483
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -446,12 +492,31 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
446
492
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
447
493
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
448
494
|
}
|
|
495
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
496
|
+
var init_help = __esm(() => {
|
|
497
|
+
init_mode();
|
|
498
|
+
init_style();
|
|
499
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
500
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
501
|
+
FULL_STOP = /\.$/;
|
|
502
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
503
|
+
});
|
|
449
504
|
|
|
450
505
|
// ../kit/src/text.ts
|
|
451
|
-
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
452
506
|
function stripAnsi(text) {
|
|
453
507
|
return text.replace(ANSI, "");
|
|
454
508
|
}
|
|
509
|
+
function stripControls(text) {
|
|
510
|
+
return text.replace(CONTROLS, "");
|
|
511
|
+
}
|
|
512
|
+
function escapeControls(text) {
|
|
513
|
+
return text.replace(CONTROLS, (char) => {
|
|
514
|
+
const code = char.charCodeAt(0);
|
|
515
|
+
if (code === 127)
|
|
516
|
+
return "^?";
|
|
517
|
+
return code < 128 ? `^${String.fromCharCode(code + 64)}` : `M-^${String.fromCharCode(code - 64)}`;
|
|
518
|
+
});
|
|
519
|
+
}
|
|
455
520
|
function distance(a, b) {
|
|
456
521
|
const left = [...a];
|
|
457
522
|
const right = [...b];
|
|
@@ -477,9 +542,14 @@ function closest(name, names) {
|
|
|
477
542
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
478
543
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
479
544
|
}
|
|
545
|
+
var ANSI, CONTROLS;
|
|
546
|
+
var init_text = __esm(() => {
|
|
547
|
+
ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
548
|
+
CONTROLS = /[\x00-\x08\x0B-\x1F\x7F-\x9F]/g;
|
|
549
|
+
});
|
|
550
|
+
|
|
480
551
|
// ../kit/src/input.ts
|
|
481
552
|
import process9 from "process";
|
|
482
|
-
var WHOLE = /^\d+$/;
|
|
483
553
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
484
554
|
if (value === undefined)
|
|
485
555
|
return fallback;
|
|
@@ -499,40 +569,25 @@ async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
|
499
569
|
fail(`no file ${path}`);
|
|
500
570
|
return file.text();
|
|
501
571
|
}
|
|
572
|
+
var WHOLE;
|
|
573
|
+
var init_input = __esm(() => {
|
|
574
|
+
init_args();
|
|
575
|
+
WHOLE = /^\d+$/;
|
|
576
|
+
});
|
|
502
577
|
|
|
503
578
|
// ../kit/src/args.ts
|
|
504
|
-
|
|
579
|
+
import process10 from "process";
|
|
580
|
+
import { parseArgs } from "util";
|
|
505
581
|
function jsonOption(holds) {
|
|
506
582
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
507
583
|
}
|
|
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
584
|
function fail(message, code = 2, hint) {
|
|
518
585
|
throw new Exit(message, code, hint);
|
|
519
586
|
}
|
|
520
|
-
|
|
521
|
-
class UsageError extends Exit {
|
|
522
|
-
constructor(message, hint) {
|
|
523
|
-
super(message, 2, hint);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
587
|
function badUsage(message) {
|
|
527
588
|
throw new UsageError(message);
|
|
528
589
|
}
|
|
529
590
|
|
|
530
|
-
class HelpShown extends Exit {
|
|
531
|
-
constructor() {
|
|
532
|
-
super("help shown", 0);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
|
|
536
591
|
class Completing {
|
|
537
592
|
options;
|
|
538
593
|
positionals;
|
|
@@ -543,11 +598,6 @@ class Completing {
|
|
|
543
598
|
this.candidates = candidates;
|
|
544
599
|
}
|
|
545
600
|
}
|
|
546
|
-
var completion = { active: false };
|
|
547
|
-
var OUTPUT_OPTIONS = {
|
|
548
|
-
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
549
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
550
|
-
};
|
|
551
601
|
function applyOutput(color, plain, env = process10.env) {
|
|
552
602
|
const when = plain === true ? "never" : color ?? "auto";
|
|
553
603
|
if (when === "auto")
|
|
@@ -701,7 +751,6 @@ function parseError(error) {
|
|
|
701
751
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
702
752
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
703
753
|
}
|
|
704
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
705
754
|
function nearestOption(message, options, allowNegative) {
|
|
706
755
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
707
756
|
if (typed === undefined)
|
|
@@ -717,6 +766,61 @@ function nearestOption(message, options, allowNegative) {
|
|
|
717
766
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
718
767
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
719
768
|
}
|
|
769
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
770
|
+
var init_args = __esm(() => {
|
|
771
|
+
init_format();
|
|
772
|
+
init_help();
|
|
773
|
+
init_text();
|
|
774
|
+
init_help();
|
|
775
|
+
init_input();
|
|
776
|
+
DASHES = /^-+/;
|
|
777
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
778
|
+
Exit = class Exit extends Error {
|
|
779
|
+
code;
|
|
780
|
+
hint;
|
|
781
|
+
[EXIT] = true;
|
|
782
|
+
constructor(message, code, hint) {
|
|
783
|
+
super(message);
|
|
784
|
+
this.code = code;
|
|
785
|
+
this.hint = hint;
|
|
786
|
+
}
|
|
787
|
+
static [Symbol.hasInstance](value) {
|
|
788
|
+
if (this !== Exit)
|
|
789
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
790
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
UsageError = class UsageError extends Exit {
|
|
794
|
+
constructor(message, hint) {
|
|
795
|
+
super(message, 2, hint);
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
HelpShown = class HelpShown extends Exit {
|
|
799
|
+
constructor() {
|
|
800
|
+
super("help shown", 0);
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
completion = { active: false };
|
|
804
|
+
OUTPUT_OPTIONS = {
|
|
805
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
806
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
807
|
+
};
|
|
808
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
// ../kit/src/folders.ts
|
|
812
|
+
var SKIPPED_FOLDERS;
|
|
813
|
+
var init_folders = __esm(() => {
|
|
814
|
+
init_user_config();
|
|
815
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
// src/view.ts
|
|
819
|
+
import process18 from "process";
|
|
820
|
+
|
|
821
|
+
// ../kit/src/index.ts
|
|
822
|
+
init_args();
|
|
823
|
+
|
|
720
824
|
// ../kit/src/argv.ts
|
|
721
825
|
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
722
826
|
import { resolve as resolve3 } from "path";
|
|
@@ -741,45 +845,176 @@ function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), scr
|
|
|
741
845
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
742
846
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
743
847
|
}
|
|
848
|
+
// ../kit/src/chart.ts
|
|
849
|
+
init_format();
|
|
850
|
+
init_mode();
|
|
851
|
+
init_style();
|
|
852
|
+
init_theme();
|
|
853
|
+
// ../kit/src/ci.ts
|
|
854
|
+
init_args();
|
|
855
|
+
init_format();
|
|
856
|
+
|
|
744
857
|
// ../kit/src/progress.ts
|
|
858
|
+
init_format();
|
|
859
|
+
|
|
860
|
+
// ../kit/src/process.ts
|
|
861
|
+
var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
|
|
862
|
+
|
|
863
|
+
// ../kit/src/progress.ts
|
|
864
|
+
init_style();
|
|
865
|
+
init_theme();
|
|
745
866
|
var ESC = String.fromCharCode(27);
|
|
746
867
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
747
868
|
var RESET_STYLE = `${ESC}[0m`;
|
|
748
869
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
870
|
+
|
|
871
|
+
// ../kit/src/ci.ts
|
|
872
|
+
init_style();
|
|
873
|
+
|
|
874
|
+
// ../kit/src/tool.ts
|
|
875
|
+
init_format();
|
|
749
876
|
// ../kit/src/cli.ts
|
|
877
|
+
init_args();
|
|
750
878
|
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
751
879
|
import { dirname as dirname3, join as join5 } from "path";
|
|
752
|
-
import
|
|
880
|
+
import process15 from "process";
|
|
753
881
|
|
|
754
|
-
// ../kit/src/
|
|
882
|
+
// ../kit/src/askpass.ts
|
|
755
883
|
import process12 from "process";
|
|
884
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
885
|
+
async function askpassClient(argv) {
|
|
886
|
+
const socketPath = process12.env[SOCKET_VARIABLE];
|
|
887
|
+
if (socketPath === undefined)
|
|
888
|
+
return;
|
|
889
|
+
const request = { prompt: argv[0] ?? "", ...process12.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
890
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
891
|
+
let received = "";
|
|
892
|
+
try {
|
|
893
|
+
await Bun.connect({
|
|
894
|
+
unix: socketPath,
|
|
895
|
+
socket: {
|
|
896
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
897
|
+
`),
|
|
898
|
+
data: (_, chunk) => {
|
|
899
|
+
received += chunk.toString();
|
|
900
|
+
},
|
|
901
|
+
close: () => resolve(received),
|
|
902
|
+
error: () => resolve("")
|
|
903
|
+
}
|
|
904
|
+
});
|
|
905
|
+
} catch {
|
|
906
|
+
return 1;
|
|
907
|
+
}
|
|
908
|
+
const reply = await promise;
|
|
909
|
+
if (reply === "")
|
|
910
|
+
return 1;
|
|
911
|
+
const { answer } = JSON.parse(reply);
|
|
912
|
+
if (request.notice === true)
|
|
913
|
+
return 0;
|
|
914
|
+
if (answer === undefined)
|
|
915
|
+
return 1;
|
|
916
|
+
process12.stdout.write(`${answer}
|
|
917
|
+
`);
|
|
918
|
+
return 0;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// ../kit/src/completions.ts
|
|
922
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
923
|
+
var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
924
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
925
|
+
set -l current (commandline -ct)
|
|
926
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
927
|
+
if test "$line" = __files__
|
|
928
|
+
__fish_complete_path $current
|
|
929
|
+
else
|
|
930
|
+
echo $line
|
|
931
|
+
end
|
|
932
|
+
end
|
|
933
|
+
end`;
|
|
934
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
935
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
936
|
+
local -a lines
|
|
937
|
+
COMPREPLY=()
|
|
938
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
939
|
+
for line in "\${lines[@]}"; do
|
|
940
|
+
if [[ $line == __files__ ]]; then
|
|
941
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
942
|
+
else
|
|
943
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
944
|
+
fi
|
|
945
|
+
done
|
|
946
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
947
|
+
}`;
|
|
948
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
949
|
+
local line
|
|
950
|
+
local -a described plain
|
|
951
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
952
|
+
if [[ $line == __files__ ]]; then
|
|
953
|
+
_files
|
|
954
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
955
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
956
|
+
else
|
|
957
|
+
plain+=("$line")
|
|
958
|
+
fi
|
|
959
|
+
done
|
|
960
|
+
(( \${#described} )) && _describe -V value described
|
|
961
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
962
|
+
return 0
|
|
963
|
+
}`;
|
|
964
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
965
|
+
if (shell === "fish")
|
|
966
|
+
return `${header}
|
|
967
|
+
${FISH_FUNCTION}
|
|
968
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
969
|
+
`).join("")}`;
|
|
970
|
+
if (shell === "bash")
|
|
971
|
+
return `${header}
|
|
972
|
+
${BASH_FUNCTION}
|
|
973
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
974
|
+
`;
|
|
975
|
+
return `${header}
|
|
976
|
+
${ZSH_FUNCTION}
|
|
977
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
978
|
+
`;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
// ../kit/src/notify.ts
|
|
982
|
+
init_format();
|
|
983
|
+
init_mode();
|
|
984
|
+
import process13 from "process";
|
|
756
985
|
var NOTIFY_AFTER_MS = 1e4;
|
|
757
986
|
var CANCELLED = 130;
|
|
758
987
|
function base64(text) {
|
|
759
988
|
return Buffer.from(text).toString("base64");
|
|
760
989
|
}
|
|
761
|
-
function notification(title, body, env =
|
|
762
|
-
const id = `kit${
|
|
990
|
+
function notification(title, body, env = process13.env) {
|
|
991
|
+
const id = `kit${process13.pid}`;
|
|
763
992
|
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\\`];
|
|
764
993
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
765
994
|
}
|
|
766
|
-
function notifyEnd(command, code, ms, { stream =
|
|
995
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
767
996
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
768
997
|
return;
|
|
769
998
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
770
999
|
}
|
|
771
1000
|
|
|
1001
|
+
// ../kit/src/cli.ts
|
|
1002
|
+
init_style();
|
|
1003
|
+
init_text();
|
|
1004
|
+
|
|
772
1005
|
// ../kit/src/usage.ts
|
|
773
1006
|
import { appendFileSync, mkdirSync } from "fs";
|
|
774
1007
|
import { homedir as homedir3 } from "os";
|
|
775
|
-
import { dirname as dirname2,
|
|
776
|
-
import
|
|
1008
|
+
import { dirname as dirname2, join as join4 } from "path";
|
|
1009
|
+
import process14 from "process";
|
|
777
1010
|
|
|
778
1011
|
// ../kit/src/logs.ts
|
|
1012
|
+
init_user_config();
|
|
779
1013
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
780
1014
|
var CLI_FOLDER = "kaynooo-cli";
|
|
781
1015
|
|
|
782
1016
|
// ../kit/src/usage.ts
|
|
1017
|
+
init_user_config();
|
|
783
1018
|
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
784
1019
|
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
785
1020
|
var LONGEST_NAME = 40;
|
|
@@ -787,14 +1022,13 @@ var usageError;
|
|
|
787
1022
|
function noteUsageError(message) {
|
|
788
1023
|
usageError = message;
|
|
789
1024
|
}
|
|
790
|
-
function stateHome(env =
|
|
791
|
-
|
|
792
|
-
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1025
|
+
function stateHome(env = process14.env) {
|
|
1026
|
+
return xdgFolder(env.XDG_STATE_HOME, join4(homedir3(), ".local", "state"));
|
|
793
1027
|
}
|
|
794
|
-
function usagePath(env =
|
|
1028
|
+
function usagePath(env = process14.env) {
|
|
795
1029
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
796
1030
|
}
|
|
797
|
-
function usageRecorded(env =
|
|
1031
|
+
function usageRecorded(env = process14.env) {
|
|
798
1032
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
799
1033
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
800
1034
|
}
|
|
@@ -803,12 +1037,12 @@ function flagNames(argv) {
|
|
|
803
1037
|
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
804
1038
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
805
1039
|
}
|
|
806
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
1040
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
807
1041
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
808
1042
|
usageError = undefined;
|
|
809
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1043
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
810
1044
|
}
|
|
811
|
-
function recordUsage(entry, env =
|
|
1045
|
+
function recordUsage(entry, env = process14.env) {
|
|
812
1046
|
if (!usageRecorded(env))
|
|
813
1047
|
return;
|
|
814
1048
|
try {
|
|
@@ -824,10 +1058,14 @@ var LEVEL_OPTIONS = {
|
|
|
824
1058
|
...OUTPUT_OPTIONS,
|
|
825
1059
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
826
1060
|
};
|
|
827
|
-
var TOP_OPTIONS = {
|
|
1061
|
+
var TOP_OPTIONS = {
|
|
1062
|
+
...LEVEL_OPTIONS,
|
|
1063
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1064
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1065
|
+
};
|
|
828
1066
|
function printError(prefix, message, hint, cause) {
|
|
829
|
-
const colors = paint(
|
|
830
|
-
const styled = takesControlCodes(
|
|
1067
|
+
const colors = paint(process15.stderr);
|
|
1068
|
+
const styled = takesControlCodes(process15.stderr);
|
|
831
1069
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
832
1070
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
833
1071
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -904,6 +1142,19 @@ async function leafCandidates(run, words) {
|
|
|
904
1142
|
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
905
1143
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
906
1144
|
}
|
|
1145
|
+
var COMPLETIONS = "--completions";
|
|
1146
|
+
function flagValue([flag = "", ...rest]) {
|
|
1147
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1148
|
+
}
|
|
1149
|
+
function printCompletionScript(name, args) {
|
|
1150
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1151
|
+
if (shell === undefined || args.length !== 1) {
|
|
1152
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1153
|
+
return 2;
|
|
1154
|
+
}
|
|
1155
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1156
|
+
return 0;
|
|
1157
|
+
}
|
|
907
1158
|
async function printCandidates(found) {
|
|
908
1159
|
for (const line of await found)
|
|
909
1160
|
console.log(line);
|
|
@@ -925,8 +1176,13 @@ function packageVersion(entry = Bun.main) {
|
|
|
925
1176
|
}
|
|
926
1177
|
}
|
|
927
1178
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1179
|
+
const answered = await askpassClient(argv);
|
|
1180
|
+
if (answered !== undefined)
|
|
1181
|
+
return answered;
|
|
928
1182
|
if (argv[0] === COMPLETE)
|
|
929
1183
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1184
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1185
|
+
return printCompletionScript(name, flagValue(argv));
|
|
930
1186
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
931
1187
|
console.log(version ?? packageVersion());
|
|
932
1188
|
return 0;
|
|
@@ -941,19 +1197,53 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
941
1197
|
notifyEnd(name, code, performance.now() - started);
|
|
942
1198
|
if (usage !== false) {
|
|
943
1199
|
try {
|
|
944
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1200
|
+
recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
|
|
945
1201
|
} catch {}
|
|
946
1202
|
}
|
|
947
1203
|
return code;
|
|
948
1204
|
}
|
|
949
|
-
|
|
950
|
-
|
|
1205
|
+
|
|
1206
|
+
// ../kit/src/index.ts
|
|
1207
|
+
init_config();
|
|
1208
|
+
|
|
1209
|
+
// ../kit/src/excerpt.ts
|
|
1210
|
+
init_text();
|
|
1211
|
+
|
|
1212
|
+
// ../kit/src/index.ts
|
|
1213
|
+
init_folders();
|
|
1214
|
+
init_format();
|
|
1215
|
+
|
|
1216
|
+
// ../kit/src/git.ts
|
|
1217
|
+
init_args();
|
|
1218
|
+
// ../kit/src/limit.ts
|
|
1219
|
+
init_args();
|
|
1220
|
+
|
|
1221
|
+
// ../kit/src/index.ts
|
|
1222
|
+
init_mode();
|
|
1223
|
+
|
|
1224
|
+
// ../kit/src/report.ts
|
|
1225
|
+
init_style();
|
|
1226
|
+
init_text();
|
|
951
1227
|
// ../kit/src/secrets.ts
|
|
952
1228
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1229
|
+
var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
|
|
953
1230
|
// ../kit/src/sessions.ts
|
|
954
1231
|
var {Glob } = globalThis.Bun;
|
|
955
1232
|
var SESSION_FILES = new Glob("*.json");
|
|
956
1233
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1234
|
+
|
|
1235
|
+
// ../kit/src/index.ts
|
|
1236
|
+
init_style();
|
|
1237
|
+
init_text();
|
|
1238
|
+
init_theme();
|
|
1239
|
+
init_user_config();
|
|
1240
|
+
|
|
1241
|
+
// ../kit/src/watch.ts
|
|
1242
|
+
init_args();
|
|
1243
|
+
init_input();
|
|
1244
|
+
init_style();
|
|
1245
|
+
// ../kit/src/workspace-root.ts
|
|
1246
|
+
init_user_config();
|
|
957
1247
|
// src/code.ts
|
|
958
1248
|
var WORD_START = /[a-z_$]/i;
|
|
959
1249
|
var WORD = /^[\w$-]+/;
|
|
@@ -1131,7 +1421,9 @@ function highlight(source, name, theme) {
|
|
|
1131
1421
|
return out;
|
|
1132
1422
|
}
|
|
1133
1423
|
function renderCode(source, name, theme, lineNumbers) {
|
|
1134
|
-
const text = source.
|
|
1424
|
+
const text = escapeControls(source.replaceAll(`\r
|
|
1425
|
+
`, `
|
|
1426
|
+
`)).replace(TRAILING_NEWLINE, "");
|
|
1135
1427
|
const shown = name === undefined ? text : highlight(text, name, theme);
|
|
1136
1428
|
if (!lineNumbers)
|
|
1137
1429
|
return `${shown}
|
|
@@ -1152,6 +1444,7 @@ var NEW_FILE = /^\+\+\+ (?:b\/)?([^\t]*)/;
|
|
|
1152
1444
|
var COMMIT = /^(commit )([0-9a-f]{7,40})(.*)$/;
|
|
1153
1445
|
var HUNK_LINE = new Set([" ", "+", "-", "\\"]);
|
|
1154
1446
|
var MARKERS = /^(?:--- |\+\+\+ )/;
|
|
1447
|
+
var GIT_COLOR = /\x1B\[[\d;]*m/g;
|
|
1155
1448
|
var META = /^(?:index |old mode |new mode |deleted file mode |new file mode |similarity index |dissimilarity index |rename from |rename to |copy from |copy to |Binary files |GIT binary patch)/;
|
|
1156
1449
|
var COMMIT_META = /^(?:Author|Date|Merge|AuthorDate|Commit|CommitDate):/;
|
|
1157
1450
|
var TOKEN = /\w+|\s+|[^\w\s]/g;
|
|
@@ -1230,7 +1523,9 @@ function renderDiff(text, theme) {
|
|
|
1230
1523
|
let oldLeft = 0;
|
|
1231
1524
|
let newLeft = 0;
|
|
1232
1525
|
let language;
|
|
1233
|
-
const lines =
|
|
1526
|
+
const lines = escapeControls(text.replace(GIT_COLOR, "").replaceAll(`\r
|
|
1527
|
+
`, `
|
|
1528
|
+
`)).replace(TRAILING_NEWLINE2, "").split(`
|
|
1234
1529
|
`).map((line) => {
|
|
1235
1530
|
if ((oldLeft > 0 || newLeft > 0) && line !== "" && !HUNK_LINE.has(line[0] ?? ""))
|
|
1236
1531
|
oldLeft = newLeft = 0;
|
|
@@ -1398,10 +1693,9 @@ function renderTable(rows, aligns, width, theme) {
|
|
|
1398
1693
|
`);
|
|
1399
1694
|
}
|
|
1400
1695
|
function printable(source) {
|
|
1401
|
-
return
|
|
1696
|
+
return stripControls(stripAnsi(source.replaceAll(`\r
|
|
1402
1697
|
`, `
|
|
1403
|
-
`)))
|
|
1404
|
-
` || char === "\t").join("");
|
|
1698
|
+
`)));
|
|
1405
1699
|
}
|
|
1406
1700
|
function renderMarkdown(source, { theme, width }) {
|
|
1407
1701
|
const quote = [`${theme.shade("\u275D", 0)} `, " "];
|
|
@@ -1485,8 +1779,8 @@ ${theme.dim("\u2500".repeat(rule))}
|
|
|
1485
1779
|
}
|
|
1486
1780
|
|
|
1487
1781
|
// src/theme.ts
|
|
1488
|
-
import
|
|
1489
|
-
function themeFor(stream =
|
|
1782
|
+
import process17 from "process";
|
|
1783
|
+
function themeFor(stream = process17.stdout, env = process17.env) {
|
|
1490
1784
|
const colors = paint(stream, env);
|
|
1491
1785
|
const accent = role("accent", stream, env);
|
|
1492
1786
|
const path = role("path", stream, env);
|
|
@@ -1517,8 +1811,8 @@ var MARKDOWN_FILE = /\.(?:md|markdown|mdx)$/i;
|
|
|
1517
1811
|
var DIFF_FILE = /\.(?:diff|patch)$/i;
|
|
1518
1812
|
var USAGE = `view [options] [file]: shows a markdown file, a source file or a git diff in the colours of the other @kaynooo CLIs
|
|
1519
1813
|
|
|
1520
|
-
A file, or what is piped on stdin (or - for stdin). A source file
|
|
1521
|
-
Lines wrap to the terminal width
|
|
1814
|
+
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.
|
|
1815
|
+
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. Control characters of the text, escape sequences included, show as cat -v writes them (^[) in code and diffs and are dropped from markdown, --json too.`;
|
|
1522
1816
|
var EXITS = [[0, "it showed the text"], [1, "there is nothing to show"], [2, "a usage error or a file that is missing"]];
|
|
1523
1817
|
var OPTIONS = {
|
|
1524
1818
|
diff: { type: "boolean", description: "show the text as a diff" },
|
|
@@ -1533,7 +1827,7 @@ function columnsOf(variable) {
|
|
|
1533
1827
|
const columns = Number(variable);
|
|
1534
1828
|
return Number.isInteger(columns) && columns >= 20 ? columns : DEFAULT_WIDTH;
|
|
1535
1829
|
}
|
|
1536
|
-
function pagerCommand(pager =
|
|
1830
|
+
function pagerCommand(pager = process18.env.PAGER) {
|
|
1537
1831
|
return pager === undefined || pager.trim() === "" || pager.trim() === "less" ? ["less", "-FRX"] : ["sh", "-c", pager];
|
|
1538
1832
|
}
|
|
1539
1833
|
async function page(text) {
|
|
@@ -1545,7 +1839,7 @@ async function page(text) {
|
|
|
1545
1839
|
} catch {}
|
|
1546
1840
|
await pager.exited;
|
|
1547
1841
|
} catch {
|
|
1548
|
-
|
|
1842
|
+
process18.stdout.write(text);
|
|
1549
1843
|
}
|
|
1550
1844
|
}
|
|
1551
1845
|
async function main(args) {
|
|
@@ -1558,8 +1852,8 @@ async function main(args) {
|
|
|
1558
1852
|
const text = await readInput(path, { noStdin: "give a file, or pipe the text on stdin" });
|
|
1559
1853
|
if (text.trim() === "")
|
|
1560
1854
|
fail("nothing to show", 1);
|
|
1561
|
-
const width = wholeNumber(values.width, "width",
|
|
1562
|
-
const theme = themeFor(
|
|
1855
|
+
const width = wholeNumber(values.width, "width", process18.stdout.isTTY === true ? process18.stdout.columns || DEFAULT_WIDTH : columnsOf(process18.env.COLUMNS), 20);
|
|
1856
|
+
const theme = themeFor(process18.stdout);
|
|
1563
1857
|
const language = values.lang === undefined ? languageOf(path) : languageOf(values.lang);
|
|
1564
1858
|
if (values.lang !== undefined && language === undefined)
|
|
1565
1859
|
badUsage(`unknown language ${values.lang}`);
|
|
@@ -1576,12 +1870,12 @@ async function main(args) {
|
|
|
1576
1870
|
printJson({ kind: isCode ? "code" : kind, language: isCode ? language ?? null : null, text: stripAnsi(render(themeFor({ isTTY: false }), values.lines ?? false)) });
|
|
1577
1871
|
return 0;
|
|
1578
1872
|
}
|
|
1579
|
-
const shown = render(theme, values.lines ??
|
|
1580
|
-
if (
|
|
1581
|
-
`).length > (
|
|
1873
|
+
const shown = render(theme, values.lines ?? process18.stdout.isTTY === true);
|
|
1874
|
+
if (process18.stdout.isTTY === true && values.pager !== false && shown.split(`
|
|
1875
|
+
`).length > (process18.stdout.rows || 24))
|
|
1582
1876
|
await page(shown);
|
|
1583
1877
|
else
|
|
1584
|
-
|
|
1878
|
+
process18.stdout.write(shown);
|
|
1585
1879
|
return 0;
|
|
1586
1880
|
}
|
|
1587
|
-
|
|
1881
|
+
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.4",
|
|
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.1"
|
|
39
39
|
}
|
|
40
40
|
}
|