buninu 0.2.5 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/README.md +100 -2
- package/apps/bunmsh/CHANGELOG.md +262 -0
- package/apps/bunmsh/LICENSE +21 -0
- package/apps/bunmsh/LICENSE-MKSH +295 -0
- package/apps/bunmsh/PORTING.md +192 -0
- package/apps/bunmsh/README.md +801 -0
- package/apps/bunmsh/bunmsh +7 -0
- package/apps/bunmsh/bunshell.md +61 -0
- package/apps/bunmsh/help/README.md +1945 -0
- package/apps/bunmsh/help/alias.md +22 -0
- package/apps/bunmsh/help/basename.md +38 -0
- package/apps/bunmsh/help/builtin.md +25 -0
- package/apps/bunmsh/help/bun.md +27 -0
- package/apps/bunmsh/help/bunmsh.md +47 -0
- package/apps/bunmsh/help/cat.md +31 -0
- package/apps/bunmsh/help/catfancy.md +35 -0
- package/apps/bunmsh/help/cd.md +22 -0
- package/apps/bunmsh/help/chmod.md +27 -0
- package/apps/bunmsh/help/clear.md +21 -0
- package/apps/bunmsh/help/colon.md +22 -0
- package/apps/bunmsh/help/command.md +27 -0
- package/apps/bunmsh/help/cp.md +28 -0
- package/apps/bunmsh/help/cut.md +25 -0
- package/apps/bunmsh/help/date.md +25 -0
- package/apps/bunmsh/help/dirname.md +25 -0
- package/apps/bunmsh/help/echo.md +25 -0
- package/apps/bunmsh/help/env.md +27 -0
- package/apps/bunmsh/help/eval.md +22 -0
- package/apps/bunmsh/help/exec.md +22 -0
- package/apps/bunmsh/help/exit.md +21 -0
- package/apps/bunmsh/help/export.md +22 -0
- package/apps/bunmsh/help/false.md +22 -0
- package/apps/bunmsh/help/find.md +33 -0
- package/apps/bunmsh/help/getopts.md +28 -0
- package/apps/bunmsh/help/grep.md +34 -0
- package/apps/bunmsh/help/head.md +27 -0
- package/apps/bunmsh/help/kill.md +27 -0
- package/apps/bunmsh/help/ln.md +28 -0
- package/apps/bunmsh/help/ls.md +37 -0
- package/apps/bunmsh/help/lsbun.md +29 -0
- package/apps/bunmsh/help/lsfancy.md +37 -0
- package/apps/bunmsh/help/md5sum.md +21 -0
- package/apps/bunmsh/help/mkdir.md +27 -0
- package/apps/bunmsh/help/mktemp.md +26 -0
- package/apps/bunmsh/help/mv.md +26 -0
- package/apps/bunmsh/help/print.md +30 -0
- package/apps/bunmsh/help/printf.md +25 -0
- package/apps/bunmsh/help/pwd.md +21 -0
- package/apps/bunmsh/help/read.md +27 -0
- package/apps/bunmsh/help/readonly.md +27 -0
- package/apps/bunmsh/help/realpath.md +21 -0
- package/apps/bunmsh/help/rm.md +33 -0
- package/apps/bunmsh/help/rmdir.md +27 -0
- package/apps/bunmsh/help/sed.md +29 -0
- package/apps/bunmsh/help/seq.md +29 -0
- package/apps/bunmsh/help/serve.md +50 -0
- package/apps/bunmsh/help/set.md +26 -0
- package/apps/bunmsh/help/sha256sum.md +21 -0
- package/apps/bunmsh/help/shift.md +23 -0
- package/apps/bunmsh/help/sleep.md +25 -0
- package/apps/bunmsh/help/sort.md +29 -0
- package/apps/bunmsh/help/source.md +23 -0
- package/apps/bunmsh/help/tab.md +30 -0
- package/apps/bunmsh/help/tac.md +29 -0
- package/apps/bunmsh/help/tail.md +27 -0
- package/apps/bunmsh/help/tee.md +25 -0
- package/apps/bunmsh/help/test.md +30 -0
- package/apps/bunmsh/help/time.md +29 -0
- package/apps/bunmsh/help/touch.md +26 -0
- package/apps/bunmsh/help/tr.md +26 -0
- package/apps/bunmsh/help/true.md +22 -0
- package/apps/bunmsh/help/type.md +21 -0
- package/apps/bunmsh/help/umask.md +22 -0
- package/apps/bunmsh/help/unalias.md +28 -0
- package/apps/bunmsh/help/uname.md +31 -0
- package/apps/bunmsh/help/unset.md +28 -0
- package/apps/bunmsh/help/wc.md +27 -0
- package/apps/bunmsh/help/whence.md +26 -0
- package/apps/bunmsh/help/which.md +41 -0
- package/apps/bunmsh/help/yes.md +23 -0
- package/apps/bunmsh/package.json +26 -0
- package/apps/bunmsh/serve.js +468 -0
- package/apps/bunmsh/single-exe/README.md +402 -0
- package/apps/bunmsh/single-exe/assetsHelper.js +371 -0
- package/apps/bunmsh/single-exe/assetsLoader.mjs +85 -0
- package/apps/bunmsh/single-exe/assetsPacker.js +218 -0
- package/apps/bunmsh/single-exe/compiled.js +527 -0
- package/apps/bunmsh/single-exe/entry.mjs +17 -0
- package/apps/bunmsh/src/cat-fancy.js +117 -0
- package/apps/bunmsh/src/cat-operands.js +31 -0
- package/apps/bunmsh/src/completion.js +247 -0
- package/apps/bunmsh/src/environment.js +61 -0
- package/apps/bunmsh/src/fancy-ls.js +186 -0
- package/apps/bunmsh/src/find.js +119 -0
- package/apps/bunmsh/src/history.js +198 -0
- package/apps/bunmsh/src/main.js +776 -0
- package/apps/bunmsh/src/mouse.js +103 -0
- package/apps/bunmsh/src/shell.js +3557 -0
- package/apps/bunmsh/test/catfancy.test.js +102 -0
- package/apps/bunmsh/test/reference-source.sh +1 -0
- package/apps/bunmsh/test/reference.test.js +677 -0
- package/apps/bunmsh/test/serve/README.md +3 -0
- package/apps/bunmsh/test/serve/bad.json +1 -0
- package/apps/bunmsh/test/serve/data.json +1 -0
- package/apps/bunmsh/test/serve/data.json5 +1 -0
- package/apps/bunmsh/test/serve/data.jsonc +2 -0
- package/apps/bunmsh/test/serve/data.jsonl +2 -0
- package/apps/bunmsh/test/serve/data.ndjson +1 -0
- package/apps/bunmsh/test/serve/data.toml +3 -0
- package/apps/bunmsh/test/serve/data.ts +15 -0
- package/apps/bunmsh/test/serve/data.xml +1 -0
- package/apps/bunmsh/test/serve/data.yaml +3 -0
- package/apps/bunmsh/test/serve/data.yml +1 -0
- package/apps/bunmsh/test/serve.test.js +241 -0
- package/apps/bunmsh/test/shell.test.js +1778 -0
- package/apps/bunmsh/test/t.sh +12 -0
- package/apps/native-bridge/native-bridge.js +45 -0
- package/apps/xdg-open/xdg-open.js +74 -2
- package/bin/init.js +11 -3
- package/demo-server.js +64 -0
- package/package.json +4 -2
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Transform } from "node:stream";
|
|
2
|
+
import { StringDecoder } from "node:string_decoder";
|
|
3
|
+
|
|
4
|
+
export const MOUSE_ON = "\x1b[?1000h\x1b[?1006h";
|
|
5
|
+
export const MOUSE_OFF = "\x1b[?1000l\x1b[?1006l";
|
|
6
|
+
export const PASTE_ON = "\x1b[?2004h";
|
|
7
|
+
export const PASTE_OFF = "\x1b[?2004l";
|
|
8
|
+
|
|
9
|
+
const PASTE_START = "\x1b[200~";
|
|
10
|
+
const PASTE_END = "\x1b[201~";
|
|
11
|
+
|
|
12
|
+
// The longest suffix of `text` that could still grow into `marker` once more
|
|
13
|
+
// bytes arrive in a later chunk (e.g. "\x1b[20" against "\x1b[201~"). Held
|
|
14
|
+
// back instead of treated as confirmed paste content, so a marker split
|
|
15
|
+
// across a transform() chunk boundary is never missed or double-counted.
|
|
16
|
+
function partialMarkerSuffixLength(text, marker) {
|
|
17
|
+
const max = Math.min(text.length, marker.length - 1);
|
|
18
|
+
for (let length = max; length > 0; length--) {
|
|
19
|
+
if (marker.startsWith(text.slice(text.length - length))) return length;
|
|
20
|
+
}
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function mouseInput(onMouse, onCursorPosition, onShortcut = () => {}, onPaste = () => {}) {
|
|
25
|
+
const decoder = new StringDecoder("utf8");
|
|
26
|
+
let pending = "";
|
|
27
|
+
// Bracketed paste (\x1b[200~ ... \x1b[201~): everything between the
|
|
28
|
+
// markers is literal pasted text, handed to onPaste once the end marker
|
|
29
|
+
// closes it, never interpreted as a shortcut/mouse/cursor escape.
|
|
30
|
+
// Known gap: a paste that both starts and ends within one transform()
|
|
31
|
+
// chunk (by far the common case) still has the shortcut regexes below run
|
|
32
|
+
// over it first, since they scan the whole chunk before this loop even
|
|
33
|
+
// sees the paste markers. Real pasted text (commands, prose) essentially
|
|
34
|
+
// never contains a raw \x14 or an ESC immediately followed by t/l/u/p/c,
|
|
35
|
+
// so this is left as a documented gap rather than restructuring the scan.
|
|
36
|
+
let pasting = false;
|
|
37
|
+
let pasteBuffer = "";
|
|
38
|
+
const input = new Transform({
|
|
39
|
+
transform(chunk, _encoding, done) {
|
|
40
|
+
let source = pending + decoder.write(chunk);
|
|
41
|
+
pending = "";
|
|
42
|
+
if (!pasting) {
|
|
43
|
+
source = source.replace(/\x14/g, () => { onShortcut("tab"); return ""; });
|
|
44
|
+
source = source.replace(/\x1bt/g, () => { onShortcut("tab-left"); return ""; });
|
|
45
|
+
source = source.replace(/\x1bl/g, () => { onShortcut("lsfancy"); return ""; });
|
|
46
|
+
source = source.replace(/\x1bu/g, () => { onShortcut("lsfancy-parent"); return ""; });
|
|
47
|
+
source = source.replace(/\x1bp/g, () => { onShortcut("lsfancy-parent"); return ""; });
|
|
48
|
+
source = source.replace(/\x1bc/g, () => { onShortcut("tab-close"); return ""; });
|
|
49
|
+
}
|
|
50
|
+
let output = "";
|
|
51
|
+
while (source) {
|
|
52
|
+
if (pasting) {
|
|
53
|
+
const end = source.indexOf(PASTE_END);
|
|
54
|
+
if (end < 0) {
|
|
55
|
+
const holdback = partialMarkerSuffixLength(source, PASTE_END);
|
|
56
|
+
pasteBuffer += source.slice(0, source.length - holdback);
|
|
57
|
+
pending = source.slice(source.length - holdback);
|
|
58
|
+
source = "";
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
pasteBuffer += source.slice(0, end);
|
|
62
|
+
onPaste(pasteBuffer);
|
|
63
|
+
pasteBuffer = "";
|
|
64
|
+
pasting = false;
|
|
65
|
+
source = source.slice(end + PASTE_END.length);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const escape = source.indexOf("\x1b[");
|
|
69
|
+
if (escape < 0) { output += source; break; }
|
|
70
|
+
output += source.slice(0, escape);
|
|
71
|
+
source = source.slice(escape);
|
|
72
|
+
if (source.startsWith(PASTE_START)) {
|
|
73
|
+
pasting = true;
|
|
74
|
+
source = source.slice(PASTE_START.length);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
let match = /^\x1b\[<(\d+);(\d+);(\d+)([Mm])/.exec(source);
|
|
78
|
+
if (match) {
|
|
79
|
+
onMouse({ button: Number(match[1]), x: Number(match[2]), y: Number(match[3]), press: match[4] === "M" });
|
|
80
|
+
source = source.slice(match[0].length);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
match = /^\x1b\[(\d+);(\d+)R/.exec(source);
|
|
84
|
+
if (match) {
|
|
85
|
+
onCursorPosition({ row: Number(match[1]), column: Number(match[2]) });
|
|
86
|
+
source = source.slice(match[0].length);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (/^\x1b\[(?:<\d*(?:;\d*){0,2}|\d*(?:;\d*)?)?$/.test(source)) {
|
|
90
|
+
pending = source;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
output += source.slice(0, 2);
|
|
94
|
+
source = source.slice(2);
|
|
95
|
+
}
|
|
96
|
+
if (output) this.push(output);
|
|
97
|
+
done();
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
input.isTTY = process.stdin.isTTY;
|
|
101
|
+
input.setRawMode = (mode) => process.stdin.setRawMode?.(mode);
|
|
102
|
+
return input;
|
|
103
|
+
}
|