implementing the shellState sessionState, historyState implemented with helpers - no tests

This commit is contained in:
2026-07-24 17:46:09 +02:00
parent b63bae54aa
commit 0fce10895f
3 changed files with 36 additions and 4 deletions
+27
View File
@@ -0,0 +1,27 @@
const HISTORY_MAX_CAPACITY = 255;
export type HistoryState = readonly string[];
export function addHistoryEntry(state: HistoryState, input: string): HistoryState {
const entries: string[] = [...state];
if (entries.length === HISTORY_MAX_CAPACITY) {
entries.shift();
entries.push(input);
} else {
entries.push(input);
}
const result: readonly string[] = entries;
return Object.freeze(result);
}
export function getHistoryEntry(state: HistoryState, index: number): string {
const entry = state[index];
if (entry === undefined) {
// Add a custom error object later
throw Error(`HistoryState at index ${index} is undefined`);
}
return entry;
}
+8
View File
@@ -0,0 +1,8 @@
interface SessionState {
readonly user: UserInfo;
readonly envVars: ReadonlyMap<string, string>;
readonly history: HistoryState;
readonly cwd: number;
readonly pwd: number;
readonly exitCode: number;
}
+1 -4
View File
@@ -3,8 +3,5 @@ import type { FileSystem } from "./filesystem/filesystem";
interface ShellState {
readonly filesystem: FileSystem;
readonly users: ReadonlyMap<number, UserInfo>;
readonly currentUid: number;
readonly envVars: ReadonlyMap<string, string>;
readonly cwd: number;
readonly pwd: number;
readonly sessionState: ReadonlyArray<SessionState>;
}