bigass changes

- ls beginnings,
- added groups to shellstate
- made buffers optional in result factory functions,
- made an enum signal map,
- fixed a minor bug in path resolver that didnt output the '/' if     the inode was at root (inode 0) from the moment it was called

- added code that attaches the shell to the built-in IDE terminal

--

tests need fixing, new code needs testing
This commit is contained in:
2026-08-24 10:30:04 +02:00
parent 48aac3c883
commit dad18cd4cc
14 changed files with 380 additions and 82 deletions
+14 -15
View File
@@ -2,6 +2,7 @@ import { COMMAND_REGISTRY } from "@core/command_registry";
import { createErrorResult, type Result } from "@core/result";
import { getCurrentSession } from "@core/session_manager";
import { withExitCode, withHistory, type ShellState } from "@core/shell_state";
import { SIGNAL_MAP } from "@core/signal";
import type { ShellError } from "@core/util/errors";
import { createImmutableBuffer } from "@core/util/immutable_buffer";
import { parseCommand } from "@core/util/parser";
@@ -14,13 +15,18 @@ export class Shell {
private _State: Readonly<ShellState>;
private _ProcessManager: ProcessManager = new ProcessManager();
private _EventEmitter: EventEmitter<ShellEventMap> = new EventEmitter();
private _GlobalKeyMap: ReadonlyMap<string, string>;
private _GlobalKeyMap: ReadonlyMap<string, SIGNAL_MAP>;
public BoundPID: number | null = null;
private constructor(state: ShellState) {
this._State = Object.freeze(state);
this._GlobalKeyMap = new Map();
//Temporary solution for sigint keybind
const map = new Map();
map.set("ctrl+c", SIGNAL_MAP.SIGINT);
this._GlobalKeyMap = map;
this._ProcessManager.on("stdout", payload => this._EventEmitter.emit("stdout", payload));
this._ProcessManager.on("stderr", payload => this._EventEmitter.emit("stderr", payload));
@@ -62,14 +68,7 @@ export class Shell {
try {
parsed = parseCommand(input);
} catch {
const result = createErrorResult(
"ParseError",
`Parsing error - ${input}`,
{},
createImmutableBuffer(new Uint8Array()),
createImmutableBuffer(new Uint8Array()),
"",
);
const result = createErrorResult("ParseError", `Parsing error - ${input}`, {});
this._State = withExitCode(this._State, result.error.exitCode);
this._EventEmitter.emit("result", { pid: 0, result, state: this._State });
@@ -82,13 +81,15 @@ export class Shell {
const command = COMMAND_REGISTRY.get(parsed.command);
if (!command) {
const encoded = new TextEncoder().encode(`Command ${parsed.command} not found`);
const result = createErrorResult(
"CommandNotFound",
`Command ${parsed.command} not found`,
{ command: parsed.command },
createImmutableBuffer(new Uint8Array()),
createImmutableBuffer(new Uint8Array()),
parsed.command,
createImmutableBuffer(encoded),
createImmutableBuffer(new Uint8Array()),
);
this._State = withExitCode(this._State, result.error.exitCode);
@@ -101,8 +102,6 @@ export class Shell {
"PermissionDenied",
`Permission Denied`,
{ resource: `Execution of the ${command.name} command` },
createImmutableBuffer(new Uint8Array()),
createImmutableBuffer(new Uint8Array()),
parsed.command,
);
@@ -124,7 +123,7 @@ export class Shell {
}
} else {
if (this.BoundPID !== null) {
this._ProcessManager.sendSignal(this.BoundPID, { type: "INPUT", payload: input });
this._ProcessManager.sendSignal(this.BoundPID, { type: SIGNAL_MAP.INPUT, payload: input });
}
}
}