fixed naming convention and text casing to use CamelCase on class fields. Process manager implemented, not tested, needs integration with current shell implementation
This commit is contained in:
+21
-21
@@ -7,32 +7,32 @@ import { createImmutableBuffer } from "@core/util/immutable_buffer";
|
||||
import { parseCommand } from "@core/util/parser";
|
||||
|
||||
export class Shell {
|
||||
static #instance: Shell;
|
||||
static #promise: Promise<Shell> | null = null;
|
||||
private _state: Readonly<ShellState>;
|
||||
static #Instance: Shell;
|
||||
static #Promise: Promise<Shell> | null = null;
|
||||
private _State: Readonly<ShellState>;
|
||||
|
||||
private constructor(state: ShellState) {
|
||||
this._state = Object.freeze(state);
|
||||
this._State = Object.freeze(state);
|
||||
}
|
||||
|
||||
static async init(initialState: ShellState): Promise<Shell> {
|
||||
if (Shell.#instance) {
|
||||
if (Shell.#Instance) {
|
||||
console.warn("Shell already initialized");
|
||||
return this.#instance;
|
||||
return this.#Instance;
|
||||
}
|
||||
|
||||
if (Shell.#promise) return Shell.#promise;
|
||||
if (Shell.#Promise) return Shell.#Promise;
|
||||
|
||||
Shell.#promise = (async () => {
|
||||
Shell.#Promise = (async () => {
|
||||
try {
|
||||
Shell.#instance = new Shell(initialState);
|
||||
return Shell.#instance;
|
||||
Shell.#Instance = new Shell(initialState);
|
||||
return Shell.#Instance;
|
||||
} finally {
|
||||
Shell.#promise = null;
|
||||
Shell.#Promise = null;
|
||||
}
|
||||
})();
|
||||
|
||||
return Shell.#promise;
|
||||
return Shell.#Promise;
|
||||
}
|
||||
|
||||
public async Execute(input: string): Promise<Result<ShellError>> {
|
||||
@@ -59,7 +59,7 @@ export class Shell {
|
||||
);
|
||||
}
|
||||
|
||||
this._state = withHistory(this._state, input);
|
||||
this._State = withHistory(this._State, input);
|
||||
const command = COMMAND_REGISTRY.get(parsed.command);
|
||||
|
||||
if (!command)
|
||||
@@ -72,7 +72,7 @@ export class Shell {
|
||||
parsed.command,
|
||||
) satisfies ResultError<CommandNotFoundError>;
|
||||
|
||||
if (command.requiresRoot && getCurrentSession(this._state).user.uid != 0) {
|
||||
if (command.requiresRoot && getCurrentSession(this._State).user.uid != 0) {
|
||||
return createErrorResult(
|
||||
"PermissionDenied",
|
||||
`Permission Denied`,
|
||||
@@ -83,28 +83,28 @@ export class Shell {
|
||||
) satisfies ResultError<PermissionDeniedError>;
|
||||
}
|
||||
|
||||
const out = command.fn(this._state, parsed.flags, parsed.args);
|
||||
this._state = out.state;
|
||||
const out = command.fn(this._State, parsed.flags, parsed.args);
|
||||
this._State = out.state;
|
||||
|
||||
if (out.result.type === "error") {
|
||||
this._state = withExitCode(this._state, out.result.error.exitCode);
|
||||
this._State = withExitCode(this._State, out.result.error.exitCode);
|
||||
} else {
|
||||
this._state = withExitCode(this._state, out.result.exitCode);
|
||||
this._State = withExitCode(this._State, out.result.exitCode);
|
||||
}
|
||||
|
||||
return out.result;
|
||||
}
|
||||
|
||||
public get State(): Readonly<ShellState> {
|
||||
return this._state;
|
||||
return this._State;
|
||||
}
|
||||
|
||||
public static get Instance(): Shell | undefined {
|
||||
if (!Shell.#instance) {
|
||||
if (!Shell.#Instance) {
|
||||
console.error("Shell has not been initialised yet. Call `await Shell.init()` first.");
|
||||
return;
|
||||
}
|
||||
return Shell.#instance;
|
||||
return Shell.#Instance;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user