some dog-tier work i dont remember (too sleepy)

This commit is contained in:
2026-08-19 03:15:51 +02:00
parent c39bbae091
commit dfa393b4d9
4 changed files with 56 additions and 3 deletions
+7 -1
View File
@@ -1,8 +1,14 @@
import type { CommandIO } from "./command_io";
import type { Result } from "./result";
import type { ShellState } from "./shell_state";
import type { ShellError } from "./util/errors";
type CommandFn = (state: ShellState, flags: string[], args: string[]) => CommandOutput<ShellError>;
export type CommandFn = (
io: CommandIO,
state: ShellState,
flags: string[],
args: string[],
) => CommandOutput<ShellError>;
export interface CommandDescriptor {
fn: CommandFn;
@@ -1,6 +1,6 @@
import type { Signal } from "./signal";
export interface ProcessContext {
export interface CommandIO {
writeStdout(data: Uint8Array): void;
writeStderr(data: Uint8Array): void;
getSignal(): Promise<Signal>;
+47
View File
@@ -0,0 +1,47 @@
import type { CommandFn } from "@core/command";
import type { ProcessContext } from "@core/command_io";
import type { Signal } from "@core/signal";
import type { EventEmitter } from "./event_emitter";
import type { ShellEventMap } from "./shell";
export class Process {
private signalQueue: Signal[];
private signalHandler: ((signal: Signal) => void) | null;
private stdoutChunks: Uint8Array[];
private stderrChunks: Uint8Array[];
private settled: boolean;
private readonly maxChunkByteSize: number;
pid: number;
name: string;
commandFn: CommandFn;
state: ShellState;
args: string[];
flags: string[];
events: EventEmitter<ShellEventMap>;
constructor() {
this.maxChunkByteSize = 1024;
}
private divideToChunks(data: Uint8Array): Uint8Array[] {}
private writeToOutput(chunks: Uint8Array[], eventType: "stdout" | "stderr", data: Uint8Array): void {
chunks.push(data);
if (data.length <= this.maxChunkByteSize) {
this.events.emit(eventType, { pid: this.pid, data });
return;
} else {
const chunk = data.slice(this.maxChunkByteSize);
}
}
private chunkData(data: Uint8Array): Uint8Array[] {}
start(): void {
const context: ProcessContext = {
writeStdout: data => this.writeOutput(data),
};
}
}
+1 -1
View File
@@ -112,5 +112,5 @@ export interface ShellEventMap {
process: { pid: number; name: string };
stdout: { pid: number; data: Uint8Array };
stderr: { pid: number; data: Uint8Array };
result: { pid: number; result: Result<ShellError> };
result: { pid: number; result: Result<ShellError>; state: ShellState };
}