some dog-tier work i dont remember (too sleepy)
This commit is contained in:
+7
-1
@@ -1,8 +1,14 @@
|
|||||||
|
import type { CommandIO } from "./command_io";
|
||||||
import type { Result } from "./result";
|
import type { Result } from "./result";
|
||||||
import type { ShellState } from "./shell_state";
|
import type { ShellState } from "./shell_state";
|
||||||
import type { ShellError } from "./util/errors";
|
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 {
|
export interface CommandDescriptor {
|
||||||
fn: CommandFn;
|
fn: CommandFn;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Signal } from "./signal";
|
import type { Signal } from "./signal";
|
||||||
|
|
||||||
export interface ProcessContext {
|
export interface CommandIO {
|
||||||
writeStdout(data: Uint8Array): void;
|
writeStdout(data: Uint8Array): void;
|
||||||
writeStderr(data: Uint8Array): void;
|
writeStderr(data: Uint8Array): void;
|
||||||
getSignal(): Promise<Signal>;
|
getSignal(): Promise<Signal>;
|
||||||
@@ -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
@@ -112,5 +112,5 @@ export interface ShellEventMap {
|
|||||||
process: { pid: number; name: string };
|
process: { pid: number; name: string };
|
||||||
stdout: { pid: number; data: Uint8Array };
|
stdout: { pid: number; data: Uint8Array };
|
||||||
stderr: { pid: number; data: Uint8Array };
|
stderr: { pid: number; data: Uint8Array };
|
||||||
result: { pid: number; result: Result<ShellError> };
|
result: { pid: number; result: Result<ShellError>; state: ShellState };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user