- 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
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
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 { SIGNAL_MAP } from "@core/signal";
|
|
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 === SIGNAL_MAP.INPUT) {
|
|
const encoded = new TextEncoder().encode(("user pressed: " + out.payload + "\n") as string);
|
|
io.writeStdout(encoded);
|
|
|
|
if (out.payload === "x") {
|
|
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;
|