small tweaks to the file structure, and reorganization of the codebase.
preparations for session manager function implementations
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { type HistoryState } from "./history_state";
|
||||
import type { ShellState } from "./shell_state";
|
||||
|
||||
export interface UserInfo {
|
||||
readonly username: string;
|
||||
readonly uid: number;
|
||||
readonly gid: number;
|
||||
readonly group: readonly number[];
|
||||
readonly home: number;
|
||||
}
|
||||
|
||||
export interface SessionState {
|
||||
readonly user: UserInfo;
|
||||
readonly envVars: ReadonlyMap<string, string>;
|
||||
readonly history: HistoryState;
|
||||
readonly cwd: number;
|
||||
readonly pwd: number;
|
||||
readonly exitCode: number;
|
||||
}
|
||||
|
||||
export function createInitialSessionState(user: UserInfo): SessionState {
|
||||
return Object.freeze({
|
||||
user,
|
||||
envVars: Object.freeze(new Map()),
|
||||
history: Object.freeze([]),
|
||||
cwd: user.home,
|
||||
pwd: user.home,
|
||||
exitCode: 0,
|
||||
} satisfies SessionState);
|
||||
}
|
||||
|
||||
export function getCurrentSession(state: ShellState): SessionState {
|
||||
return state.sessionStack[state.sessionStack.length - 1]!;
|
||||
}
|
||||
Reference in New Issue
Block a user