cd fixed and cleaned up. Shell started, needs data fetching code to initialize properly, added the approperiate db_manager file to implement that.

This commit is contained in:
2026-08-08 08:11:19 +02:00
parent 394e0b9e7c
commit 0149937526
3 changed files with 74 additions and 24 deletions
+20 -24
View File
@@ -32,30 +32,26 @@ function main(state: ShellState, __flags: string[], args: string[]): CommandOutp
let inode: number; let inode: number;
const session = getCurrentSession(state); const session = getCurrentSession(state);
switch (args[0]) { if (args[0] === undefined) {
case undefined: inode = session.user.home;
inode = session.user.home; } else if (args[0] === "-") {
break; inode = session.pwd;
case "-": } else {
inode = session.pwd; const result = safeResolvePath(state.filesystem, session.cwd, args[0]);
break; if (result.type === "error") {
default: return {
const result = safeResolvePath(state.filesystem, session.cwd, args[0]); state,
if (result.type === "error") { result: createErrorResult(
return { "PathResolutionError",
state, "No such file or directory",
result: createErrorResult( { path: args[0]! },
"PathResolutionError", createImmutableBuffer(new Uint8Array()),
"No such file or directory", createImmutableBuffer(new Uint8Array()),
{ path: args[0]! }, COMMAND_NAME,
createImmutableBuffer(new Uint8Array()), ),
createImmutableBuffer(new Uint8Array()), } satisfies CommandOutput<PathResolutionError>;
COMMAND_NAME, }
), inode = result.inode;
} satisfies CommandOutput<PathResolutionError>;
}
inode = result.inode;
break;
} }
if (state.filesystem.isFile(inode)) { if (state.filesystem.isFile(inode)) {
+5
View File
@@ -0,0 +1,5 @@
/*
Create an interface for the rest of the library to use to fetch nessesary data.
To do that, implement a termos config that will contain the table and db names, aswell as other relevant information -
maybe a flag for headless mode (uses the built-in console frontend module - need to evaluate this idea more)
*/
+49
View File
@@ -0,0 +1,49 @@
import type { Result } from "@core/result";
import { type ShellState } from "@core/shell_state";
import type { ShellError } from "@core/util/errors";
export class Shell {
static #instance: Shell;
static #promise: Promise<Shell> | null = null;
private readonly state: Readonly<ShellState>;
private constructor(state: ShellState) {
this.state = Object.freeze(state);
}
static async init(): Promise<Shell> {
if (Shell.#instance) {
console.warn("Shell already initialized");
return this.#instance;
}
if (Shell.#promise) return Shell.#promise;
const state; //Create initial shell state,
Shell.#promise = (async () => {
try {
Shell.#instance = new Shell();
return Shell.#instance;
} finally {
Shell.#promise = null;
}
})();
return Shell.#promise;
}
public async Execute(input: string): Promise<Result<ShellError>> {}
public get State(): Readonly<ShellState> {
return this.state;
}
public static get Instance(): Shell | undefined {
if (!Shell.#instance) {
console.error("Shell has not been initialised yet. Call `await Singleton.init()` first.");
return;
}
return Shell.#instance;
}
}