@prozilla-os/cli 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Sieben De Beule
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,98 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
+ <br />
3
+ <p>
4
+ <a href="https://os.prozilla.dev/terminal"><img src="https://os.prozilla.dev/assets/posh.svg" height="200" alt="Posh" /></a>
5
+ </p>
6
+ <p>
7
+ <a href="https://github.com/prozilla-os/ProzillaOS/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/prozilla-os/ProzillaOS?style=flat-square&color=FF4D5B&label=License"></a>
8
+ <a href="https://github.com/prozilla-os/ProzillaOS"><img alt="Stars" src="https://img.shields.io/github/stars/prozilla-os/ProzillaOS?style=flat-square&color=FED24C&label=%E2%AD%90"></a>
9
+ <a href="https://github.com/prozilla-os/ProzillaOS"><img alt="Forks" src="https://img.shields.io/github/forks/prozilla-os/ProzillaOS?style=flat-square&color=4D9CFF&label=Forks&logo=github"></a>
10
+ <a href="https://www.npmjs.com/package/prozilla-os"><img alt="NPM Version" src="https://img.shields.io/npm/v/prozilla-os?logo=npm&style=flat-square&label=prozilla-os&color=FF4D5B"></a>
11
+ </p>
12
+ </div>
2
13
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
14
+ ## About
15
+
16
+ `@prozilla-os/cli` is a NodeJS wrapper for Posh (ProzillaOS shell), a Bash-like shell emulator.
17
+
18
+ ## Installation
19
+
20
+ ```sh
21
+ npm install -g @prozilla-os/cli
22
+ yarn global add @prozilla-os/cli
23
+ pnpm add -g @prozilla-os/cli
24
+ ```
25
+
26
+ ## Use Posh as your default shell
27
+
28
+ 1. Verify your installation:
29
+
30
+ ```sh
31
+ which posh
32
+ ```
33
+
34
+ 2. Add Posh to your authorized shell list (`/etc/shells`).
35
+ 3. Make it your default shell:
36
+
37
+ ```sh
38
+ chsh -s $(which posh)
39
+ ```
40
+
41
+ 4. Restart your computer for the changes to take effect.
42
+ 5. Check your current shell:
43
+
44
+ ```sh
45
+ echo $SHELL
46
+ ```
47
+
48
+ This should print `posh`.
49
+
50
+ ## Usage
51
+
52
+ ### Command line interface
53
+
54
+ #### Interactive mode
55
+
56
+ ```sh
57
+ posh
58
+ ```
59
+
60
+ #### Single command
61
+
62
+ ```sh
63
+ posh -c help
64
+ ```
65
+
66
+ ### Shell script
67
+
68
+ ```sh
69
+ #!/usr/bin/env posh
70
+
71
+ echo "Hello, world!"
72
+ ```
73
+
74
+ ### Node module
75
+
76
+ ```ts
77
+ import { HeadlessShell } from "@prozilla-os/cli";
78
+
79
+ const shell = new HeadlessShell();
80
+ const exitCode = await shell.start("help");
81
+ process.exit(exitCode);
82
+ ```
83
+
84
+ ## Links
85
+
86
+ - [Demo][demo]
87
+ - [Docs][docs]
88
+ - [GitHub][github]
89
+ - [npm][npm]
90
+ - [Discord][discord]
91
+ - [Ko-fi][ko-fi]
92
+
93
+ [demo]: https://os.prozilla.dev/terminal
94
+ [docs]: https://os.prozilla.dev/docs/reference/cli
95
+ [github]: https://github.com/prozilla-os/ProzillaOS/tree/main/packages/cli
96
+ [npm]: https://www.npmjs.com/package/@prozilla-os/cli
97
+ [discord]: https://discord.gg/JwbyQP4tdz
98
+ [ko-fi]: https://ko-fi.com/prozilla
@@ -0,0 +1,211 @@
1
+ import { Shell as R, SettingsManager as x, Stream as d, EXIT_CODE as m, HistoryFlags as S, SystemManager as k, VirtualDriveConfig as v, WindowsConfig as D, TrackingConfig as V, TaskbarConfig as L, ModalsConfig as Y, MiscConfig as I, DesktopConfig as K, AppsConfig as B, VirtualRoot as P, Vector2 as _ } from "@prozilla-os/core";
2
+ import { ANSI as t, BASE_URL as z } from "@prozilla-os/shared";
3
+ import { emitKeypressEvents as N } from "node:readline";
4
+ import { subscribe as F } from "valtio/vanilla";
5
+ import { XMLSerializer as H, DOMParser as U } from "@xmldom/xmldom";
6
+ const T = t.input.carriageReturn + t.screen.clearLine, y = t.screen.clear + t.screen.home, O = {
7
+ return: "Enter",
8
+ tab: "Tab",
9
+ backspace: "Backspace",
10
+ delete: "Delete",
11
+ up: "ArrowUp",
12
+ down: "ArrowDown",
13
+ left: "ArrowLeft",
14
+ right: "ArrowRight",
15
+ escape: "Escape"
16
+ };
17
+ class W extends k {
18
+ constructor(e = {}) {
19
+ super({
20
+ systemName: e.systemName ?? null,
21
+ tagLine: e.tagLine ?? null,
22
+ appsConfig: e.appsConfig ?? new B(),
23
+ desktopConfig: e.desktopConfig ?? new K(),
24
+ miscConfig: e.miscConfig ?? new I(),
25
+ modalsConfig: e.modalsConfig ?? new Y(),
26
+ taskbarConfig: e.taskbarConfig ?? new L(),
27
+ trackingConfig: e.trackingConfig ?? new V(),
28
+ windowsConfig: e.windowsConfig ?? new D(),
29
+ virtualDriveConfig: e.virtualDriveConfig ?? new v({
30
+ defaultData: {
31
+ includeAppsFolder: !0,
32
+ includeDesktopFolder: !0,
33
+ includeDocumentsFolder: !0,
34
+ includePicturesFolder: !0,
35
+ includeSourceTree: !1
36
+ },
37
+ saveData: !1
38
+ })
39
+ });
40
+ }
41
+ }
42
+ class X extends P {
43
+ constructor(e) {
44
+ super(e), this.init();
45
+ }
46
+ readSource(e) {
47
+ return e.startsWith("/") && (e = z + e.slice(1)), super.readSource(e);
48
+ }
49
+ }
50
+ function A() {
51
+ return new _(process.stdout.columns || 0, process.stdout.rows || 0);
52
+ }
53
+ class Z extends R {
54
+ #s = !1;
55
+ #t = !0;
56
+ #e = () => {
57
+ };
58
+ constructor() {
59
+ Object.assign(globalThis, { DOMParser: U, XMLSerializer: H });
60
+ const e = new W(), r = new X(e), c = new x(r, !1);
61
+ super({
62
+ virtualRoot: r,
63
+ systemManager: e,
64
+ settingsManager: c,
65
+ exit: () => {
66
+ this.state.isUsingAltScreen && process.stdout.write(t.screen.exitAltBuffer), this.setTTYRawMode(!1), this.isInteractive && process.stdout.write(T), this.#e();
67
+ },
68
+ sizeRef: {
69
+ current: A()
70
+ }
71
+ }), process.on("exit", () => {
72
+ this.isCursorVisible || process.stdout.write(t.cursor.show);
73
+ }), process.stdout.on("resize", () => {
74
+ const n = A();
75
+ this.config.sizeRef.current.set(n.x, n.y);
76
+ });
77
+ }
78
+ /**
79
+ * Executes the given command string or starts interactive mode if the command string is empty.
80
+ * @param input - The input string.
81
+ * @returns The exit code.
82
+ */
83
+ async start(e) {
84
+ return e !== void 0 && e.length !== 0 ? await this.startCommand(e) : await this.startInteractiveMode();
85
+ }
86
+ /**
87
+ * Executes the given command string.
88
+ * @param input - The input string.
89
+ * @returns The exit code.
90
+ */
91
+ async startCommand(e) {
92
+ this.#e = () => {
93
+ }, this.#s = !1;
94
+ const r = new d(), c = new d(), n = new d();
95
+ c.on(d.DATA_EVENT, (s) => {
96
+ s.includes(t.screen.enterAltBuffer) && this.setCursorVisible(!1), process.stdout.write(s), s.includes(t.screen.exitAltBuffer) && this.setCursorVisible(!0);
97
+ }), n.on(d.DATA_EVENT, (s) => {
98
+ process.stderr.write(s);
99
+ });
100
+ const l = process.stdin.isTTY;
101
+ this.setTTYRawMode(!0);
102
+ const u = (s) => {
103
+ const a = s.toString();
104
+ l && a === t.input.ctrlC ? this.interrupt() : l && a === t.input.ctrlD ? r.end() : r.write(a);
105
+ }, o = () => r.end();
106
+ process.stdin.on("data", u), process.stdin.on("end", o);
107
+ const i = await this.interpreter.execute(e, {
108
+ stdin: r,
109
+ stdout: c,
110
+ stderr: n
111
+ });
112
+ return this.setTTYRawMode(!1), process.stdin.pause(), new Promise((s) => {
113
+ process.stdout.write("", () => {
114
+ process.stdin.off("data", u), process.stdin.off("end", o), s(i);
115
+ });
116
+ });
117
+ }
118
+ /**
119
+ * Starts interactive mode.
120
+ * @returns The exit code.
121
+ */
122
+ async startInteractiveMode() {
123
+ if (this.#e = () => {
124
+ }, this.#s = !0, !process.stdin.isTTY)
125
+ return process.stderr.write(`Interactive mode requires an interactive terminal.
126
+ `), m.generalError;
127
+ N(process.stdin), process.stdin.setRawMode(!0);
128
+ let e = 0, r = !1;
129
+ const c = () => {
130
+ const { history: o, isUsingAltScreen: i, isRawMode: s, cursorPosition: a, stream: w, ttyBuffer: h, prompt: E, line: b } = this.state, g = s || !i && w == null;
131
+ if (g || this.setCursorVisible(!1), i !== r && (process.stdout.write(i ? t.screen.enterAltBuffer : t.screen.exitAltBuffer), r = i), i)
132
+ process.stdout.write(y + (h ?? "")), s && process.stdout.write(t.cursor.position(a.y + 1, a.x + 1));
133
+ else {
134
+ const C = o.slice(e);
135
+ e += C.length, process.stdout.write(T);
136
+ for (const f of C)
137
+ f.flags & S.Clear ? process.stdout.write(y) : f.displayText != null && process.stdout.write(f.displayText + `
138
+ `);
139
+ const M = w != null ? "" : E + b;
140
+ process.stdout.write((h ?? "") + M);
141
+ }
142
+ g && this.setCursorVisible(!0);
143
+ }, n = () => {
144
+ this.commitLine(), c(), this.kill();
145
+ }, l = (o, i) => {
146
+ this.handleKeypress(o, i, n);
147
+ };
148
+ process.stdin.on("keypress", l);
149
+ const u = F(this.state, c);
150
+ return c(), new Promise((o) => {
151
+ this.#e = () => {
152
+ u(), process.stdin.off("keypress", l), process.stdin.pause(), o(m.success);
153
+ };
154
+ });
155
+ }
156
+ handleKeypress(e, r, c) {
157
+ const { name: n, ctrl: l = !1, meta: u = !1, shift: o = !1 } = r, i = l || u, s = i ? n ?? "" : O[n ?? ""] ?? e ?? "";
158
+ if (s.length) {
159
+ if (this.state.stream == null)
160
+ if (i) {
161
+ if ((s === "c" || s === "d") && !o)
162
+ return c();
163
+ } else {
164
+ if (n === "backspace") {
165
+ this.setLine((a) => a.slice(0, -1));
166
+ return;
167
+ }
168
+ if (e?.length === 1 && s === e) {
169
+ this.setLine((a) => a + e);
170
+ return;
171
+ }
172
+ }
173
+ this.handleKeyDown({
174
+ key: s,
175
+ ctrlKey: l,
176
+ metaKey: u,
177
+ shiftKey: o,
178
+ preventDefault: () => {
179
+ }
180
+ });
181
+ }
182
+ }
183
+ /**
184
+ * Checks if this shell is running in interactive mode.
185
+ * @returns `true` if this shell is running in interactive mode.
186
+ */
187
+ get isInteractive() {
188
+ return this.#s;
189
+ }
190
+ /**
191
+ * Checks if the cursor is currently visible.
192
+ * @returns `true` if the cursor is currently visible.
193
+ */
194
+ get isCursorVisible() {
195
+ return this.#t;
196
+ }
197
+ /**
198
+ * Sets the visible state of the cursor.
199
+ * @param visible - The state to set.
200
+ */
201
+ setCursorVisible(e) {
202
+ !process.stdout.isTTY || e === this.isCursorVisible || (process.stdout.write(e ? t.cursor.show : t.cursor.hide), this.#t = e);
203
+ }
204
+ setTTYRawMode(e) {
205
+ process.stdin.isTTY && process.stdin.setRawMode(e);
206
+ }
207
+ }
208
+ export {
209
+ Z as H
210
+ };
211
+ //# sourceMappingURL=shell-CBn2l1Ly.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-CBn2l1Ly.js","sources":["../../src/features/shell.ts"],"sourcesContent":["import { AppsConfig, DesktopConfig, EXIT_CODE, HistoryFlags, MiscConfig, ModalsConfig, SettingsManager, Shell, Stream, SystemManager, SystemManagerParams, TaskbarConfig, TrackingConfig, Vector2, VirtualDriveConfig, VirtualRoot, WindowsConfig } from \"@prozilla-os/core\";\nimport { ANSI, BASE_URL } from \"@prozilla-os/shared\";\nimport { emitKeypressEvents, Key } from \"node:readline\";\nimport { subscribe } from \"valtio/vanilla\";\nimport { DOMParser, XMLSerializer } from \"@xmldom/xmldom\";\nimport { readFile } from \"node:fs/promises\";\n\nconst CLEAR_ROW = ANSI.input.carriageReturn + ANSI.screen.clearLine;\nconst CLEAR_SCREEN = ANSI.screen.clear + ANSI.screen.home;\n\nconst KEY_MAP: Partial<Record<string, string>> = {\n\treturn: \"Enter\",\n\ttab: \"Tab\",\n\tbackspace: \"Backspace\",\n\tdelete: \"Delete\",\n\tup: \"ArrowUp\",\n\tdown: \"ArrowDown\",\n\tleft: \"ArrowLeft\",\n\tright: \"ArrowRight\",\n\tescape: \"Escape\",\n};\n\nclass HeadlessSystemManager extends SystemManager {\n\n\tconstructor(params: Partial<SystemManagerParams> = {}) {\n\t\tsuper({\n\t\t\tsystemName: params.systemName ?? null,\n\t\t\ttagLine: params.tagLine ?? null,\n\t\t\tappsConfig: params.appsConfig ?? new AppsConfig(),\n\t\t\tdesktopConfig: params.desktopConfig ?? new DesktopConfig(),\n\t\t\tmiscConfig: params.miscConfig ?? new MiscConfig(),\n\t\t\tmodalsConfig: params.modalsConfig ?? new ModalsConfig(),\n\t\t\ttaskbarConfig: params.taskbarConfig ?? new TaskbarConfig(),\n\t\t\ttrackingConfig: params.trackingConfig ?? new TrackingConfig(),\n\t\t\twindowsConfig: params.windowsConfig ?? new WindowsConfig(),\n\t\t\tvirtualDriveConfig: params.virtualDriveConfig ?? new VirtualDriveConfig({\n\t\t\t\tdefaultData: {\n\t\t\t\t\tincludeAppsFolder: true,\n\t\t\t\t\tincludeDesktopFolder: true,\n\t\t\t\t\tincludeDocumentsFolder: true,\n\t\t\t\t\tincludePicturesFolder: true,\n\t\t\t\t\tincludeSourceTree: false,\n\t\t\t\t},\n\t\t\t\tsaveData: false,\n\t\t\t}),\n\t\t});\n\t}\n\n}\n\nclass HeadlessVirtualRoot extends VirtualRoot {\n\n\tconstructor(systemManager: SystemManager) {\n\t\tsuper(systemManager);\n\t\tthis.init();\n\t}\n\n\toverride readSource(source: string): Promise<string | null> {\n\t\tif (source.startsWith(\"/\")) {\n\t\t\tsource = BASE_URL + source.slice(1);\n\t\t}\n\t\treturn super.readSource(source);\n\t}\n\n}\n\nfunction getTerminalSize() {\n\treturn new Vector2(process.stdout.columns || 0, process.stdout.rows || 0);\n}\n\n/**\n * A headless Posh shell.\n * @example\n * const shell = new HeadlessShell();\n * const input = process.argv.slice(2).map(Shell.quote).join(\" \");\n *\n * const exitCode = await shell.start(input);\n * process.exit(exitCode);\n */\nexport class HeadlessShell extends Shell {\n\n\t#isInteractive = false;\n\t#isCursorVisible = true;\n\t#onExit = () => {};\n\n\tconstructor() {\n\t\tObject.assign(globalThis, { DOMParser, XMLSerializer });\n\t\t\n\t\tconst systemManager = new HeadlessSystemManager();\n\t\tconst virtualRoot = new HeadlessVirtualRoot(systemManager);\n\t\tconst settingsManager = new SettingsManager(virtualRoot, false);\n\t\t\n\t\tsuper({\n\t\t\tvirtualRoot,\n\t\t\tsystemManager,\n\t\t\tsettingsManager,\n\t\t\texit: () => {\n\t\t\t\tif (this.state.isUsingAltScreen)\n\t\t\t\t\tprocess.stdout.write(ANSI.screen.exitAltBuffer);\n\t\t\t\tthis.setTTYRawMode(false);\n\t\t\t\tif (this.isInteractive)\n\t\t\t\t\tprocess.stdout.write(CLEAR_ROW);\n\t\t\t\tthis.#onExit();\n\t\t\t},\n\t\t\tsizeRef: {\n\t\t\t\tcurrent: getTerminalSize(),\n\t\t\t},\n\t\t});\n\n\t\tprocess.on(\"exit\", () => {\n\t\t\tif (!this.isCursorVisible)\n\t\t\t\tprocess.stdout.write(ANSI.cursor.show);\n\t\t});\n\t\t\n\t\tprocess.stdout.on(\"resize\", () => {\n\t\t\tconst size = getTerminalSize();\n\t\t\tthis.config.sizeRef.current.set(size.x, size.y);\n\t\t});\n\t}\n\n\t/**\n\t * Executes the given command string or starts interactive mode if the command string is empty.\n\t * @param input - The input string.\n\t * @returns The exit code.\n\t */\n\tpublic async start(input?: string): Promise<number> {\n\t\treturn input !== undefined && input.length !== 0 ? await this.startCommand(input) : await this.startInteractiveMode();\n\t}\n\n\t/**\n\t * Executes the given command string.\n\t * @param input - The input string.\n\t * @returns The exit code.\n\t */\n\tpublic async startCommand(input: string): Promise<number> {\n\t\tthis.#onExit = () => {};\n\t\tthis.#isInteractive = false;\n\n\t\tconst stdin = new Stream();\n\t\tconst stdout = new Stream();\n\t\tconst stderr = new Stream();\n\n\t\tstdout.on(Stream.DATA_EVENT, (data: string) => {\n\t\t\tif (data.includes(ANSI.screen.enterAltBuffer))\n\t\t\t\tthis.setCursorVisible(false);\n\n\t\t\tprocess.stdout.write(data);\n\n\t\t\tif (data.includes(ANSI.screen.exitAltBuffer))\n\t\t\t\tthis.setCursorVisible(true);\n\t\t});\n\t\n\t\tstderr.on(Stream.DATA_EVENT, (data: string) => {\n\t\t\tprocess.stderr.write(data);\n\t\t});\n\n\t\tconst isTTY = process.stdin.isTTY;\n\t\tthis.setTTYRawMode(true);\n\n\t\tconst handleInput = (chunk: Buffer) => {\n\t\t\tconst text = chunk.toString();\n\n\t\t\tif (isTTY && text === ANSI.input.ctrlC) {\n\t\t\t\tthis.interrupt();\n\t\t\t} else if (isTTY && text === ANSI.input.ctrlD) {\n\t\t\t\tstdin.end();\n\t\t\t} else {\n\t\t\t\tvoid stdin.write(text);\n\t\t\t}\n\t\t};\n\n\t\tconst handleEnd = () => stdin.end();\n\n\t\tprocess.stdin.on(\"data\", handleInput);\n\t\tprocess.stdin.on(\"end\", handleEnd);\n\n\t\tconst exitCode = await this.interpreter.execute(input, {\n\t\t\tstdin,\n\t\t\tstdout,\n\t\t\tstderr,\n\t\t});\n\n\t\tthis.setTTYRawMode(false);\n\t\tprocess.stdin.pause();\n\n\t\treturn new Promise((resolve) => {\n\t\t\t// Clean up and exit\n\t\t\tprocess.stdout.write(\"\", () => {\n\t\t\t\tprocess.stdin.off(\"data\", handleInput);\n\t\t\t\tprocess.stdin.off(\"end\", handleEnd);\n\t\t\t\tresolve(exitCode);\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Starts interactive mode.\n\t * @returns The exit code.\n\t */\n\tpublic async startInteractiveMode(): Promise<number> {\n\t\tthis.#onExit = () => {};\n\t\tthis.#isInteractive = true;\n\n\t\tif (!process.stdin.isTTY) {\n\t\t\tprocess.stderr.write(\"Interactive mode requires an interactive terminal.\\n\");\n\t\t\treturn EXIT_CODE.generalError;\n\t\t}\n\n\t\temitKeypressEvents(process.stdin);\n\t\tprocess.stdin.setRawMode(true);\n\n\t\tlet writtenEntries = 0;\n\t\tlet wasUsingAltScreen = false;\n\n\t\tconst render = () => {\n\t\t\tconst { history, isUsingAltScreen, isRawMode, cursorPosition, stream, ttyBuffer, prompt, line } = this.state;\n\n\t\t\tconst showCursor = isRawMode || !isUsingAltScreen && stream == null;\n\n\t\t\tif (!showCursor)\n\t\t\t\tthis.setCursorVisible(false);\n\n\t\t\tif (isUsingAltScreen !== wasUsingAltScreen) {\n\t\t\t\tprocess.stdout.write(isUsingAltScreen ? ANSI.screen.enterAltBuffer : ANSI.screen.exitAltBuffer);\n\t\t\t\twasUsingAltScreen = isUsingAltScreen;\n\t\t\t}\n\n\t\t\tif (isUsingAltScreen) {\n\t\t\t\tprocess.stdout.write(CLEAR_SCREEN + (ttyBuffer ?? \"\"));\n\n\t\t\t\tif (isRawMode)\n\t\t\t\t\tprocess.stdout.write(ANSI.cursor.position(cursorPosition.y + 1, cursorPosition.x + 1));\n\t\t\t} else {\n\t\t\t\tconst newEntries = history.slice(writtenEntries);\n\t\t\t\twrittenEntries += newEntries.length;\n\n\t\t\t\tprocess.stdout.write(CLEAR_ROW);\n\n\t\t\t\tfor (const entry of newEntries) {\n\t\t\t\t\tif (entry.flags & HistoryFlags.Clear) {\n\t\t\t\t\t\tprocess.stdout.write(CLEAR_SCREEN);\n\t\t\t\t\t} else if (entry.displayText != null) {\n\t\t\t\t\t\tprocess.stdout.write(entry.displayText + \"\\n\");\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst inputLine = stream != null ? \"\" : prompt + line;\n\t\t\t\tprocess.stdout.write((ttyBuffer ?? \"\") + inputLine);\n\t\t\t}\n\n\t\t\tif (showCursor)\n\t\t\t\tthis.setCursorVisible(true);\n\t\t};\n\n\t\tconst handleExit = () => {\n\t\t\tthis.commitLine();\n\t\t\trender();\n\t\t\tthis.kill();\n\t\t};\n\t\tconst handleKeypress = (input: string | undefined, keypress: Key) => {\n\t\t\tthis.handleKeypress(input, keypress, handleExit);\n\t\t};\n\t\tprocess.stdin.on(\"keypress\", handleKeypress);\n\n\t\tconst unsubscribe = subscribe(this.state, render);\n\t\trender();\n\n\t\treturn new Promise((resolve) => {\n\t\t\tthis.#onExit = () => {\n\t\t\t\tunsubscribe();\n\t\t\t\tprocess.stdin.off(\"keypress\", handleKeypress);\n\t\t\t\tprocess.stdin.pause();\n\t\t\t\tresolve(EXIT_CODE.success);\n\t\t\t};\n\t\t});\n\t}\n\n\tprivate handleKeypress(input: string | undefined, keypress: Key, onExit: () => void) {\n\t\tconst { name, ctrl = false, meta = false, shift = false } = keypress;\n\t\tconst isControlPressed = ctrl || meta;\n\t\n\t\tconst key = isControlPressed\n\t\t\t? name ?? \"\"\n\t\t\t: KEY_MAP[name ?? \"\"] ?? input ?? \"\";\n\t\n\t\tif (!key.length)\n\t\t\treturn;\n\t\n\t\tif (this.state.stream == null) {\n\t\t\tif (isControlPressed) {\n\t\t\t\tif ((key === \"c\" || key === \"d\") && !shift) {\n\t\t\t\t\treturn onExit();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (name === \"backspace\") {\n\t\t\t\t\tthis.setLine((line) => line.slice(0, -1));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\n\t\t\t\tif (input?.length === 1 && key === input) {\n\t\t\t\t\tthis.setLine((line) => line + input);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\n\t\tvoid this.handleKeyDown({\n\t\t\tkey,\n\t\t\tctrlKey: ctrl,\n\t\t\tmetaKey: meta,\n\t\t\tshiftKey: shift,\n\t\t\tpreventDefault: () => {},\n\t\t});\n\t}\n\n\t/**\n\t * Checks if this shell is running in interactive mode.\n\t * @returns `true` if this shell is running in interactive mode.\n\t */\n\tpublic get isInteractive() {\n\t\treturn this.#isInteractive;\n\t}\n\n\t/**\n\t * Checks if the cursor is currently visible.\n\t * @returns `true` if the cursor is currently visible.\n\t */\n\tpublic get isCursorVisible() {\n\t\treturn this.#isCursorVisible;\n\t}\n\n\t/**\n\t * Sets the visible state of the cursor.\n\t * @param visible - The state to set.\n\t */\n\tpublic setCursorVisible(visible: boolean) {\n\t\tif (!process.stdout.isTTY || visible === this.isCursorVisible)\n\t\t\treturn;\n\n\t\tprocess.stdout.write(visible ? ANSI.cursor.show : ANSI.cursor.hide);\n\t\tthis.#isCursorVisible = visible;\n\t}\n\n\tprivate setTTYRawMode(rawMode: boolean) {\n\t\tif (process.stdin.isTTY)\n\t\t\tprocess.stdin.setRawMode(rawMode);\n\t}\n}"],"names":["CLEAR_ROW","ANSI","CLEAR_SCREEN","KEY_MAP","HeadlessSystemManager","SystemManager","params","AppsConfig","DesktopConfig","MiscConfig","ModalsConfig","TaskbarConfig","TrackingConfig","WindowsConfig","VirtualDriveConfig","HeadlessVirtualRoot","VirtualRoot","systemManager","source","BASE_URL","getTerminalSize","Vector2","HeadlessShell","Shell","#isInteractive","#isCursorVisible","#onExit","DOMParser","XMLSerializer","virtualRoot","settingsManager","SettingsManager","size","input","stdin","Stream","stdout","stderr","data","isTTY","handleInput","chunk","text","handleEnd","exitCode","resolve","EXIT_CODE","emitKeypressEvents","writtenEntries","wasUsingAltScreen","render","history","isUsingAltScreen","isRawMode","cursorPosition","stream","ttyBuffer","prompt","line","showCursor","newEntries","entry","HistoryFlags","inputLine","handleExit","handleKeypress","keypress","unsubscribe","subscribe","onExit","name","ctrl","meta","shift","isControlPressed","key","visible","rawMode"],"mappings":";;;;;AAOA,MAAMA,IAAYC,EAAK,MAAM,iBAAiBA,EAAK,OAAO,WACpDC,IAAeD,EAAK,OAAO,QAAQA,EAAK,OAAO,MAE/CE,IAA2C;AAAA,EAChD,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AACT;AAEA,MAAMC,UAA8BC,EAAc;AAAA,EAEjD,YAAYC,IAAuC,IAAI;AACtD,UAAM;AAAA,MACL,YAAYA,EAAO,cAAc;AAAA,MACjC,SAASA,EAAO,WAAW;AAAA,MAC3B,YAAYA,EAAO,cAAc,IAAIC,EAAA;AAAA,MACrC,eAAeD,EAAO,iBAAiB,IAAIE,EAAA;AAAA,MAC3C,YAAYF,EAAO,cAAc,IAAIG,EAAA;AAAA,MACrC,cAAcH,EAAO,gBAAgB,IAAII,EAAA;AAAA,MACzC,eAAeJ,EAAO,iBAAiB,IAAIK,EAAA;AAAA,MAC3C,gBAAgBL,EAAO,kBAAkB,IAAIM,EAAA;AAAA,MAC7C,eAAeN,EAAO,iBAAiB,IAAIO,EAAA;AAAA,MAC3C,oBAAoBP,EAAO,sBAAsB,IAAIQ,EAAmB;AAAA,QACvE,aAAa;AAAA,UACZ,mBAAmB;AAAA,UACnB,sBAAsB;AAAA,UACtB,wBAAwB;AAAA,UACxB,uBAAuB;AAAA,UACvB,mBAAmB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AAAA,eAEF;AACN,cAAIC,MAAS,aAAa;AACzB,iBAAK,QAAQ,CAACZ,MAASA,EAAK,MAAM,GAAG,EAAE,CAAC;AACxC;AAAA,UACD;AAEA,cAAIzB,GAAO,WAAW,KAAK0C,MAAQ1C,GAAO;AACzC,iBAAK,QAAQ,CAACyB,MAASA,IAAOzB,CAAK;AACnC;AAAA,UACD;AAAA,QACD;AAGD,MAAK,KAAK,cAAc;AAAA,QACvB,KAAA0C;AAAA,QACA,SAASJ;AAAA,QACT,SAASC;AAAA,QACT,UAAUC;AAAA,QACV,gBAAgB,MAAM;AAAA,QAAC;AAAA,MAAA,CACvB;AAAA;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAW,gBAAgB;AAC1B,WAAO,KAAKjD;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAW,kBAAkB;AAC5B,WAAO,KAAKC;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,iBAAiBmD,GAAkB;AACzC,IAAI,CAAC,QAAQ,OAAO,SAASA,MAAY,KAAK,oBAG9C,QAAQ,OAAO,MAAMA,IAAU3E,EAAK,OAAO,OAAOA,EAAK,OAAO,IAAI,GAClE,KAAKwB,KAAmBmD;AAAA,EACzB;AAAA,EAEQ,cAAcC,GAAkB;AACvC,IAAI,QAAQ,MAAM,SACjB,QAAQ,MAAM,WAAWA,CAAO;AAAA,EAClC;AACD;"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { }
package/dist/cli.js ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ import { ExecutableResolver as l, Shell as c } from "@prozilla-os/core";
3
+ import { H as n } from "./chunks/shell-CBn2l1Ly.js";
4
+ import { program as e } from "@commander-js/extra-typings";
5
+ import { existsSync as u, readFileSync as m } from "node:fs";
6
+ import { Ansi as f } from "@prozilla-os/shared/logging";
7
+ const g = "1.0.0";
8
+ process.title = "posh";
9
+ function a(o) {
10
+ process.stderr.write(f.red(`posh: ${o}
11
+ `)), process.exit(1);
12
+ }
13
+ await l.loadBuiltins();
14
+ const s = l.getBuiltin("posh");
15
+ s || a("Failed to resolve executable");
16
+ e.name("posh");
17
+ s?.manual?.description && e.description(s.manual.description);
18
+ s?.manual?.usage && e.usage(s.manual.usage.replace("posh ", ""));
19
+ e.allowExcessArguments(!0).option("-c", s?.manual?.options?.["-c"]).version(g, "-v, --version").action(async (o) => {
20
+ const i = new n();
21
+ let r;
22
+ if (o.c) {
23
+ if (!e.args.length)
24
+ return a("-c: Option requires an argument");
25
+ const t = e.args.map(n.quote).join(" ");
26
+ r = await i.start(t);
27
+ } else if (e.args.length) {
28
+ const t = e.args[0];
29
+ if (!u(t))
30
+ return a(`${t}: ${c.INVALID_PATH_ERROR}`);
31
+ const p = m(t, "utf-8");
32
+ r = await i.start(p);
33
+ } else
34
+ r = await i.start();
35
+ process.exit(r);
36
+ });
37
+ e.parse(process.argv);
38
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { ExecutableResolver, Shell } from \"@prozilla-os/core\";\nimport { HeadlessShell } from \"./features\";\nimport { program } from \"@commander-js/extra-typings\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { Ansi } from \"@prozilla-os/shared/logging\";\nimport { version } from \"../package.json\";\n\nprocess.title = \"posh\";\n\nfunction error(message: string) {\n\tprocess.stderr.write(Ansi.red(`posh: ${message}\\n`));\n\tprocess.exit(1);\n}\n\nawait ExecutableResolver.loadBuiltins();\nconst posh = ExecutableResolver.getBuiltin(\"posh\");\nif (!posh)\n\terror(\"Failed to resolve executable\");\n\nprogram.name(\"posh\");\nif (posh?.manual?.description)\n\tprogram.description(posh.manual.description);\nif (posh?.manual?.usage)\n\tprogram.usage(posh.manual.usage.replace(\"posh \", \"\"));\n\nprogram\n\t.allowExcessArguments(true)\n\t.option(\"-c\", posh?.manual?.options?.[\"-c\"])\n\t.version(version, \"-v, --version\")\n\t.action(async (options) => {\n\t\tconst shell = new HeadlessShell();\n\n\t\tlet exitCode: number;\n\t\tif (options.c) {\n\t\t\tif (!program.args.length) {\n\t\t\t\treturn error(\"-c: Option requires an argument\");\n\t\t\t}\n\n\t\t\tconst input = program.args.map(HeadlessShell.quote).join(\" \");\n\t\t\texitCode = await shell.start(input);\n\t\t} else if (program.args.length) {\n\t\t\tconst path = program.args[0];\n\n\t\t\tif (!existsSync(path)) {\n\t\t\t\treturn error(`${path}: ${Shell.INVALID_PATH_ERROR}`);\n\t\t\t}\n\n\t\t\tconst input = readFileSync(path, \"utf-8\");\n\t\t\texitCode = await shell.start(input);\n\t\t} else {\n\t\t\texitCode = await shell.start();\n\t\t}\n\n\t\tprocess.exit(exitCode);\n\t});\n\nprogram.parse(process.argv);"],"names":["error","message","Ansi","ExecutableResolver","posh","program","version","options","shell","HeadlessShell","exitCode","input","path","existsSync","Shell","readFileSync"],"mappings":";;;;;;;AASA,QAAQ,QAAQ;AAEhB,SAASA,EAAMC,GAAiB;AAC/B,UAAQ,OAAO,MAAMC,EAAK,IAAI,SAASD,CAAO;AAAA,CAAI,CAAC,GACnD,QAAQ,KAAK,CAAC;AACf;AAEA,MAAME,EAAmB,aAAA;AACzB,MAAMC,IAAOD,EAAmB,WAAW,MAAM;AAC5CC,KACJJ,EAAM,8BAA8B;AAErCK,EAAQ,KAAK,MAAM;AACfD,GAAM,QAAQ,eACjBC,EAAQ,YAAYD,EAAK,OAAO,WAAW;AACxCA,GAAM,QAAQ,SACjBC,EAAQ,MAAMD,EAAK,OAAO,MAAM,QAAQ,SAAS,EAAE,CAAC;AAErDC,EACE,qBAAqB,EAAI,EACzB,OAAO,MAAMD,GAAM,QAAQ,UAAU,IAAI,CAAC,EAC1C,QAAQE,GAAS,eAAe,EAChC,OAAO,OAAOC,MAAY;AAC1B,QAAMC,IAAQ,IAAIC,EAAA;AAElB,MAAIC;AACJ,MAAIH,EAAQ,GAAG;AACd,QAAI,CAACF,EAAQ,KAAK;AACjB,aAAOL,EAAM,iCAAiC;AAG/C,UAAMW,IAAQN,EAAQ,KAAK,IAAII,EAAc,KAAK,EAAE,KAAK,GAAG;AAC5D,IAAAC,IAAW,MAAMF,EAAM,MAAMG,CAAK;AAAA,EACnC,WAAWN,EAAQ,KAAK,QAAQ;AAC/B,UAAMO,IAAOP,EAAQ,KAAK,CAAC;AAE3B,QAAI,CAACQ,EAAWD,CAAI;AACnB,aAAOZ,EAAM,GAAGY,CAAI,KAAKE,EAAM,kBAAkB,EAAE;AAGpD,UAAMH,IAAQI,EAAaH,GAAM,OAAO;AACxC,IAAAF,IAAW,MAAMF,EAAM,MAAMG,CAAK;AAAA,EACnC;AACC,IAAAD,IAAW,MAAMF,EAAM,MAAA;AAGxB,UAAQ,KAAKE,CAAQ;AACtB,CAAC;AAEFL,EAAQ,MAAM,QAAQ,IAAI;"}
package/dist/main.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ import { Shell } from '@prozilla-os/core';
2
+
3
+ /**
4
+ * A headless Posh shell.
5
+ * @example
6
+ * const shell = new HeadlessShell();
7
+ * const input = process.argv.slice(2).map(Shell.quote).join(" ");
8
+ *
9
+ * const exitCode = await shell.start(input);
10
+ * process.exit(exitCode);
11
+ */
12
+ export declare class HeadlessShell extends Shell {
13
+ #private;
14
+ constructor();
15
+ /**
16
+ * Executes the given command string or starts interactive mode if the command string is empty.
17
+ * @param input - The input string.
18
+ * @returns The exit code.
19
+ */
20
+ start(input?: string): Promise<number>;
21
+ /**
22
+ * Executes the given command string.
23
+ * @param input - The input string.
24
+ * @returns The exit code.
25
+ */
26
+ startCommand(input: string): Promise<number>;
27
+ /**
28
+ * Starts interactive mode.
29
+ * @returns The exit code.
30
+ */
31
+ startInteractiveMode(): Promise<number>;
32
+ private handleKeypress;
33
+ /**
34
+ * Checks if this shell is running in interactive mode.
35
+ * @returns `true` if this shell is running in interactive mode.
36
+ */
37
+ get isInteractive(): boolean;
38
+ /**
39
+ * Checks if the cursor is currently visible.
40
+ * @returns `true` if the cursor is currently visible.
41
+ */
42
+ get isCursorVisible(): boolean;
43
+ /**
44
+ * Sets the visible state of the cursor.
45
+ * @param visible - The state to set.
46
+ */
47
+ setCursorVisible(visible: boolean): void;
48
+ private setTTYRawMode;
49
+ }
50
+
51
+ export { }
package/dist/main.js ADDED
@@ -0,0 +1,5 @@
1
+ import { H as s } from "./chunks/shell-CBn2l1Ly.js";
2
+ export {
3
+ s as HeadlessShell
4
+ };
5
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@prozilla-os/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "description": "A NodeJS wrapper for Posh (ProzillaOS shell), a Bash-like shell emulator",
4
+ "version": "1.0.1",
5
+ "homepage": "https://os.prozilla.dev",
6
+ "author": {
7
+ "name": "Prozilla",
8
+ "email": "business@prozilla.dev",
9
+ "url": "https://prozilla.dev/"
10
+ },
11
+ "funding": "https://ko-fi.com/prozilla",
12
+ "type": "module",
13
+ "main": "dist/main.js",
14
+ "types": "dist/main.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/main.d.ts",
18
+ "default": "./dist/main.js"
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "bin": {
23
+ "posh": "dist/cli.js"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/prozilla-os/ProzillaOS.git",
28
+ "directory": "packages/cli"
29
+ },
30
+ "license": "MIT",
31
+ "dependencies": {
32
+ "@commander-js/extra-typings": "^14.0.0",
33
+ "@xmldom/xmldom": "^0.9.12",
34
+ "valtio": "^2.3.2",
35
+ "vite": "^7.3.2",
36
+ "vite-plugin-css-injected-by-js": "^3.5.2",
37
+ "vite-plugin-dts": "^4.5.4",
38
+ "vitest": "^4.1.5",
39
+ "@prozilla-os/core": "3.0.0",
40
+ "@prozilla-os/shared": "1.5.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^20.19.39",
44
+ "@types/react": "^18.3.28",
45
+ "rollup": "^4.60.3",
46
+ "typescript": "^5.9.3",
47
+ "vite-plugin-externalize-deps": "^0.10.0"
48
+ },
49
+ "files": [
50
+ "dist"
51
+ ],
52
+ "publishConfig": {
53
+ "registry": "https://registry.npmjs.org/",
54
+ "access": "public"
55
+ },
56
+ "scripts": {
57
+ "build": "tsc && vite build",
58
+ "test": "vitest",
59
+ "lint": "pnpm eslint ."
60
+ }
6
61
  }