@prozilla-os/core 2.0.1 → 2.1.2
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 +105 -113
- package/dist/chunks/afire-DlRwSfiJ.js +68 -0
- package/dist/chunks/afire-DlRwSfiJ.js.map +1 -0
- package/dist/chunks/banner-jSvYkuqB.js +351 -0
- package/dist/chunks/banner-jSvYkuqB.js.map +1 -0
- package/dist/chunks/cat-B_KOgu80.js +37 -0
- package/dist/chunks/cat-B_KOgu80.js.map +1 -0
- package/dist/chunks/clear-C8xhqHmC.js +12 -0
- package/dist/chunks/clear-C8xhqHmC.js.map +1 -0
- package/dist/chunks/compgen-2kLzA1wV.js +11 -0
- package/dist/chunks/compgen-2kLzA1wV.js.map +1 -0
- package/dist/chunks/{cowsay-hTKzWScw.js → cowsay-CTLxUPtF.js} +13 -13
- package/dist/chunks/cowsay-CTLxUPtF.js.map +1 -0
- package/dist/chunks/date-CA1ub92R.js +33 -0
- package/dist/chunks/date-CA1ub92R.js.map +1 -0
- package/dist/chunks/dir-w2XNd6oI.js +11 -0
- package/dist/chunks/dir-w2XNd6oI.js.map +1 -0
- package/dist/chunks/doubleBracket-B5nqIccY.js +78 -0
- package/dist/chunks/doubleBracket-B5nqIccY.js.map +1 -0
- package/dist/chunks/{echo-Gmh-b8f5.js → echo-_hDVbupR.js} +5 -5
- package/dist/chunks/echo-_hDVbupR.js.map +1 -0
- package/dist/chunks/{eval-DINS_Vhl.js → eval-4uLqmhXl.js} +5 -5
- package/dist/chunks/eval-4uLqmhXl.js.map +1 -0
- package/dist/chunks/false-D6AWAlcU.js +12 -0
- package/dist/chunks/false-D6AWAlcU.js.map +1 -0
- package/dist/chunks/{fortune-DkIZpYa_.js → fortune-D8ZK6xtX.js} +7 -7
- package/dist/chunks/fortune-D8ZK6xtX.js.map +1 -0
- package/dist/chunks/grep-DZO92KaH.js +41 -0
- package/dist/chunks/grep-DZO92KaH.js.map +1 -0
- package/dist/chunks/head-C_bbNyUc.js +50 -0
- package/dist/chunks/head-C_bbNyUc.js.map +1 -0
- package/dist/chunks/help-OHTeCzgo.js +19 -0
- package/dist/chunks/help-OHTeCzgo.js.map +1 -0
- package/dist/chunks/history-DeQor0w1.js +17 -0
- package/dist/chunks/history-DeQor0w1.js.map +1 -0
- package/dist/chunks/hostname-B-lPyRps.js +10 -0
- package/dist/chunks/hostname-B-lPyRps.js.map +1 -0
- package/dist/chunks/install-9Dikj7i2.js +27 -0
- package/dist/chunks/install-9Dikj7i2.js.map +1 -0
- package/dist/chunks/less-wELkkcQx.js +98 -0
- package/dist/chunks/less-wELkkcQx.js.map +1 -0
- package/dist/chunks/{lolcat-Dyjbg15t.js → lolcat-xpDAXsIt.js} +20 -20
- package/dist/chunks/lolcat-xpDAXsIt.js.map +1 -0
- package/dist/chunks/{ls-DnmR50y0.js → ls-D2Ln7mue.js} +7 -7
- package/dist/chunks/ls-D2Ln7mue.js.map +1 -0
- package/dist/chunks/man-E9nMmKZ1.js +58 -0
- package/dist/chunks/man-E9nMmKZ1.js.map +1 -0
- package/dist/chunks/nano-DsRjsQ-k.js +79 -0
- package/dist/chunks/nano-DsRjsQ-k.js.map +1 -0
- package/dist/chunks/neofetch-Dyre2Ik0.js +46 -0
- package/dist/chunks/neofetch-Dyre2Ik0.js.map +1 -0
- package/dist/chunks/pipes-CQ-pK6Kv.js +89 -0
- package/dist/chunks/pipes-CQ-pK6Kv.js.map +1 -0
- package/dist/chunks/printenv-Cq-skM9d.js +22 -0
- package/dist/chunks/printenv-Cq-skM9d.js.map +1 -0
- package/dist/chunks/pwd-CZ9IWAfu.js +11 -0
- package/dist/chunks/pwd-CZ9IWAfu.js.map +1 -0
- package/dist/chunks/rain-DT-V01dD.js +63 -0
- package/dist/chunks/rain-DT-V01dD.js.map +1 -0
- package/dist/chunks/reload-CE3ZVq6O.js +10 -0
- package/dist/chunks/reload-CE3ZVq6O.js.map +1 -0
- package/dist/chunks/rev-C5m1qeoZ.js +15 -0
- package/dist/chunks/rev-C5m1qeoZ.js.map +1 -0
- package/dist/chunks/rm-Uxuv-dEz.js.map +1 -1
- package/dist/chunks/rmdir-BYWer3pb.js.map +1 -1
- package/dist/chunks/sh-CIyBHb8C.js +11 -0
- package/dist/chunks/sh-CIyBHb8C.js.map +1 -0
- package/dist/chunks/{sl-CLAmugya.js → sl-CVLteJLH.js} +10 -10
- package/dist/chunks/{sl-CLAmugya.js.map → sl-CVLteJLH.js.map} +1 -1
- package/dist/chunks/sleep-hEBW30R3.js +26 -0
- package/dist/chunks/sleep-hEBW30R3.js.map +1 -0
- package/dist/chunks/snow-DAlyPPxX.js +76 -0
- package/dist/chunks/snow-DAlyPPxX.js.map +1 -0
- package/dist/chunks/tail-BLlaoTxA.js +50 -0
- package/dist/chunks/tail-BLlaoTxA.js.map +1 -0
- package/dist/chunks/terminalUIApp-Bmiaqvd9.js +63 -0
- package/dist/chunks/terminalUIApp-Bmiaqvd9.js.map +1 -0
- package/dist/chunks/textEditorApp-BM3EiMoV.js +56 -0
- package/dist/chunks/textEditorApp-BM3EiMoV.js.map +1 -0
- package/dist/chunks/true-j1Uf2Nz9.js +12 -0
- package/dist/chunks/true-j1Uf2Nz9.js.map +1 -0
- package/dist/chunks/uniq-LncLpnFY.js +44 -0
- package/dist/chunks/uniq-LncLpnFY.js.map +1 -0
- package/dist/chunks/uptime-pYltXMOi.js +10 -0
- package/dist/chunks/uptime-pYltXMOi.js.map +1 -0
- package/dist/chunks/vi-Cgo3qLR9.js +121 -0
- package/dist/chunks/vi-Cgo3qLR9.js.map +1 -0
- package/dist/chunks/watch-B4Tgzgbn.js +53 -0
- package/dist/chunks/watch-B4Tgzgbn.js.map +1 -0
- package/dist/chunks/whatis-BPKA-MNF.js +17 -0
- package/dist/chunks/whatis-BPKA-MNF.js.map +1 -0
- package/dist/chunks/whoami-BS3xdQEI.js +10 -0
- package/dist/chunks/whoami-BS3xdQEI.js.map +1 -0
- package/dist/chunks/yes-ilM2l2xq.js +18 -0
- package/dist/chunks/yes-ilM2l2xq.js.map +1 -0
- package/dist/main.d.ts +807 -77
- package/dist/main.js +17714 -16034
- package/dist/main.js.map +1 -1
- package/package.json +20 -19
- package/dist/chunks/cat-DH-kPf08.js +0 -44
- package/dist/chunks/cat-DH-kPf08.js.map +0 -1
- package/dist/chunks/clear-DC-frUcf.js +0 -13
- package/dist/chunks/clear-DC-frUcf.js.map +0 -1
- package/dist/chunks/compgen-OhvISbst.js +0 -11
- package/dist/chunks/compgen-OhvISbst.js.map +0 -1
- package/dist/chunks/cowsay-hTKzWScw.js.map +0 -1
- package/dist/chunks/date-D8cnHZuY.js +0 -33
- package/dist/chunks/date-D8cnHZuY.js.map +0 -1
- package/dist/chunks/dir-BmNeEPzy.js +0 -11
- package/dist/chunks/dir-BmNeEPzy.js.map +0 -1
- package/dist/chunks/echo-Gmh-b8f5.js.map +0 -1
- package/dist/chunks/eval-DINS_Vhl.js.map +0 -1
- package/dist/chunks/fortune-DkIZpYa_.js.map +0 -1
- package/dist/chunks/grep-CR3FMStR.js +0 -41
- package/dist/chunks/grep-CR3FMStR.js.map +0 -1
- package/dist/chunks/help-Drx0UDCY.js +0 -19
- package/dist/chunks/help-Drx0UDCY.js.map +0 -1
- package/dist/chunks/history-BEJhnsrb.js +0 -17
- package/dist/chunks/history-BEJhnsrb.js.map +0 -1
- package/dist/chunks/hostname-D8sxyWIy.js +0 -10
- package/dist/chunks/hostname-D8sxyWIy.js.map +0 -1
- package/dist/chunks/lolcat-Dyjbg15t.js.map +0 -1
- package/dist/chunks/ls-DnmR50y0.js.map +0 -1
- package/dist/chunks/man-7W6T7lda.js +0 -60
- package/dist/chunks/man-7W6T7lda.js.map +0 -1
- package/dist/chunks/neofetch--vHMIS9v.js +0 -40
- package/dist/chunks/neofetch--vHMIS9v.js.map +0 -1
- package/dist/chunks/printenv-6OpJKd7g.js +0 -24
- package/dist/chunks/printenv-6OpJKd7g.js.map +0 -1
- package/dist/chunks/pwd-9JYDUbov.js +0 -11
- package/dist/chunks/pwd-9JYDUbov.js.map +0 -1
- package/dist/chunks/reload-CjTJVt5Z.js +0 -10
- package/dist/chunks/reload-CjTJVt5Z.js.map +0 -1
- package/dist/chunks/rev--2pyt1P8.js +0 -12
- package/dist/chunks/rev--2pyt1P8.js.map +0 -1
- package/dist/chunks/sh-B67OTc-j.js +0 -15
- package/dist/chunks/sh-B67OTc-j.js.map +0 -1
- package/dist/chunks/uniq-Dx_4r3B5.js +0 -44
- package/dist/chunks/uniq-Dx_4r3B5.js.map +0 -1
- package/dist/chunks/uptime-DjJ5V7hu.js +0 -10
- package/dist/chunks/uptime-DjJ5V7hu.js.map +0 -1
- package/dist/chunks/watch-BjJ8bCnP.js +0 -52
- package/dist/chunks/watch-BjJ8bCnP.js.map +0 -1
- package/dist/chunks/whatis-CFZWdHZ4.js +0 -17
- package/dist/chunks/whatis-CFZWdHZ4.js.map +0 -1
- package/dist/chunks/whoami-D-es0JvS.js +0 -10
- package/dist/chunks/whoami-D-es0JvS.js.map +0 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Command as a, HistoryFlags as u, EXIT_CODE as e, Shell as c } from "../main.js";
|
|
2
|
+
const h = new a().setManual({
|
|
3
|
+
purpose: "Display the command history list with line numbers",
|
|
4
|
+
usage: "history",
|
|
5
|
+
description: "Display the list of commands typed since the shell session started."
|
|
6
|
+
}).setExecute(async function(l, { stdout: n, shell: i }) {
|
|
7
|
+
const s = i.state.history.filter(({ flags: t }) => t & u.Command);
|
|
8
|
+
if (s.length === 0)
|
|
9
|
+
return e.success;
|
|
10
|
+
const r = s.map((t, o) => `${(o + 1).toString().padStart(5, " ")} ${t.input}`).join(`
|
|
11
|
+
`);
|
|
12
|
+
return await c.printLn(n, r), e.success;
|
|
13
|
+
});
|
|
14
|
+
export {
|
|
15
|
+
h as history
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=history-DeQor0w1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history-DeQor0w1.js","sources":["../../src/features/shell/commands/history.ts"],"sourcesContent":["import { Command } from \"../command\";\nimport { EXIT_CODE } from \"../../../constants\";\nimport { HistoryFlags, Shell } from \"../shell\";\n\nexport const history = new Command()\n\t.setManual({\n\t\tpurpose: \"Display the command history list with line numbers\",\n\t\tusage: \"history\",\n\t\tdescription: \"Display the list of commands typed since the shell session started.\",\n\t})\n\t.setExecute(async function(this: Command, _args, { stdout, shell }) {\n\t\tconst inputHistory = shell.state.history.filter(({ flags }) => flags & HistoryFlags.Command);\n\n\t\tif (inputHistory.length === 0) \n\t\t\treturn EXIT_CODE.success;\n\n\t\tconst output = inputHistory\n\t\t\t.map((entry, index) => {\n\t\t\t\tconst lineNumber = (index + 1).toString().padStart(5, \" \");\n\t\t\t\treturn `${lineNumber} ${entry.input}`;\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\n\t\tawait Shell.printLn(stdout, output);\n\n\t\treturn EXIT_CODE.success;\n\t});"],"names":["history","Command","_args","stdout","shell","inputHistory","flags","HistoryFlags","EXIT_CODE","output","entry","index","Shell"],"mappings":";AAIO,MAAMA,IAAU,IAAIC,EAAA,EACzB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,OAAO;AAAA,EACP,aAAa;AACd,CAAC,EACA,WAAW,eAA8BC,GAAO,EAAE,QAAAC,GAAQ,OAAAC,KAAS;AACnE,QAAMC,IAAeD,EAAM,MAAM,QAAQ,OAAO,CAAC,EAAE,OAAAE,EAAA,MAAYA,IAAQC,EAAa,OAAO;AAE3F,MAAIF,EAAa,WAAW;AAC3B,WAAOG,EAAU;AAElB,QAAMC,IAASJ,EACb,IAAI,CAACK,GAAOC,MAEL,IADaA,IAAQ,GAAG,WAAW,SAAS,GAAG,GAAG,CACrC,KAAKD,EAAM,KAAK,EACpC,EACA,KAAK;AAAA,CAAI;AAEX,eAAME,EAAM,QAAQT,GAAQM,CAAM,GAE3BD,EAAU;AAClB,CAAC;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command as n, Shell as a } from "../main.js";
|
|
2
|
+
const m = new n().setManual({
|
|
3
|
+
purpose: "Display the hostname"
|
|
4
|
+
}).setExecute(async function(o, { hostname: t, stdout: e }) {
|
|
5
|
+
await a.printLn(e, t);
|
|
6
|
+
});
|
|
7
|
+
export {
|
|
8
|
+
m as hostname
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=hostname-B-lPyRps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostname-B-lPyRps.js","sources":["../../src/features/shell/commands/hostname.ts"],"sourcesContent":["import { Command } from \"../command\";\nimport { Shell } from \"../shell\";\n\nexport const hostname = new Command()\n\t.setManual({\n\t\tpurpose: \"Display the hostname\",\n\t})\n\t.setExecute(async function(_args, { hostname, stdout }) {\n\t\tawait Shell.printLn(stdout, hostname);\n\t});"],"names":["hostname","Command","_args","stdout","Shell"],"mappings":";AAGO,MAAMA,IAAW,IAAIC,EAAA,EAC1B,UAAU;AAAA,EACV,SAAS;AACV,CAAC,EACA,WAAW,eAAeC,GAAO,EAAE,UAAAF,GAAU,QAAAG,KAAU;AACvD,QAAMC,EAAM,QAAQD,GAAQH,CAAQ;AACrC,CAAC;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Command as l, Shell as t } from "../main.js";
|
|
2
|
+
const m = new l().setManual({
|
|
3
|
+
purpose: "Install an app from a URL or npm package",
|
|
4
|
+
usage: "install [--export <name>] <npm-package | url>",
|
|
5
|
+
description: "Dynamically install an app from an npm package name (e.g. @scope/package) or a direct URL to an ES module that exports an App instance.",
|
|
6
|
+
options: {
|
|
7
|
+
"-e, --export <name>": "Name of the export that contains the App instance (default: checks `app` then `default`)"
|
|
8
|
+
}
|
|
9
|
+
}).addOption({ short: "e", long: "export", isInput: !0 }).setRequireArgs(!0).setExecute(async function(i, { stdout: n, stderr: r, systemManager: s, inputs: p }) {
|
|
10
|
+
const e = i[0];
|
|
11
|
+
if (!e)
|
|
12
|
+
return await t.writeError(r, "install", "expected a package name or URL"), 1;
|
|
13
|
+
await n.write(`Installing "${e}"...
|
|
14
|
+
`);
|
|
15
|
+
try {
|
|
16
|
+
const a = {};
|
|
17
|
+
p.e && (a.exportName = p.e);
|
|
18
|
+
const o = await s.appsConfig.installApp(e, a);
|
|
19
|
+
await t.printLn(n, `Successfully installed "${o.name}" (${o.id})`);
|
|
20
|
+
} catch (a) {
|
|
21
|
+
return await t.writeError(r, "install", a instanceof Error ? a.message : String(a)), 1;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
export {
|
|
25
|
+
m as install
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=install-9Dikj7i2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install-9Dikj7i2.js","sources":["../../src/features/shell/commands/install.ts"],"sourcesContent":["import { Command } from \"../command\";\nimport { Shell } from \"../shell\";\nimport type { LoadAppOptions } from \"../../apps/appLoader\";\n\nexport const install = new Command()\n\t.setManual({\n\t\tpurpose: \"Install an app from a URL or npm package\",\n\t\tusage: \"install [--export <name>] <npm-package | url>\",\n\t\tdescription: \"Dynamically install an app from an npm package name (e.g. @scope/package) or a direct URL to an ES module that exports an App instance.\",\n\t\toptions: {\n\t\t\t\"-e, --export <name>\": \"Name of the export that contains the App instance (default: checks `app` then `default`)\",\n\t\t},\n\t})\n\t.addOption({ short: \"e\", long: \"export\", isInput: true })\n\t.setRequireArgs(true)\n\t.setExecute(async function(args, { stdout, stderr, systemManager, inputs }) {\n\t\tconst target = args[0];\n\n\t\tif (!target) {\n\t\t\tawait Shell.writeError(stderr, \"install\", \"expected a package name or URL\");\n\t\t\treturn 1;\n\t\t}\n\n\t\tawait stdout.write(`Installing \"${target}\"...\\n`);\n\n\t\ttry {\n\t\t\tconst options: LoadAppOptions = {};\n\t\t\tif (inputs.e)\n\t\t\t\toptions.exportName = inputs.e;\n\n\t\t\tconst app = await systemManager.appsConfig.installApp(target, options);\n\n\t\t\tawait Shell.printLn(stdout, `Successfully installed \"${app.name}\" (${app.id})`);\n\t\t} catch (error) {\n\t\t\tawait Shell.writeError(stderr, \"install\", error instanceof Error ? error.message : String(error));\n\t\t\treturn 1;\n\t\t}\n\t});\n"],"names":["install","Command","args","stdout","stderr","systemManager","inputs","target","Shell","options","app","error"],"mappings":";AAIO,MAAMA,IAAU,IAAIC,EAAA,EACzB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,OAAO;AAAA,EACP,aAAa;AAAA,EACb,SAAS;AAAA,IACR,uBAAuB;AAAA,EAAA;AAEzB,CAAC,EACA,UAAU,EAAE,OAAO,KAAK,MAAM,UAAU,SAAS,IAAM,EACvD,eAAe,EAAI,EACnB,WAAW,eAAeC,GAAM,EAAE,QAAAC,GAAQ,QAAAC,GAAQ,eAAAC,GAAe,QAAAC,KAAU;AAC3E,QAAMC,IAASL,EAAK,CAAC;AAErB,MAAI,CAACK;AACJ,iBAAMC,EAAM,WAAWJ,GAAQ,WAAW,gCAAgC,GACnE;AAGR,QAAMD,EAAO,MAAM,eAAeI,CAAM;AAAA,CAAQ;AAEhD,MAAI;AACH,UAAME,IAA0B,CAAA;AAChC,IAAIH,EAAO,MACVG,EAAQ,aAAaH,EAAO;AAE7B,UAAMI,IAAM,MAAML,EAAc,WAAW,WAAWE,GAAQE,CAAO;AAErE,UAAMD,EAAM,QAAQL,GAAQ,2BAA2BO,EAAI,IAAI,MAAMA,EAAI,EAAE,GAAG;AAAA,EAC/E,SAASC,GAAO;AACf,iBAAMH,EAAM,WAAWJ,GAAQ,WAAWO,aAAiB,QAAQA,EAAM,UAAU,OAAOA,CAAK,CAAC,GACzF;AAAA,EACR;AACD,CAAC;"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Command as p, Shell as o } from "../main.js";
|
|
2
|
+
import { ANSI as t } from "@prozilla-os/shared";
|
|
3
|
+
import { T as n } from "./terminalUIApp-Bmiaqvd9.js";
|
|
4
|
+
class u extends n {
|
|
5
|
+
lines = [];
|
|
6
|
+
scrollIndex = 0;
|
|
7
|
+
fileName;
|
|
8
|
+
constructor(i, e) {
|
|
9
|
+
super(
|
|
10
|
+
i,
|
|
11
|
+
0
|
|
12
|
+
/* Viewer */
|
|
13
|
+
), this.fileName = e[0] ?? "stdin", this.on(n.RENDER_EVENT, async () => {
|
|
14
|
+
await this.render();
|
|
15
|
+
}), this.on(n.INPUT_EVENT, async (s) => {
|
|
16
|
+
await this.handleInput(s);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Reads the file or stream content.
|
|
21
|
+
*/
|
|
22
|
+
async init(i) {
|
|
23
|
+
if (!i.length)
|
|
24
|
+
return "No file specified";
|
|
25
|
+
const e = this.context.workingDirectory.navigate(this.fileName);
|
|
26
|
+
if (!e)
|
|
27
|
+
return `${this.fileName}: ${o.INVALID_PATH_ERROR}`;
|
|
28
|
+
if (e.isFolder())
|
|
29
|
+
return `${this.fileName}: Is a directory`;
|
|
30
|
+
const s = await e.read();
|
|
31
|
+
return this.lines = s?.split(`
|
|
32
|
+
`) ?? [""], null;
|
|
33
|
+
}
|
|
34
|
+
async render() {
|
|
35
|
+
const i = this.size.y, e = i - 1;
|
|
36
|
+
let s = t.screen.home + t.screen.clear;
|
|
37
|
+
const a = this.lines.slice(
|
|
38
|
+
this.scrollIndex,
|
|
39
|
+
this.scrollIndex + e
|
|
40
|
+
);
|
|
41
|
+
if (s += a.join(`
|
|
42
|
+
`) + `
|
|
43
|
+
`, a.length < e)
|
|
44
|
+
for (let l = 0; l < e - a.length; l++)
|
|
45
|
+
s += `~
|
|
46
|
+
`;
|
|
47
|
+
const c = i, h = Math.round((this.scrollIndex + e) / this.lines.length * 100), d = Math.min(100, h);
|
|
48
|
+
s += t.cursor.position(c, 1) + t.decoration.invert, s += ` ${this.fileName} (line ${this.scrollIndex + 1}/${this.lines.length}) ${d}% `, s += t.reset, await this.stdout.write(s + t.cursor.hide);
|
|
49
|
+
}
|
|
50
|
+
async handleInput(i) {
|
|
51
|
+
const e = this.size.y - 1;
|
|
52
|
+
switch (i) {
|
|
53
|
+
case "q":
|
|
54
|
+
case t.input.ctrlC:
|
|
55
|
+
case t.input.escape:
|
|
56
|
+
await this.stdout.write(t.cursor.show), this.exit();
|
|
57
|
+
return;
|
|
58
|
+
case "j":
|
|
59
|
+
case t.input.arrowDown:
|
|
60
|
+
this.scrollIndex + e < this.lines.length && this.scrollIndex++;
|
|
61
|
+
break;
|
|
62
|
+
case "k":
|
|
63
|
+
case t.input.arrowUp:
|
|
64
|
+
this.scrollIndex > 0 && this.scrollIndex--;
|
|
65
|
+
break;
|
|
66
|
+
case " ":
|
|
67
|
+
case t.input.pageDown:
|
|
68
|
+
this.scrollIndex = Math.min(
|
|
69
|
+
this.lines.length - e,
|
|
70
|
+
this.scrollIndex + e
|
|
71
|
+
), this.scrollIndex < 0 && (this.scrollIndex = 0);
|
|
72
|
+
break;
|
|
73
|
+
case "b":
|
|
74
|
+
case t.input.pageUp:
|
|
75
|
+
this.scrollIndex = Math.max(0, this.scrollIndex - e);
|
|
76
|
+
break;
|
|
77
|
+
case "g":
|
|
78
|
+
this.scrollIndex = 0;
|
|
79
|
+
break;
|
|
80
|
+
case "G":
|
|
81
|
+
this.scrollIndex = Math.max(0, this.lines.length - e);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
await this.emitAsync(n.RENDER_EVENT);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const f = new p().setManual({
|
|
88
|
+
purpose: "Display the contents of a file in a terminal",
|
|
89
|
+
usage: "less [FILE]",
|
|
90
|
+
description: "Less is a program similar to more, but it has many more features."
|
|
91
|
+
}).setExecute(async function(r, i) {
|
|
92
|
+
const e = new u(i, r), s = await e.init(r);
|
|
93
|
+
return s ? await o.writeError(i.stderr, this.name, s) : await e.run();
|
|
94
|
+
});
|
|
95
|
+
export {
|
|
96
|
+
f as less
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=less-wELkkcQx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"less-wELkkcQx.js","sources":["../../src/features/shell/commands/less.ts"],"sourcesContent":["import { Command } from \"../command\";\r\nimport { ANSI } from \"@prozilla-os/shared\";\r\nimport { TerminalUIApp } from \"../terminal-ui/terminalUIApp\";\r\nimport { Shell, ShellContext } from \"../shell\";\r\n\r\nenum LessMode {\r\n\tViewer\r\n}\r\n\r\nclass LessApp extends TerminalUIApp<LessMode> {\r\n\tprivate lines: string[] = [];\r\n\tprivate scrollIndex = 0;\r\n\tprivate fileName: string;\r\n\r\n\tconstructor(context: ShellContext, args: string[]) {\r\n\t\tsuper(context, LessMode.Viewer);\r\n\t\tthis.fileName = args[0] ?? \"stdin\";\r\n\r\n\t\tthis.on(TerminalUIApp.RENDER_EVENT, async () => {\r\n\t\t\tawait this.render();\r\n\t\t});\r\n\t\tthis.on(TerminalUIApp.INPUT_EVENT, async (data) => {\r\n\t\t\tawait this.handleInput(data);\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Reads the file or stream content.\r\n\t */\r\n\tpublic async init(args: string[]): Promise<string | null> {\r\n\t\tif (!args.length)\r\n\t\t\treturn \"No file specified\";\r\n\r\n\t\tconst targetFile = this.context.workingDirectory.navigate(this.fileName);\r\n\t\tif (!targetFile)\r\n\t\t\treturn `${this.fileName}: ${Shell.INVALID_PATH_ERROR}`;\r\n\r\n\t\tif (targetFile.isFolder())\r\n\t\t\treturn `${this.fileName}: Is a directory`;\r\n\r\n\t\tconst content = await targetFile.read();\r\n\t\tthis.lines = content?.split(\"\\n\") ?? [\"\"];\r\n\t\t\r\n\t\treturn null;\r\n\t}\r\n\r\n\tprivate async render(): Promise<void> {\r\n\t\tconst terminalHeight = this.size.y;\r\n\t\tconst mainViewHeight = terminalHeight - 1;\r\n\t\tlet view = ANSI.screen.home + ANSI.screen.clear;\r\n\r\n\t\t// Content Area\r\n\t\tconst visibleLines = this.lines.slice(\r\n\t\t\tthis.scrollIndex, \r\n\t\t\tthis.scrollIndex + mainViewHeight\r\n\t\t);\r\n\r\n\t\tview += visibleLines.join(\"\\n\") + \"\\n\";\r\n\t\tif (visibleLines.length < mainViewHeight) {\r\n\t\t\tfor (let i = 0; i < mainViewHeight - visibleLines.length; i++) {\r\n\t\t\t\tview += \"~\\n\";\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst statusRow = terminalHeight;\r\n\t\tconst progress = Math.round((this.scrollIndex + mainViewHeight) / this.lines.length * 100);\r\n\t\tconst clampedProgress = Math.min(100, progress);\r\n\t\t\r\n\t\tview += ANSI.cursor.position(statusRow, 1) + ANSI.decoration.invert;\r\n\t\tview += ` ${this.fileName} (line ${this.scrollIndex + 1}/${this.lines.length}) ${clampedProgress}% `;\r\n\t\tview += ANSI.reset;\r\n\r\n\t\tawait this.stdout.write(view + ANSI.cursor.hide);\r\n\t}\r\n\r\n\tprivate async handleInput(data: string): Promise<void> {\r\n\t\tconst mainViewHeight = this.size.y - 1;\r\n\r\n\t\tswitch (data) {\r\n\t\t\tcase \"q\":\r\n\t\t\tcase ANSI.input.ctrlC:\r\n\t\t\tcase ANSI.input.escape:\r\n\t\t\t\tawait this.stdout.write(ANSI.cursor.show);\r\n\t\t\t\tthis.exit();\r\n\t\t\t\treturn;\r\n\t\t\tcase \"j\":\r\n\t\t\tcase ANSI.input.arrowDown:\r\n\t\t\t\tif (this.scrollIndex + mainViewHeight < this.lines.length) {\r\n\t\t\t\t\tthis.scrollIndex++;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"k\":\r\n\t\t\tcase ANSI.input.arrowUp:\r\n\t\t\t\tif (this.scrollIndex > 0) {\r\n\t\t\t\t\tthis.scrollIndex--;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase \" \":\r\n\t\t\tcase ANSI.input.pageDown:\r\n\t\t\t\tthis.scrollIndex = Math.min(\r\n\t\t\t\t\tthis.lines.length - mainViewHeight, \r\n\t\t\t\t\tthis.scrollIndex + mainViewHeight\r\n\t\t\t\t);\r\n\t\t\t\tif (this.scrollIndex < 0) this.scrollIndex = 0;\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"b\":\r\n\t\t\tcase ANSI.input.pageUp:\r\n\t\t\t\tthis.scrollIndex = Math.max(0, this.scrollIndex - mainViewHeight);\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"g\":\r\n\t\t\t\tthis.scrollIndex = 0;\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"G\":\r\n\t\t\t\tthis.scrollIndex = Math.max(0, this.lines.length - mainViewHeight);\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\r\n\t\tawait this.emitAsync(TerminalUIApp.RENDER_EVENT);\r\n\t}\r\n}\r\n\r\nexport const less = new Command()\r\n\t.setManual({\r\n\t\tpurpose: \"Display the contents of a file in a terminal\",\r\n\t\tusage: \"less [FILE]\",\r\n\t\tdescription: \"Less is a program similar to more, but it has many more features.\",\r\n\t})\r\n\t.setExecute(async function(this: Command, args, context) {\r\n\t\tconst app = new LessApp(context, args);\r\n\t\t\r\n\t\tconst error = await app.init(args);\r\n\t\tif (error)\r\n\t\t\treturn await Shell.writeError(context.stderr, this.name, error);\r\n\r\n\t\treturn await app.run();\r\n\t});"],"names":["LessApp","TerminalUIApp","context","args","data","targetFile","Shell","content","terminalHeight","mainViewHeight","view","ANSI","visibleLines","i","statusRow","progress","clampedProgress","less","Command","app","error"],"mappings":";;;AASA,MAAMA,UAAgBC,EAAwB;AAAA,EACrC,QAAkB,CAAA;AAAA,EAClB,cAAc;AAAA,EACd;AAAA,EAER,YAAYC,GAAuBC,GAAgB;AAClD;AAAA,MAAMD;AAAA,MAAS;AAAA;AAAA,IAAA,GACf,KAAK,WAAWC,EAAK,CAAC,KAAK,SAE3B,KAAK,GAAGF,EAAc,cAAc,YAAY;AAC/C,YAAM,KAAK,OAAA;AAAA,IACZ,CAAC,GACD,KAAK,GAAGA,EAAc,aAAa,OAAOG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AAA;AAClB,CAAC;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseOptionalFloat as f, ANSI as e } from "@prozilla-os/shared";
|
|
2
|
-
import { Command as O, Stream as x, EXIT_CODE as
|
|
3
|
-
const
|
|
2
|
+
import { Command as O, Stream as x, EXIT_CODE as y } from "../main.js";
|
|
3
|
+
const d = [
|
|
4
4
|
e.fg.red,
|
|
5
5
|
e.fg.yellow,
|
|
6
6
|
e.fg.green,
|
|
@@ -27,41 +27,41 @@ const p = [
|
|
|
27
27
|
short: "S",
|
|
28
28
|
long: "seed",
|
|
29
29
|
isInput: !0
|
|
30
|
-
}).setExecute(function(
|
|
31
|
-
const m = f(
|
|
32
|
-
let
|
|
33
|
-
const I = (o) => {
|
|
34
|
-
let s = "",
|
|
30
|
+
}).setExecute(function(S, { timestamp: g, stdout: h, stdin: p, inputs: i }) {
|
|
31
|
+
const m = f(i.p, 3), w = f(i.F, 0.1), b = f(i.S);
|
|
32
|
+
let l = 0;
|
|
33
|
+
const I = async (o) => {
|
|
34
|
+
let s = "", a = 0, r = 0;
|
|
35
35
|
const q = g / 1e3;
|
|
36
|
-
for (;
|
|
37
|
-
const t = o[
|
|
36
|
+
for (; a < o.length; ) {
|
|
37
|
+
const t = o[a];
|
|
38
38
|
if (t === "\x1B") {
|
|
39
|
-
const c = o.substring(
|
|
39
|
+
const c = o.substring(a).match(/^\u001b\[[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/);
|
|
40
40
|
if (c) {
|
|
41
41
|
const n = c[0];
|
|
42
|
-
s += n, (n === e.screen.home || n === e.screen.clear) && (
|
|
42
|
+
s += n, (n === e.screen.home || n === e.screen.clear) && (l = 0, r = 0), a += n.length;
|
|
43
43
|
continue;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
if (t === `
|
|
47
47
|
`)
|
|
48
48
|
s += `
|
|
49
|
-
`,
|
|
49
|
+
`, l++, r = 0;
|
|
50
50
|
else if (t === "\r" || t === " " || t === " ")
|
|
51
|
-
s += t,
|
|
51
|
+
s += t, r++;
|
|
52
52
|
else {
|
|
53
|
-
const u = w * (b +
|
|
54
|
-
s += n + t + e.reset,
|
|
53
|
+
const u = w * (b + l + r / m + q), c = Math.floor(Math.abs(u) * d.length), n = d[c % d.length];
|
|
54
|
+
s += n + t + e.reset, r++;
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
a++;
|
|
57
57
|
}
|
|
58
|
-
h.write(s);
|
|
58
|
+
await h.write(s);
|
|
59
59
|
};
|
|
60
|
-
return
|
|
60
|
+
return p.on(x.DATA_EVENT, (o) => {
|
|
61
61
|
I(o);
|
|
62
|
-
}),
|
|
62
|
+
}), p.wait(y.success);
|
|
63
63
|
});
|
|
64
64
|
export {
|
|
65
65
|
F as lolcat
|
|
66
66
|
};
|
|
67
|
-
//# sourceMappingURL=lolcat-
|
|
67
|
+
//# sourceMappingURL=lolcat-xpDAXsIt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lolcat-xpDAXsIt.js","sources":["../../src/features/shell/commands/lolcat.ts"],"sourcesContent":["import { ANSI, parseOptionalFloat } from \"@prozilla-os/shared\";\nimport { Command } from \"../command\";\nimport { Stream } from \"../streams/stream\";\nimport { EXIT_CODE } from \"../../../constants\";\n\nconst RAINBOW = [\n\tANSI.fg.red,\n\tANSI.fg.yellow,\n\tANSI.fg.green,\n\tANSI.fg.cyan,\n\tANSI.fg.blue,\n\tANSI.fg.magenta,\n];\n\nexport const lolcat = new Command()\n\t.setManual({\n\t\tpurpose: \"Display text with a rainbow effect\",\n\t\tusage: \"lolcat [ -p spread ] [ -F freq ] [ -S seed ]\",\n\t\toptions: {\n\t\t\t\"-p spread\": \"Rainbow spread (default: 3.0)\",\n\t\t\t\"-F freq\": \"Rainbow frequency (default: 0.1)\",\n\t\t\t\"-S seed\": \"Rainbow seed (default: 0)\",\n\t\t},\n\t})\n\t.addOption({\n\t\tshort: \"p\",\n\t\tlong: \"spread\",\n\t\tisInput: true,\n\t})\n\t.addOption({\n\t\tshort: \"F\",\n\t\tlong: \"freq\",\n\t\tisInput: true,\n\t})\n\t.addOption({\n\t\tshort: \"S\",\n\t\tlong: \"seed\",\n\t\tisInput: true,\n\t})\n\t.setExecute(function(this: Command, _args, { timestamp, stdout, stdin, inputs }) {\n\t\tconst spread = parseOptionalFloat(inputs.p, 3.0);\n\t\tconst freq = parseOptionalFloat(inputs.F, 0.1);\n\t\tconst seed = parseOptionalFloat(inputs.S);\n\n\t\tlet lineIndex = 0;\n\n\t\tconst processText = async (text: string) => {\n\t\t\tlet output = \"\";\n\t\t\tlet i = 0;\n\t\t\tlet colIndex = 0;\n\t\t\tconst offset = timestamp / 1000;\n\n\t\t\twhile (i < text.length) {\n\t\t\t\tconst char = text[i];\n\n\t\t\t\tif (char === \"\\x1b\") {\n\t\t\t\t\tconst remaining = text.substring(i);\n\t\t\t\t\t// eslint-disable-next-line no-control-regex\n\t\t\t\t\tconst match = remaining.match(/^\\u001b\\[[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/);\n\t\t\t\t\t\n\t\t\t\t\tif (match) {\n\t\t\t\t\t\tconst seq = match[0];\n\t\t\t\t\t\toutput += seq;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (seq === ANSI.screen.home || seq === ANSI.screen.clear) {\n\t\t\t\t\t\t\tlineIndex = 0;\n\t\t\t\t\t\t\tcolIndex = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\ti += seq.length;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (char === \"\\n\") {\n\t\t\t\t\toutput += \"\\n\";\n\t\t\t\t\tlineIndex++;\n\t\t\t\t\tcolIndex = 0;\n\t\t\t\t} else if (char === \"\\r\" || char === \"\\t\" || char === \" \") {\n\t\t\t\t\toutput += char;\n\t\t\t\t\tcolIndex++;\n\t\t\t\t} else {\n\t\t\t\t\tconst iVal = freq * (seed + lineIndex + colIndex / spread + offset);\n\t\t\t\t\tconst rainbowIndex = Math.floor(Math.abs(iVal) * RAINBOW.length);\n\t\t\t\t\tconst color = RAINBOW[rainbowIndex % RAINBOW.length];\n\n\t\t\t\t\toutput += color + char + ANSI.reset;\n\t\t\t\t\tcolIndex++;\n\t\t\t\t}\n\t\t\t\ti++;\n\t\t\t}\n\n\t\t\tawait stdout.write(output);\n\t\t};\n\n\t\tstdin.on(Stream.DATA_EVENT, (data) => {\n\t\t\tvoid processText(data);\n\t\t});\n\n\t\treturn stdin.wait(EXIT_CODE.success);\n\t});"],"names":["RAINBOW","ANSI","lolcat","Command","_args","timestamp","stdout","stdin","inputs","spread","parseOptionalFloat","freq","seed","lineIndex","processText","text","output","i","colIndex","offset","char","match","seq","iVal","rainbowIndex","color","Stream","data","EXIT_CODE"],"mappings":";;AAKA,MAAMA,IAAU;AAAA,EACfC,EAAK,GAAG;AAAA,EACRA,EAAK,GAAG;AAAA,EACRA,EAAK,GAAG;AAAA,EACRA,EAAK,GAAG;AAAA,EACRA,EAAK,GAAG;AAAA,EACRA,EAAK,GAAG;AACT,GAEaC,IAAS,IAAIC,EAAA,EACxB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,IACR,aAAa;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,EAAA;AAEb,CAAC,EACA,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AAAA,EACN,SAAS;AACV,CAAC,EACA,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AAAA,EACN,SAAS;AACV,CAAC,EACA,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AAAA,EACN,SAAS;AACV,CAAC,EACA,WAAW,SAAwBC,GAAO,EAAE,WAAAC,GAAW,QAAAC,GAAQ,OAAAC,GAAO,QAAAC,KAAU;AAChF,QAAMC,IAASC,EA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|
+
import { Command as d, Shell as r } from "../main.js";
|
|
2
2
|
import { ANSI as s } from "@prozilla-os/shared";
|
|
3
|
-
const p = new
|
|
3
|
+
const p = new d().setManual({
|
|
4
4
|
purpose: "List directory contents",
|
|
5
5
|
usage: "ls [options] [files]",
|
|
6
6
|
description: "List information about directories or files (the current directory by default)."
|
|
7
|
-
}).setExecute(function(t, { workingDirectory: i, stdout:
|
|
7
|
+
}).setExecute(async function(t, { workingDirectory: i, stdout: c, stderr: a }) {
|
|
8
8
|
let e = i;
|
|
9
9
|
if (t.length && (e = i.navigateToFolder(t[0])), !e)
|
|
10
|
-
return
|
|
11
|
-
const l = e.subFolders.map((o) => `${s.fg.blue}${o.id}${s.reset}`),
|
|
12
|
-
|
|
10
|
+
return r.writeError(a, this.name, `Cannot access '${t[0]}': No such file or directory`);
|
|
11
|
+
const l = e.subFolders.map((o) => `${s.fg.blue}${o.id}${s.reset}`), f = e.files.map((o) => o.id), n = l.concat(f);
|
|
12
|
+
n.length && await r.printLn(c, n.sort().join(" "));
|
|
13
13
|
});
|
|
14
14
|
export {
|
|
15
15
|
p as ls
|
|
16
16
|
};
|
|
17
|
-
//# sourceMappingURL=ls-
|
|
17
|
+
//# sourceMappingURL=ls-D2Ln7mue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ls-D2Ln7mue.js","sources":["../../src/features/shell/commands/ls.ts"],"sourcesContent":["import { VirtualFolder } from \"../../virtual-drive\";\nimport { Shell } from \"../shell\";\nimport { Command } from \"../command\";\nimport { ANSI } from \"@prozilla-os/shared\";\n\nexport const ls = new Command()\n\t.setManual({\n\t\tpurpose: \"List directory contents\",\n\t\tusage: \"ls [options] [files]\",\n\t\tdescription: \"List information about directories or files (the current directory by default).\",\n\t})\n\t.setExecute(async function(this: Command, args, { workingDirectory, stdout, stderr }) {\n\t\tlet directory: VirtualFolder | null = workingDirectory;\n\t\tif (args.length)\n\t\t\tdirectory = workingDirectory.navigateToFolder(args[0]);\n\t\n\t\tif (!directory)\n\t\t\treturn Shell.writeError(stderr, this.name, `Cannot access '${args[0]}': No such file or directory`);\n\t\n\t\tconst folderNames = directory.subFolders.map((folder) => `${ANSI.fg.blue}${folder.id}${ANSI.reset}`);\n\t\tconst fileNames = directory.files.map((file) => file.id);\n\t\n\t\tconst contents = folderNames.concat(fileNames);\n\t\n\t\tif (contents.length)\n\t\t\tawait Shell.printLn(stdout, contents.sort().join(\" \"));\n\t});"],"names":["ls","Command","args","workingDirectory","stdout","stderr","directory","Shell","folderNames","folder","ANSI","fileNames","file","contents"],"mappings":";;AAKO,MAAMA,IAAK,IAAIC,EAAA,EACpB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,OAAO;AAAA,EACP,aAAa;AACd,CAAC,EACA,WAAW,eAA8BC,GAAM,EAAE,kBAAAC,GAAkB,QAAAC,GAAQ,QAAAC,KAAU;AACrF,MAAIC,IAAkCH;AAItC,MAHID,EAAK,WACRI,IAAYH,EAAiB,iBAAiBD,EAAK,CAAC,CAAC,IAElD,CAACI;AACJ,WAAOC,EAAM,WAAWF,GAAQ,KAAK,MAAM,kBAAkBH,EAAK,CAAC,CAAC,8BAA8B;AAEnG,QAAMM,IAAcF,EAAU,WAAW,IAAI,CAACG,MAAW,GAAGC,EAAK,GAAG,IAAI,GAAGD,EAAO,EAAE,GAAGC,EAAK,KAAK,EAAE,GAC7FC,IAAYL,EAAU,MAAM,IAAI,CAACM,MAASA,EAAK,EAAE,GAEjDC,IAAWL,EAAY,OAAOG,CAAS;AAE7C,EAAIE,EAAS,UACZ,MAAMN,EAAM,QAAQH,GAAQS,EAAS,OAAO,KAAK,IAAI,CAAC;AACxD,CAAC;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ANSI as g, Ansi as r } from "@prozilla-os/shared";
|
|
2
|
+
import { Command as x, ExecutableResolver as w, Shell as p } from "../main.js";
|
|
3
|
+
const N = 5, E = new x().setRequireArgs(!0).setManual({
|
|
4
|
+
purpose: "Show system reference manuals",
|
|
5
|
+
usage: `man [options] page
|
|
6
|
+
man -k [options] regexp`,
|
|
7
|
+
description: `Each page arguments given to man is normally the name of a command.
|
|
8
|
+
The manual page associated with this command is then found and displayed.`,
|
|
9
|
+
options: {
|
|
10
|
+
"-k": "Search for manual page using regexp"
|
|
11
|
+
}
|
|
12
|
+
}).addOption({
|
|
13
|
+
short: "k",
|
|
14
|
+
long: "apropos"
|
|
15
|
+
}).setExecute(async function(l, { options: S, stdout: c, stderr: d }) {
|
|
16
|
+
if (S.includes("k")) {
|
|
17
|
+
const a = w.builtins.filter((n) => n.name.match(l[0].toLowerCase())).map((n) => n.manual?.purpose ? `${n.name} - ${n.manual.purpose}` : n.name).sort().join(`
|
|
18
|
+
`);
|
|
19
|
+
await p.printLn(c, a);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const i = l[0].toLowerCase(), u = w.getBuiltin(i);
|
|
23
|
+
if (!u)
|
|
24
|
+
return p.writeError(d, this.name, `${i}: Command not found`);
|
|
25
|
+
const o = u.manual;
|
|
26
|
+
if (!o)
|
|
27
|
+
return p.writeError(d, this.name, `${i}: No manual found`);
|
|
28
|
+
const s = (e) => e.split(`
|
|
29
|
+
`).map((n) => " ".repeat(N) + n).join(`
|
|
30
|
+
`), t = [["NAME"]];
|
|
31
|
+
o.purpose ? t[0].push(s(`${i} - ${g.decoration.dim}${r.yellow(o.purpose)}`)) : t[0].push(s(i)), o.usage && t.push([
|
|
32
|
+
"SYNOPSIS",
|
|
33
|
+
s(o.usage)
|
|
34
|
+
]), o.description && t.push([
|
|
35
|
+
"DESCRIPTION",
|
|
36
|
+
s(o.description)
|
|
37
|
+
]), o.options && t.push([
|
|
38
|
+
"OPTIONS",
|
|
39
|
+
s(Object.entries(o.options).map(([e, a]) => {
|
|
40
|
+
let n = e.split(" ");
|
|
41
|
+
const f = n[0].slice(1);
|
|
42
|
+
n = n.slice(1);
|
|
43
|
+
let m = "-" + f;
|
|
44
|
+
const h = u.options.find((y) => y.short == f);
|
|
45
|
+
return h !== void 0 && (m += ", --" + h.long), n.length && (m += " " + r.dim(n.join(" "))), `${m} ${g.decoration.dim}${r.yellow(String(a))}`;
|
|
46
|
+
}).join(`
|
|
47
|
+
`))
|
|
48
|
+
]);
|
|
49
|
+
const $ = t.map((e) => (e[0] = r.yellow(e[0]), e.join(`
|
|
50
|
+
`))).join(`
|
|
51
|
+
|
|
52
|
+
`);
|
|
53
|
+
await p.printLn(c, $);
|
|
54
|
+
});
|
|
55
|
+
export {
|
|
56
|
+
E as man
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=man-E9nMmKZ1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"man-E9nMmKZ1.js","sources":["../../src/features/shell/commands/man.ts"],"sourcesContent":["import { Ansi, ANSI } from \"@prozilla-os/shared\";\nimport { Shell } from \"../shell\";\nimport { Command } from \"../command\";\nimport { ExecutableResolver } from \"../executableResolver\";\n\nconst MARGIN = 5;\n\nexport const man = new Command()\n\t.setRequireArgs(true)\n\t.setManual({\n\t\tpurpose: \"Show system reference manuals\",\n\t\tusage: \"man [options] page\\n\"\n\t\t\t+ \"man -k [options] regexp\",\n\t\tdescription: \"Each page arguments given to man is normally the name of a command.\\n\"\n\t\t\t+ \"The manual page associated with this command is then found and displayed.\",\n\t\toptions: {\n\t\t\t\"-k\": \"Search for manual page using regexp\",\n\t\t},\n\t})\n\t.addOption({\n\t\tshort: \"k\",\n\t\tlong: \"apropos\",\n\t})\n\t.setExecute(async function(this: Command, args, { options, stdout, stderr }) {\n\t\t// Search function\n\t\tif (options.includes(\"k\")) {\n\t\t\tconst commands = ExecutableResolver.builtins.filter((builtin) => builtin.name.match(args[0].toLowerCase()));\n\t\t\tconst output = commands.map((command) => {\n\t\t\t\tif (command.manual?.purpose) {\n\t\t\t\t\treturn `${command.name} - ${command.manual.purpose}`;\n\t\t\t\t} else {\n\t\t\t\t\treturn command.name;\n\t\t\t\t}\n\t\t\t}).sort().join(\"\\n\");\n\n\t\t\tawait Shell.printLn(stdout, output);\n\t\t\treturn;\n\t\t}\n\n\t\tconst commandName = args[0].toLowerCase();\n\t\tconst command = ExecutableResolver.getBuiltin(commandName);\n\n\t\tif (!command)\n\t\t\treturn Shell.writeError(stderr, this.name, `${commandName}: Command not found`);\n\n\t\tconst manual = command.manual;\n\n\t\tif (!manual)\n\t\t\treturn Shell.writeError(stderr, this.name, `${commandName}: No manual found`);\n\n\t\tconst formatText = (text: string) => {\n\t\t\tconst lines = text.split(\"\\n\").map((line) => \" \".repeat(MARGIN) + line);\n\t\t\treturn lines.join(\"\\n\");\n\t\t};\n\n\t\tconst sections = [[\"NAME\"]];\n\n\t\tif (manual.purpose) {\n\t\t\tsections[0].push(formatText(`${commandName} - ${ANSI.decoration.dim}${Ansi.yellow(manual.purpose)}`));\n\t\t} else {\n\t\t\tsections[0].push(formatText(commandName));\n\t\t}\n\n\t\tif (manual.usage) {\n\t\t\tsections.push([\n\t\t\t\t\"SYNOPSIS\",\n\t\t\t\tformatText(manual.usage),\n\t\t\t]);\n\t\t}\n\t\t\n\t\tif (manual.description) {\n\t\t\tsections.push([\n\t\t\t\t\"DESCRIPTION\",\n\t\t\t\tformatText(manual.description),\n\t\t\t]);\n\t\t}\n\n\t\tif (manual.options) {\n\t\t\tsections.push([\n\t\t\t\t\"OPTIONS\",\n\t\t\t\tformatText(Object.entries(manual.options).map(([key, value]) => {\n\t\t\t\t\tlet rawOptionSyntax = key.split(\" \");\n\t\t\t\t\tconst shortOption = rawOptionSyntax[0].slice(1);\n\t\t\t\t\trawOptionSyntax = rawOptionSyntax.slice(1);\n\n\t\t\t\t\tlet optionSyntax = \"-\" + shortOption;\n\t\t\t\t\tconst option = command.options.find((option) => option.short == shortOption);\n\t\t\t\t\tif (option !== undefined) {\n\t\t\t\t\t\toptionSyntax += \", --\" + option.long;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (rawOptionSyntax.length) {\n\t\t\t\t\t\toptionSyntax += \" \" + Ansi.dim(rawOptionSyntax.join(\" \"));\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\treturn `${optionSyntax} ${ANSI.decoration.dim}${Ansi.yellow(String(value))}`;\n\t\t\t\t}).join(\"\\n\")),\n\t\t\t]);\n\t\t}\n\n\t\tconst output = sections.map((section) => {\n\t\t\tsection[0] = Ansi.yellow(section[0]);\n\t\t\treturn section.join(\"\\n\");\n\t\t}).join(\"\\n\\n\");\n\n\t\tawait Shell.printLn(stdout, output);\n\t});"],"names":["MARGIN","man","Command","args","options","stdout","stderr","output","ExecutableResolver","builtin","command","Shell","commandName","manual","formatText","text","line","sections","ANSI","Ansi","key","value","rawOptionSyntax","shortOption","optionSyntax","option","section"],"mappings":";;AAKA,MAAMA,IAAS,GAEFC,IAAM,IAAIC,EAAA,EACrB,eAAe,EAAI,EACnB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,OAAO;AAAA;AAAA,EAEP,aAAa;AAAA;AAAA,EAEb,SAAS;AAAA,IACR,MAAM;AAAA,EAAA;AAER,CAAC,EACA,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AACP,CAAC,EACA,WAAW,eAA8BC,GAAM,EAAE,SAAAC,GAAS,QAAAC,GAAQ,QAAAC,KAAU;AAE5E,MAAIF,EAAQ,SAAS,GAAG,GAAG;AAE1B,UAAMG,IADWC,EAAmB,SAAS,OAAO,CAACC,MAAYA,EAAQ,KAAK,MAAMN,EAAK,CAAC,EAAE,YAAA,CAAa,CAAC,EAClF,IAAI,CAACO,MACxBA,EAAQ,QAAQ,UACZ,GAAGA,EAAQ,IAAI,MAAMA,EAAQ,OAAO,OAAO,KAE3CA,EAAQ,IAEhB,EAAE,OAAO,KAAK;AAAA,CAAI;AAEnB,UAAMC,EAAM,QAAQN,GAAQE,CAAM;AAClC;AAAA,EACD;AAEA,QAAMK,IAAcT,EAAK,CAAC,EAAE,YAAA,GACtBO,IAAUF,EAAmB,WAAWI,CAAW;AAEzD,MAAI,CAACF;A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AAGE,CAAY,IAAIN,EAAK,WAAW,GAAG,GAAGC,EAAK,OAAO,OAAOE,CAAK,CAAC,CAAC;AAAA,IAC3E,CAAC,EAAE,KAAK;AAAA,CAAI,CAAC;AAAA,EAAA,CACb;AAGF,QAAMd,IAASU,EAAS,IAAI,CAACS,OAC5BA,EAAQ,CAAC,IAAIP,EAAK,OAAOO,EAAQ,CAAC,CAAC,GAC5BA,EAAQ,KAAK;AAAA,CAAI,EACxB,EAAE,KAAK;AAAA;AAAA,CAAM;AAEd,QAAMf,EAAM,QAAQN,GAAQE,CAAM;AACnC,CAAC;"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Command as c, Shell as u } from "../main.js";
|
|
2
|
+
import { ANSI as e, Ansi as n } from "@prozilla-os/shared";
|
|
3
|
+
import { T as d } from "./terminalUIApp-Bmiaqvd9.js";
|
|
4
|
+
import { T as m } from "./textEditorApp-BM3EiMoV.js";
|
|
5
|
+
class p extends m {
|
|
6
|
+
constructor(t, i) {
|
|
7
|
+
super(t, 0, { args: i });
|
|
8
|
+
}
|
|
9
|
+
async render() {
|
|
10
|
+
const t = this.size.y, i = t - 4;
|
|
11
|
+
let s = e.screen.home + e.screen.clear;
|
|
12
|
+
s += e.cursor.position(1, 1) + n.invert(` GNU nano 2.0.6 File: ${this.fileName} `) + `
|
|
13
|
+
`;
|
|
14
|
+
for (let r = 0; r < i; r++)
|
|
15
|
+
r < this.lines.length ? s += this.lines[r] + `
|
|
16
|
+
` : s += `
|
|
17
|
+
`;
|
|
18
|
+
const h = t - 2;
|
|
19
|
+
s += e.cursor.position(h, 1) + (this.statusMessage.length ? this.statusMessage : "");
|
|
20
|
+
const a = t - 1;
|
|
21
|
+
s += e.cursor.position(a, 1) + n.invert("^G") + " Get Help " + n.invert("^O") + " Write Out " + n.invert("^R") + " Read File " + n.invert("^Y") + " Prev Pg" + e.cursor.position(a + 1, 1) + n.invert("^X") + " Exit " + n.invert("^J") + " Justify " + n.invert("^W") + " Where Is " + n.invert("^V") + " Next Pg";
|
|
22
|
+
const l = e.cursor.position(this.rowIndex + 2, this.columnIndex + 1);
|
|
23
|
+
await this.stdout.write(s + l);
|
|
24
|
+
}
|
|
25
|
+
async handleInput(t) {
|
|
26
|
+
this.statusMessage = "";
|
|
27
|
+
const i = this.lines[this.rowIndex];
|
|
28
|
+
switch (t) {
|
|
29
|
+
case e.input.ctrlO:
|
|
30
|
+
this.saveFile();
|
|
31
|
+
break;
|
|
32
|
+
case e.input.ctrlX:
|
|
33
|
+
this.exit();
|
|
34
|
+
return;
|
|
35
|
+
case e.input.carriageReturn:
|
|
36
|
+
case e.input.lineFeed:
|
|
37
|
+
this.lines[this.rowIndex] = i.slice(0, this.columnIndex), this.lines.splice(this.rowIndex + 1, 0, i.slice(this.columnIndex)), this.rowIndex++, this.columnIndex = 0;
|
|
38
|
+
break;
|
|
39
|
+
case e.input.backspace:
|
|
40
|
+
case e.input.delete:
|
|
41
|
+
this.deleteCharacter(i);
|
|
42
|
+
break;
|
|
43
|
+
case e.input.arrowUp:
|
|
44
|
+
this.rowIndex = Math.max(0, this.rowIndex - 1), this.columnIndex = Math.min(this.columnIndex, this.lines[this.rowIndex].length);
|
|
45
|
+
break;
|
|
46
|
+
case e.input.arrowDown:
|
|
47
|
+
this.rowIndex = Math.min(this.lines.length - 1, this.rowIndex + 1), this.columnIndex = Math.min(this.columnIndex, this.lines[this.rowIndex].length);
|
|
48
|
+
break;
|
|
49
|
+
case e.input.arrowLeft:
|
|
50
|
+
this.columnIndex = Math.max(0, this.columnIndex - 1);
|
|
51
|
+
break;
|
|
52
|
+
case e.input.arrowRight:
|
|
53
|
+
this.columnIndex = Math.min(this.lines[this.rowIndex].length, this.columnIndex + 1);
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
t.length === 1 && t.charCodeAt(0) >= 32 && (this.lines[this.rowIndex] = i.slice(0, this.columnIndex) + t + i.slice(this.columnIndex), this.columnIndex++);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
await this.emitAsync(d.RENDER_EVENT);
|
|
60
|
+
}
|
|
61
|
+
saveFile() {
|
|
62
|
+
if (!this.args.length)
|
|
63
|
+
return this.statusMessage = "File Name to Write: " + this.fileName, !1;
|
|
64
|
+
const t = super.saveFile();
|
|
65
|
+
return t && (this.statusMessage = `[ Wrote ${this.lines.length} lines ]`), t;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const f = new c().setManual({
|
|
69
|
+
purpose: "Nano's ANOther editor, an enhanced free Pico clone",
|
|
70
|
+
usage: "nano [FILE]",
|
|
71
|
+
description: `nano is a small, free and friendly editor which aims to replace Pico, the default editor included in the non-free Pine package. Rather than just copying Pico's look and feel, nano also implements some missing (or disabled by default) features in Pico, such as "search and replace" and "go to line and column number"`
|
|
72
|
+
}).setExecute(async function(o, t) {
|
|
73
|
+
const i = new p(t, o), s = await i.init();
|
|
74
|
+
return s.isError() ? await u.writeError(t.stderr, this.name, s.error) : await i.run();
|
|
75
|
+
});
|
|
76
|
+
export {
|
|
77
|
+
f as nano
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=nano-DsRjsQ-k.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nano-DsRjsQ-k.js","sources":["../../src/features/shell/commands/nano.ts"],"sourcesContent":["import { Command } from \"../command\";\r\nimport { Ansi, ANSI } from \"@prozilla-os/shared\";\r\nimport { TerminalUIApp } from \"../terminal-ui/terminalUIApp\";\r\nimport { Shell, ShellContext } from \"../shell\";\r\nimport { TextEditorApp } from \"../terminal-ui/textEditorApp\";\r\n\r\nenum NanoMode {\r\n\tEditor\r\n}\r\n\r\nclass NanoApp extends TextEditorApp<NanoMode> {\r\n\tconstructor(context: ShellContext, args: string[]) {\r\n\t\tsuper(context, NanoMode.Editor, { args });\r\n\t}\r\n\r\n\tprotected override async render() {\r\n\t\tconst terminalHeight = this.size.y;\r\n\t\tconst mainViewHeight = terminalHeight - 4;\r\n\t\tlet view = ANSI.screen.home + ANSI.screen.clear;\r\n\r\n\t\t// Title Bar\r\n\t\tview += ANSI.cursor.position(1, 1) + Ansi.invert(` GNU nano 2.0.6 File: ${this.fileName} `) + \"\\n\";\r\n\r\n\t\t// Content Area\r\n\t\tfor (let index = 0; index < mainViewHeight; index++) {\r\n\t\t\tif (index < this.lines.length) {\r\n\t\t\t\tview += this.lines[index] + \"\\n\";\r\n\t\t\t} else {\r\n\t\t\t\tview += \"\\n\";\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Status Message\r\n\t\tconst statusRow = terminalHeight - 2;\r\n\t\tview += ANSI.cursor.position(statusRow, 1) + (this.statusMessage.length ? this.statusMessage : \"\");\r\n\r\n\t\t// Shortcut Legend\r\n\t\tconst shortcutRow = terminalHeight - 1;\r\n\t\tview += ANSI.cursor.position(shortcutRow, 1) \r\n\t\t\t+ Ansi.invert(\"^G\") + \" Get Help \" + Ansi.invert(\"^O\") + \" Write Out \" + Ansi.invert(\"^R\") + \" Read File \" + Ansi.invert(\"^Y\") + \" Prev Pg\"\r\n\t\t\t+ ANSI.cursor.position(shortcutRow + 1, 1)\r\n\t\t\t+ Ansi.invert(\"^X\") + \" Exit \" + Ansi.invert(\"^J\") + \" Justify \" + Ansi.invert(\"^W\") + \" Where Is \" + Ansi.invert(\"^V\") + \" Next Pg\";\r\n\r\n\t\tconst cursorPosition = ANSI.cursor.position(this.rowIndex + 2, this.columnIndex + 1);\r\n\t\tawait this.stdout.write(view + cursorPosition);\r\n\t}\r\n\r\n\tprotected override async handleInput(data: string) {\r\n\t\tthis.statusMessage = \"\";\r\n\t\tconst currentLine = this.lines[this.rowIndex];\r\n\r\n\t\tswitch (data) {\r\n\t\t\tcase ANSI.input.ctrlO:\r\n\t\t\t\tthis.saveFile();\r\n\t\t\t\tbreak;\r\n\t\t\tcase ANSI.input.ctrlX:\r\n\t\t\t\tthis.exit();\r\n\t\t\t\treturn;\r\n\t\t\tcase ANSI.input.carriageReturn:\r\n\t\t\tcase ANSI.input.lineFeed:\r\n\t\t\t\tthis.lines[this.rowIndex] = currentLine.slice(0, this.columnIndex);\r\n\t\t\t\tthis.lines.splice(this.rowIndex + 1, 0, currentLine.slice(this.columnIndex));\r\n\t\t\t\tthis.rowIndex++;\r\n\t\t\t\tthis.columnIndex = 0;\r\n\t\t\t\tbreak;\r\n\t\t\tcase ANSI.input.backspace:\r\n\t\t\tcase ANSI.input.delete:\r\n\t\t\t\tthis.deleteCharacter(currentLine);\r\n\t\t\t\tbreak;\r\n\t\t\tcase ANSI.input.arrowUp:\r\n\t\t\t\tthis.rowIndex = Math.max(0, this.rowIndex - 1);\r\n\t\t\t\tthis.columnIndex = Math.min(this.columnIndex, this.lines[this.rowIndex].length);\r\n\t\t\t\tbreak;\r\n\t\t\tcase ANSI.input.arrowDown:\r\n\t\t\t\tthis.rowIndex = Math.min(this.lines.length - 1, this.rowIndex + 1);\r\n\t\t\t\tthis.columnIndex = Math.min(this.columnIndex, this.lines[this.rowIndex].length);\r\n\t\t\t\tbreak;\r\n\t\t\tcase ANSI.input.arrowLeft:\r\n\t\t\t\tthis.columnIndex = Math.max(0, this.columnIndex - 1);\r\n\t\t\t\tbreak;\r\n\t\t\tcase ANSI.input.arrowRight:\r\n\t\t\t\tthis.columnIndex = Math.min(this.lines[this.rowIndex].length, this.columnIndex + 1);\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (data.length === 1 && data.charCodeAt(0) >= 32) {\r\n\t\t\t\t\tthis.lines[this.rowIndex] = currentLine.slice(0, this.columnIndex) + data + currentLine.slice(this.columnIndex);\r\n\t\t\t\t\tthis.columnIndex++;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\r\n\t\tawait this.emitAsync(TerminalUIApp.RENDER_EVENT);\r\n\t}\r\n\r\n\tprotected override saveFile() {\r\n\t\tif (!this.args.length) {\r\n\t\t\tthis.statusMessage = \"File Name to Write: \" + this.fileName;\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tconst saved = super.saveFile();\r\n\t\tif (saved)\r\n\t\t\tthis.statusMessage = `[ Wrote ${this.lines.length} lines ]`;\r\n\r\n\t\treturn saved;\r\n\t}\r\n}\r\n\r\nexport const nano = new Command()\r\n\t.setManual({\r\n\t\tpurpose: \"Nano's ANOther editor, an enhanced free Pico clone\",\r\n\t\tusage: \"nano [FILE]\",\r\n\t\tdescription: \"nano is a small, free and friendly editor which aims to replace Pico, the default editor included in the non-free Pine package. Rather than just copying Pico's look and feel, nano also implements some missing (or disabled by default) features in Pico, such as \\\"search and replace\\\" and \\\"go to line and column number\\\"\",\r\n\t})\r\n\t.setExecute(async function(this: Command, args, context) {\r\n\t\tconst app = new NanoApp(context, args);\r\n\t\t\r\n\t\tconst result = await app.init();\r\n\t\tif (result.isError())\r\n\t\t\treturn await Shell.writeError(context.stderr, this.name, result.error);\r\n\r\n\t\treturn await app.run();\r\n\t});"],"names":["NanoApp","TextEditorApp","context","args","terminalHeight","mainViewHeight","view","ANSI","Ansi","index","statusRow","shortcutRow","cursorPosition","data","currentLine","TerminalUIApp","saved","nano","Command","app","result","Shell"],"mappings":";;;;AAUA,MAAMA,UAAgBC,EAAwB;AAAA,EAC7C,YAAYC,GAAuBC,GAAgB;AAClD,UAAMD,GAAS,GAAiB,EAAE,MAAAC,EAAA,CAAM;AAAA,EACzC;AAAA,EAEA,MAAyB,SAAS;AACjC,UAAMC,IAAiB,KAAK,KAAK,GAC3BC,IAAiBD,IAAiB;AACxC,QAAIE,IAAOC,EAAK,OAAO,OAAOA,EAAK,OAAO;AAG1C,IAAAD,KAAQC,EAAK,OAAO,SAAS,GAAG,CAAC,IAAIC,EAAK,OAAO,qCAAqC,KAAK,QAAQ,GAAG,IAAI;AAAA;AAG1G,aAASC,IAAQ,GAAGA,IAAQJ,GAAgBI;AAC3C,MAAIA,IAAQ,KAAK,MAAM,SACtBH,KAAQ,KAAK,MAAMG,CAAK,IAAI;AAAA,IAE5BH,KAAQ;AAAA;A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,QAAA,IACH,MAAMC,EAAM,WAAWnB,EAAQ,QAAQ,KAAK,MAAMkB,EAAO,KAAK,IAE/D,MAAMD,EAAI,IAAA;AAClB,CAAC;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ANSI as n } from "@prozilla-os/shared";
|
|
2
|
+
import { Command as y, Settings as E, ANSI_LOGO_COLOR as H, Shell as _, ANSI_ASCII_LOGO as b } from "../main.js";
|
|
3
|
+
import { Theme as c } from "@prozilla-os/skins";
|
|
4
|
+
const G = new y().setManual({
|
|
5
|
+
purpose: "Fetch system information"
|
|
6
|
+
}).setExecute(async function(F, { username: p, hostname: u, app: O, systemManager: d, settingsManager: A, stdout: M }) {
|
|
7
|
+
const s = b.split(`
|
|
8
|
+
`), N = p.length + u.length + 1, r = (await A.getSettings(E.THEME).get("theme")).value;
|
|
9
|
+
let w = c[c.Dark];
|
|
10
|
+
r != null && !isNaN(parseInt(r)) && (w = c[parseInt(r)]);
|
|
11
|
+
const a = navigator.userAgent;
|
|
12
|
+
let o;
|
|
13
|
+
a.match(/Firefox\//) ? o = "Mozilla Firefox" : a.match(/Edg\//) ? o = "Microsoft Edge" : a.match(/Chrome\//) ? o = "Google Chrome" : a.match(/Safari\//) ? o = "Apple Safari" : o = "Unknown";
|
|
14
|
+
const t = (e, i) => n.fg.cyan + e.toUpperCase() + n.reset + ": " + i, x = [
|
|
15
|
+
`${n.fg.cyan + p + n.reset}@${n.fg.cyan + u + n.reset}`,
|
|
16
|
+
"-".repeat(N),
|
|
17
|
+
t("os", d.systemName),
|
|
18
|
+
t("uptime", d.getUptime(2)),
|
|
19
|
+
t("resolution", window.innerWidth + "x" + window.innerHeight),
|
|
20
|
+
t("theme", w),
|
|
21
|
+
t("icons", "Font Awesome"),
|
|
22
|
+
t("terminal", O?.name ?? "Unknown"),
|
|
23
|
+
t("browser", o),
|
|
24
|
+
t("platform", navigator.platform),
|
|
25
|
+
t("language", navigator.language),
|
|
26
|
+
"",
|
|
27
|
+
Object.values(n.fg).map((e) => e + "███").join("") + n.reset
|
|
28
|
+
], l = s.length, m = x.length, g = Math.max(l, m), L = Math.floor((g - l) / 2), v = Math.floor((g - m) / 2), S = Math.max(...s.map((e) => e.length)), I = [];
|
|
29
|
+
for (let e = 0; e < g; e++) {
|
|
30
|
+
let i = "";
|
|
31
|
+
const h = e - L;
|
|
32
|
+
if (h >= 0 && h < l) {
|
|
33
|
+
const C = s[h];
|
|
34
|
+
i += `${H + C + n.reset}${" ".repeat(S - C.length + 2)}`;
|
|
35
|
+
} else
|
|
36
|
+
i += " ".repeat(S + 2);
|
|
37
|
+
const f = e - v;
|
|
38
|
+
f >= 0 && f < m && (i += x[f]), I.push(i);
|
|
39
|
+
}
|
|
40
|
+
await _.printLn(M, I.join(`
|
|
41
|
+
`));
|
|
42
|
+
});
|
|
43
|
+
export {
|
|
44
|
+
G as neofetch
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=neofetch-Dyre2Ik0.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"neofetch-Dyre2Ik0.js","sources":["../../src/features/shell/commands/neofetch.ts"],"sourcesContent":["import { ANSI } from \"@prozilla-os/shared\";\nimport { ANSI_ASCII_LOGO, ANSI_LOGO_COLOR } from \"../../../constants/shell.const\";\nimport { Command } from \"../command\";\nimport { Theme } from \"@prozilla-os/skins\";\nimport { Settings } from \"../../settings/settings\";\nimport { Shell } from \"../shell\";\n\nexport const neofetch = new Command()\n\t.setManual({\n\t\tpurpose: \"Fetch system information\",\n\t})\n\t.setExecute(async function(_arguments, { username, hostname, app, systemManager, settingsManager, stdout }) {\n\t\tconst leftColumn = ANSI_ASCII_LOGO.split(\"\\n\");\n\t\tconst rightColumnWidth = username.length + hostname.length + 1;\n\n\t\tconst themeSetting = await settingsManager.getSettings(Settings.THEME).get(\"theme\");\n\t\tconst themeIndex = themeSetting.value;\n\t\t\n\t\tlet theme = Theme[Theme.Dark];\n\t\tif (themeIndex != null && !isNaN(parseInt(themeIndex))) {\n\t\t\ttheme = Theme[parseInt(themeIndex)];\n\t\t}\n\n\t\tconst userAgent = navigator.userAgent;\n\n\t\t// Check for the browser name using regular expressions\n\t\tlet browserName;\n\t\tif (userAgent.match(/Firefox\\//)) {\n\t\t\tbrowserName = \"Mozilla Firefox\";\n\t\t} else if (userAgent.match(/Edg\\//)) {\n\t\t\tbrowserName = \"Microsoft Edge\";\n\t\t} else if (userAgent.match(/Chrome\\//)) {\n\t\t\tbrowserName = \"Google Chrome\";\n\t\t} else if (userAgent.match(/Safari\\//)) {\n\t\t\tbrowserName = \"Apple Safari\";\n\t\t} else {\n\t\t\tbrowserName = \"Unknown\";\n\t\t}\n\n\t\tconst formatLine = (label: string, text: string) => ANSI.fg.cyan + label.toUpperCase() + ANSI.reset + \": \" + text;\n\n\t\tconst rightColumn = [\n\t\t\t`${ANSI.fg.cyan + username + ANSI.reset}@${ANSI.fg.cyan + hostname + ANSI.reset}`,\n\t\t\t\"-\".repeat(rightColumnWidth),\n\t\t\tformatLine(\"os\", systemManager.systemName),\n\t\t\tformatLine(\"uptime\", systemManager.getUptime(2)),\n\t\t\tformatLine(\"resolution\", window.innerWidth + \"x\" + window.innerHeight),\n\t\t\tformatLine(\"theme\", theme),\n\t\t\tformatLine(\"icons\", \"Font Awesome\"),\n\t\t\tformatLine(\"terminal\", app?.name ?? \"Unknown\"),\n\t\t\tformatLine(\"browser\", browserName),\n\t\t\tformatLine(\"platform\", navigator.platform),\n\t\t\tformatLine(\"language\", navigator.language),\n\t\t\t\"\",\n\t\t\tObject.values(ANSI.fg).map((colorCode) => colorCode + \"███\").join(\"\") + ANSI.reset,\n\t\t];\n\n\t\tconst leftHeight = leftColumn.length;\n\t\tconst rightHeight = rightColumn.length;\n\t\tconst maxHeight = Math.max(leftHeight, rightHeight);\n\n\t\tconst leftOffset = Math.floor((maxHeight - leftHeight) / 2);\n\t\tconst rightOffset = Math.floor((maxHeight - rightHeight) / 2);\n\n\t\tconst logoWidth = Math.max(...leftColumn.map((line) => line.length));\n\n\t\tconst combined = [];\n\t\tfor (let i = 0; i < maxHeight; i++) {\n\t\t\tlet line = \"\";\n\n\t\t\tconst leftIndex = i - leftOffset;\n\t\t\tif (leftIndex >= 0 && leftIndex < leftHeight) {\n\t\t\t\tconst logoLine = leftColumn[leftIndex];\n\t\t\t\tline += `${ANSI_LOGO_COLOR + logoLine + ANSI.reset}${\" \".repeat(logoWidth - logoLine.length + 2)}`;\n\t\t\t} else {\n\t\t\t\tline += \" \".repeat(logoWidth + 2);\n\t\t\t}\n\n\t\t\tconst rightIndex = i - rightOffset;\n\t\t\tif (rightIndex >= 0 && rightIndex < rightHeight) {\n\t\t\t\tline += rightColumn[rightIndex];\n\t\t\t}\n\n\t\t\tcombined.push(line);\n\t\t}\n\n\t\tawait Shell.printLn(stdout, combined.join(\"\\n\"));\n\t});"],"names":["neofetch","Command","_arguments","username","hostname","app","systemManager","settingsManager","stdout","leftColumn","ANSI_ASCII_LOGO","rightColumnWidth","themeIndex","Settings","theme","Theme","userAgent","browserName","formatLine","label","text","ANSI","rightColumn","colorCode","leftHeight","rightHeight","maxHeight","leftOffset","rightOffset","logoWidth","line","combined","i","leftIndex","logoLine","ANSI_LOGO_COLOR","rightIndex","Shell"],"mappings":";;;AAOO,MAAMA,IAAW,IAAIC,EAAA,EAC1B,UAAU;AAAA,EACV,SAAS;AACV,CAAC,EACA,WAAW,eAAeC,GAAY,EAAE,UAAAC,GAAU,UAAAC,GAAU,KAAAC,GAAK,eAAAC,GAAe,iBAAAC,GAAiB,QAAAC,KAAU;AAC3G,QAAMC,IAAaC,EAAgB,MAAM;AAAA,CAAI,GACvCC,IAAmBR,EAAS,SAASC,EAAS,SAAS,GAGvDQ,KADe,MAAML,EAAgB,YAAYM,EAAS,KAAK,EAAE,IAAI,OAAO,GAClD;AAEhC,MAAIC,IAAQC,EAAMA,EAAM,IAAI;AAC5B,EAAIH,KAAc,QAAQ,CAAC,MAAM,SAASA,CAAU,CAAC,MACpDE,I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,MAASA,EAAK,MAAM,CAAC,GAE7DC,IAAW,CAAA;AACjB,WAASC,IAAI,GAAGA,IAAIN,GAAWM,KAAK;AACnC,QAAIF,IAAO;AAEX,UAAMG,IAAYD,IAAIL;AACtB,QAAIM,KAAa,KAAKA,IAAYT,GAAY;AAC7C,YAAMU,IAAWzB,EAAWwB,CAAS;AACrC,MAAAH,KAAQ,GAAGK,IAAkBD,IAAWb,EAAK,KAAK,GAAG,IAAI,OAAOQ,IAAYK,EAAS,SAAS,CAAC,CAAC;AAAA,IACjG;AACC,MAAAJ,KAAQ,IAAI,OAAOD,IAAY,CAAC;AAGjC,UAAMO,IAAaJ,IAAIJ;AACvB,IAAIQ,KAAc,KAAKA,IAAaX,MACnCK,KAAQR,EAAYc,CAAU,IAG/BL,EAAS,KAAKD,CAAI;AAAA,EACnB;AAEA,QAAMO,EAAM,QAAQ7B,GAAQuB,EAAS,KAAK;AAAA,CAAI,CAAC;AAChD,CAAC;"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { parseOptionalInteger as x, parseOptionalFloat as w, ANSI as m, Vector2 as p, randomRange as y, randomFromArray as E } from "@prozilla-os/shared";
|
|
2
|
+
import { Command as _, Shell as P } from "../main.js";
|
|
3
|
+
const T = 60 / 40, A = 10, D = 20, M = 15e-4, I = [
|
|
4
|
+
new p(1, 0),
|
|
5
|
+
new p(-1, 0),
|
|
6
|
+
new p(0, 1),
|
|
7
|
+
new p(0, -1)
|
|
8
|
+
], S = {
|
|
9
|
+
"1,0|1,0": "━",
|
|
10
|
+
"-1,0|-1,0": "━",
|
|
11
|
+
"0,1|0,1": "┃",
|
|
12
|
+
"0,-1|0,-1": "┃",
|
|
13
|
+
"0,1|1,0": "┏",
|
|
14
|
+
"0,1|-1,0": "┓",
|
|
15
|
+
"0,-1|1,0": "┗",
|
|
16
|
+
"0,-1|-1,0": "┛",
|
|
17
|
+
"1,0|0,1": "┛",
|
|
18
|
+
"1,0|0,-1": "┓",
|
|
19
|
+
"-1,0|0,1": "┗",
|
|
20
|
+
"-1,0|0,-1": "┏"
|
|
21
|
+
};
|
|
22
|
+
function $(i, t, u, g) {
|
|
23
|
+
const s = [m.fg.blue, m.fg.cyan, m.fg.green, m.fg.magenta, m.fg.red, m.fg.yellow], r = new p(y(0, i.x - 1), y(0, i.y - 1)).round(), a = E(I), l = u * 1e3 / t, n = g * 1e3 / t;
|
|
24
|
+
return {
|
|
25
|
+
position: r,
|
|
26
|
+
direction: a,
|
|
27
|
+
color: E(s),
|
|
28
|
+
dead: !1,
|
|
29
|
+
segments: [],
|
|
30
|
+
deathTimer: y(l, n),
|
|
31
|
+
removing: !1
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function O(i, t, u, g, s, r) {
|
|
35
|
+
const a = /* @__PURE__ */ new Set();
|
|
36
|
+
i.forEach((n) => n.segments.forEach((o) => {
|
|
37
|
+
a.add(`${o.position.x},${o.position.y}`);
|
|
38
|
+
}));
|
|
39
|
+
for (let n = i.length - 1; n >= 0; n--) {
|
|
40
|
+
const o = i[n];
|
|
41
|
+
if (o.dead)
|
|
42
|
+
o.removing ? (o.segments.shift(), o.segments.length === 0 && i.splice(n, 1)) : (o.deathTimer--, o.deathTimer <= 0 && (o.removing = !0));
|
|
43
|
+
else {
|
|
44
|
+
const c = o.direction;
|
|
45
|
+
if (Math.random() < 0.2) {
|
|
46
|
+
const d = E(I);
|
|
47
|
+
d.x === -c.x && d.y === -c.y || (o.direction = d);
|
|
48
|
+
}
|
|
49
|
+
const f = `${c.x},${c.y}|${o.direction.x},${o.direction.y}`, h = S[f] ?? (o.direction.x !== 0 ? "━" : "┃");
|
|
50
|
+
o.segments.push({ position: new p(o.position.x, o.position.y), char: h }), a.add(`${o.position.x},${o.position.y}`);
|
|
51
|
+
const e = o.position.add(o.direction);
|
|
52
|
+
e.x < 0 || e.x >= t.x || e.y < 0 || e.y >= t.y || a.has(`${e.x},${e.y}`) ? o.dead = !0 : o.position = e;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const l = Math.max(1, Math.floor(t.x * t.y * g));
|
|
56
|
+
i.filter((n) => !n.dead).length < l && i.push($(t, u, s, r));
|
|
57
|
+
}
|
|
58
|
+
const v = new _().setManual({
|
|
59
|
+
purpose: "Displays animated colorful pipes",
|
|
60
|
+
usage: "pipes [-s <speed>] [-r <float>] [-m <int>] [-M <int>]",
|
|
61
|
+
options: {
|
|
62
|
+
"-s speed": `Speed of the animation (Defaults to ${T})`,
|
|
63
|
+
"-r float": `Spawn rate of pipes (Defaults to ${M})`,
|
|
64
|
+
"-m int": `Minimum life time in seconds (Defaults to ${A})`,
|
|
65
|
+
"-M int": `Maximum life time in seconds (Defaults to ${D})`
|
|
66
|
+
}
|
|
67
|
+
}).addOption({ short: "s", long: "speed", isInput: !0 }).addOption({ short: "r", long: "rate", isInput: !0 }).addOption({ short: "m", long: "min", isInput: !0 }).addOption({ short: "M", long: "max", isInput: !0 }).setExecute(function(i, { size: t, stdin: u, stdout: g, inputs: s }) {
|
|
68
|
+
const r = 60 / x(s.s, T), a = w(s.r, M), l = x(s.m, A), n = x(s.M, D), o = [$(t, r, l, n)];
|
|
69
|
+
return P.animate({
|
|
70
|
+
stdin: u,
|
|
71
|
+
stdout: g,
|
|
72
|
+
delay: r,
|
|
73
|
+
render: () => {
|
|
74
|
+
O(o, t, r, a, l, n);
|
|
75
|
+
const c = Array.from({ length: t.y }, () => Array(t.x).fill(" "));
|
|
76
|
+
return o.forEach((f) => {
|
|
77
|
+
f.segments.forEach((h) => {
|
|
78
|
+
const { x: e, y: d } = h.position;
|
|
79
|
+
d >= 0 && d < t.y && e >= 0 && e < t.x && (c[d][e] = f.color + h.char + m.reset);
|
|
80
|
+
});
|
|
81
|
+
}), c.map((f) => f.join("")).reverse().join(`
|
|
82
|
+
`);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
export {
|
|
87
|
+
v as pipes
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=pipes-CQ-pK6Kv.js.map
|