WRITE UNIT TESTS!!!
first async command working, no unit tests done AGAING
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import type { CommandDescriptor, CommandOutput } from "@core/command";
|
||||
import type { CommandIO } from "@core/command_io";
|
||||
import type { ResultSuccess } from "@core/result";
|
||||
import type { ShellState } from "@core/shell_state";
|
||||
import type { ShellError } from "@core/util/errors";
|
||||
import { createImmutableBuffer } from "@core/util/immutable_buffer";
|
||||
|
||||
const COMMAND_NAME = "async";
|
||||
|
||||
async function main(
|
||||
io: CommandIO,
|
||||
state: ShellState,
|
||||
__flags: string[],
|
||||
__args: string[],
|
||||
): Promise<CommandOutput<ShellError>> {
|
||||
while (true) {
|
||||
const out = await io.getSignal();
|
||||
|
||||
if (out.type === "INPUT") {
|
||||
const encoded = new TextEncoder().encode(("user pressed: " + out.payload + "\n") as string);
|
||||
io.writeStdout(encoded);
|
||||
|
||||
if (out.payload === "ctrl+c") {
|
||||
const result: ResultSuccess = {
|
||||
type: "success",
|
||||
exitCode: 0,
|
||||
stdout: createImmutableBuffer(new Uint8Array()),
|
||||
stderr: createImmutableBuffer(new Uint8Array()),
|
||||
commandName: COMMAND_NAME,
|
||||
};
|
||||
|
||||
return {
|
||||
state: state,
|
||||
result,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const descriptor = {
|
||||
fn: main,
|
||||
name: COMMAND_NAME,
|
||||
} satisfies CommandDescriptor;
|
||||
Reference in New Issue
Block a user