@kaynooo/cli-view 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/view.js +40 -14
- package/package.json +3 -3
package/dist/view.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#!/
|
|
2
|
-
// @bun
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
// @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
|
|
3
3
|
var __esm = (fn, res, err) => () => {
|
|
4
4
|
if (fn)
|
|
5
5
|
try {
|
|
@@ -116,11 +116,14 @@ var init_config = __esm(() => {
|
|
|
116
116
|
|
|
117
117
|
// ../kit/src/user-config.ts
|
|
118
118
|
import { homedir } from "os";
|
|
119
|
-
import { join as join2 } from "path";
|
|
119
|
+
import { isAbsolute, join as join2 } from "path";
|
|
120
120
|
import process4 from "process";
|
|
121
|
+
function xdgFolder(value, fallback) {
|
|
122
|
+
return value !== undefined && isAbsolute(value) ? value : fallback;
|
|
123
|
+
}
|
|
121
124
|
function configBase(where = {}) {
|
|
122
125
|
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
123
|
-
return xdg
|
|
126
|
+
return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
|
|
124
127
|
}
|
|
125
128
|
function userConfigPath(bin, where = {}) {
|
|
126
129
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
@@ -503,6 +506,17 @@ var init_help = __esm(() => {
|
|
|
503
506
|
function stripAnsi(text) {
|
|
504
507
|
return text.replace(ANSI, "");
|
|
505
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
|
+
}
|
|
506
520
|
function distance(a, b) {
|
|
507
521
|
const left = [...a];
|
|
508
522
|
const right = [...b];
|
|
@@ -528,9 +542,10 @@ function closest(name, names) {
|
|
|
528
542
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
529
543
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
530
544
|
}
|
|
531
|
-
var ANSI;
|
|
545
|
+
var ANSI, CONTROLS;
|
|
532
546
|
var init_text = __esm(() => {
|
|
533
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;
|
|
534
549
|
});
|
|
535
550
|
|
|
536
551
|
// ../kit/src/input.ts
|
|
@@ -841,6 +856,11 @@ init_format();
|
|
|
841
856
|
|
|
842
857
|
// ../kit/src/progress.ts
|
|
843
858
|
init_format();
|
|
859
|
+
|
|
860
|
+
// ../kit/src/process.ts
|
|
861
|
+
var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
|
|
862
|
+
|
|
863
|
+
// ../kit/src/progress.ts
|
|
844
864
|
init_style();
|
|
845
865
|
init_theme();
|
|
846
866
|
var ESC = String.fromCharCode(27);
|
|
@@ -985,14 +1005,16 @@ init_text();
|
|
|
985
1005
|
// ../kit/src/usage.ts
|
|
986
1006
|
import { appendFileSync, mkdirSync } from "fs";
|
|
987
1007
|
import { homedir as homedir3 } from "os";
|
|
988
|
-
import { dirname as dirname2,
|
|
1008
|
+
import { dirname as dirname2, join as join4 } from "path";
|
|
989
1009
|
import process14 from "process";
|
|
990
1010
|
|
|
991
1011
|
// ../kit/src/logs.ts
|
|
1012
|
+
init_user_config();
|
|
992
1013
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
993
1014
|
var CLI_FOLDER = "kaynooo-cli";
|
|
994
1015
|
|
|
995
1016
|
// ../kit/src/usage.ts
|
|
1017
|
+
init_user_config();
|
|
996
1018
|
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
997
1019
|
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
998
1020
|
var LONGEST_NAME = 40;
|
|
@@ -1001,8 +1023,7 @@ function noteUsageError(message) {
|
|
|
1001
1023
|
usageError = message;
|
|
1002
1024
|
}
|
|
1003
1025
|
function stateHome(env = process14.env) {
|
|
1004
|
-
|
|
1005
|
-
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1026
|
+
return xdgFolder(env.XDG_STATE_HOME, join4(homedir3(), ".local", "state"));
|
|
1006
1027
|
}
|
|
1007
1028
|
function usagePath(env = process14.env) {
|
|
1008
1029
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
@@ -1205,6 +1226,7 @@ init_style();
|
|
|
1205
1226
|
init_text();
|
|
1206
1227
|
// ../kit/src/secrets.ts
|
|
1207
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"]);
|
|
1208
1230
|
// ../kit/src/sessions.ts
|
|
1209
1231
|
var {Glob } = globalThis.Bun;
|
|
1210
1232
|
var SESSION_FILES = new Glob("*.json");
|
|
@@ -1399,7 +1421,9 @@ function highlight(source, name, theme) {
|
|
|
1399
1421
|
return out;
|
|
1400
1422
|
}
|
|
1401
1423
|
function renderCode(source, name, theme, lineNumbers) {
|
|
1402
|
-
const text = source.
|
|
1424
|
+
const text = escapeControls(source.replaceAll(`\r
|
|
1425
|
+
`, `
|
|
1426
|
+
`)).replace(TRAILING_NEWLINE, "");
|
|
1403
1427
|
const shown = name === undefined ? text : highlight(text, name, theme);
|
|
1404
1428
|
if (!lineNumbers)
|
|
1405
1429
|
return `${shown}
|
|
@@ -1420,6 +1444,7 @@ var NEW_FILE = /^\+\+\+ (?:b\/)?([^\t]*)/;
|
|
|
1420
1444
|
var COMMIT = /^(commit )([0-9a-f]{7,40})(.*)$/;
|
|
1421
1445
|
var HUNK_LINE = new Set([" ", "+", "-", "\\"]);
|
|
1422
1446
|
var MARKERS = /^(?:--- |\+\+\+ )/;
|
|
1447
|
+
var GIT_COLOR = /\x1B\[[\d;]*m/g;
|
|
1423
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)/;
|
|
1424
1449
|
var COMMIT_META = /^(?:Author|Date|Merge|AuthorDate|Commit|CommitDate):/;
|
|
1425
1450
|
var TOKEN = /\w+|\s+|[^\w\s]/g;
|
|
@@ -1498,7 +1523,9 @@ function renderDiff(text, theme) {
|
|
|
1498
1523
|
let oldLeft = 0;
|
|
1499
1524
|
let newLeft = 0;
|
|
1500
1525
|
let language;
|
|
1501
|
-
const lines =
|
|
1526
|
+
const lines = escapeControls(text.replace(GIT_COLOR, "").replaceAll(`\r
|
|
1527
|
+
`, `
|
|
1528
|
+
`)).replace(TRAILING_NEWLINE2, "").split(`
|
|
1502
1529
|
`).map((line) => {
|
|
1503
1530
|
if ((oldLeft > 0 || newLeft > 0) && line !== "" && !HUNK_LINE.has(line[0] ?? ""))
|
|
1504
1531
|
oldLeft = newLeft = 0;
|
|
@@ -1666,10 +1693,9 @@ function renderTable(rows, aligns, width, theme) {
|
|
|
1666
1693
|
`);
|
|
1667
1694
|
}
|
|
1668
1695
|
function printable(source) {
|
|
1669
|
-
return
|
|
1696
|
+
return stripControls(stripAnsi(source.replaceAll(`\r
|
|
1670
1697
|
`, `
|
|
1671
|
-
`)))
|
|
1672
|
-
` || char === "\t").join("");
|
|
1698
|
+
`)));
|
|
1673
1699
|
}
|
|
1674
1700
|
function renderMarkdown(source, { theme, width }) {
|
|
1675
1701
|
const quote = [`${theme.shade("\u275D", 0)} `, " "];
|
|
@@ -1786,7 +1812,7 @@ var DIFF_FILE = /\.(?:diff|patch)$/i;
|
|
|
1786
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
|
|
1787
1813
|
|
|
1788
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.
|
|
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.`;
|
|
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.`;
|
|
1790
1816
|
var EXITS = [[0, "it showed the text"], [1, "there is nothing to show"], [2, "a usage error or a file that is missing"]];
|
|
1791
1817
|
var OPTIONS = {
|
|
1792
1818
|
diff: { type: "boolean", description: "show the text as a diff" },
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-view",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.5",
|
|
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",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
|
-
"build": "$npm_execpath build src/view.ts --target bun --outdir dist",
|
|
34
|
+
"build": "$npm_execpath build src/view.ts --target bun --outdir dist && $npm_execpath ../../scripts/shell-shebang.ts",
|
|
35
35
|
"view": "$npm_execpath src/view.ts"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@kaynooo/cli-kit": "0.46.
|
|
38
|
+
"@kaynooo/cli-kit": "0.46.4"
|
|
39
39
|
}
|
|
40
40
|
}
|