bigass changes
- 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
This commit is contained in:
+63
-5
@@ -10,13 +10,71 @@ namespace Termos {
|
||||
}
|
||||
*/
|
||||
|
||||
const message: string = "Hello, World!";
|
||||
console.log(message);
|
||||
import { FileSystem } from "@core/filesystem/filesystem";
|
||||
import type { TreeNode } from "@core/filesystem/treenode";
|
||||
import { getCurrentSession, type GroupInfo, type UserInfo } from "@core/session_manager";
|
||||
import { createInitialShellState, type ShellState } from "@core/shell_state";
|
||||
import { resolveInode } from "@core/util/path_resolver";
|
||||
import { deserializeFileSystem } from "@shell/serializer";
|
||||
import { Shell } from "@shell/shell";
|
||||
import { printTree } from "./util/tree_visualizer";
|
||||
|
||||
const rawJson = `{"atime": 1786341244,"children": [{"atime": 1786341264,"children": [{"atime": 1786341330,"children": [],"content": null,"ctime": 1786341330,"group": 1000,"inode": 2,"mode": 493,"mtime": 1786341330,"name": "subdir1","owner": 1000,"parent": 1,"type": "directory"}],"content": null,"ctime": 1786341330,"group": 1000,"inode": 1,"mode": 493,"mtime": 1786341330,"name": "folder1","owner": 1000,"parent": 0,"type": "directory"},{"atime": 1786341269,"children": [{"atime": 1786341344,"children": [],"content": null,"ctime": 1786341344,"group": 1000,"inode": 4,"mode": 493,"mtime": 1786341344,"name": "subdir2","owner": 1000,"parent": 3,"type": "directory"},{"atime": 1786341345,"children": [{"atime": 1786341356,"children": [],"content": [],"ctime": 1786341356,"group": 1000,"inode": 6,"mode": 420,"mtime": 1786341356,"name": "empty-foo","owner": 1000,"parent": 5,"type": "regular"}],"content": null,"ctime": 1786341356,"group": 1000,"inode": 5,"mode": 493,"mtime": 1786341356,"name": "subdir3","owner": 1000,"parent": 3,"type": "directory"}],"content": null,"ctime": 1786341345,"group": 1000,"inode": 3,"mode": 493,"mtime": 1786341345,"name": "folder2","owner": 1000,"parent": 0,"type": "directory"},{"atime": 1786341312,"children": [],"content": [72,101,108,108,111,44,32,87,111,114,108,100,33,10],"ctime": 1786341312,"group": 1000,"inode": 7,"mode": 420,"mtime": 1786341312,"name": "some-file","owner": 1000,"parent": 0,"type": "regular"}],"content": null,"ctime": 1786341312,"group": 1000,"inode": 0,"mode": 493,"mtime": 1786341312,"name": "root","owner": 1000,"parent": 0,"type": "directory"}`;
|
||||
const base = deserializeFileSystem(rawJson);
|
||||
|
||||
const overlay: ReadonlyMap<number, TreeNode | null> = new Map();
|
||||
|
||||
const fs = FileSystem.init(base, overlay, base.size - 1);
|
||||
|
||||
console.log(printTree(fs, 0));
|
||||
|
||||
const users: Map<number, UserInfo> = new Map();
|
||||
const groups: Map<number, GroupInfo> = new Map();
|
||||
const user: UserInfo = {
|
||||
username: "root",
|
||||
uid: 1000,
|
||||
gid: 0,
|
||||
group: [1000],
|
||||
home: 0,
|
||||
};
|
||||
const group: GroupInfo = {
|
||||
groupname: "root",
|
||||
gid: 1000,
|
||||
members: [0],
|
||||
};
|
||||
users.set(1000, user);
|
||||
groups.set(1000, group);
|
||||
|
||||
const state: ShellState = createInitialShellState(fs, users, groups, user);
|
||||
await Shell.init(state);
|
||||
|
||||
Shell.Instance?.on("result", payload => {
|
||||
const decoded = new TextDecoder().decode(payload.result.stdout.toArray());
|
||||
process.stdout.write(decoded + "\n");
|
||||
process.stdout.write(resolveInode(payload.state.filesystem, getCurrentSession(payload.state).cwd) + "\n> ");
|
||||
});
|
||||
|
||||
/*
|
||||
Cant do it like this because commands also use the stdout event right before returning a result so e.g. echo will print twice
|
||||
|
||||
Need to use this only if a continuous process is running
|
||||
*/
|
||||
|
||||
/* Shell.Instance?.on("stdout", payload => {
|
||||
const decoded = new TextDecoder().decode(payload.data);
|
||||
process.stdout.write(decoded + "\n");
|
||||
}); */
|
||||
|
||||
//console.clear();
|
||||
process.stdout.write(resolveInode(Shell.Instance?.State.filesystem!, getCurrentSession(state).cwd) + "\n> ");
|
||||
process.stdin.on("data", async data => {
|
||||
if (Shell.Instance?.BoundPID !== null) {
|
||||
Shell.Instance?.sendInput(data.toString().trim());
|
||||
return;
|
||||
}
|
||||
|
||||
console.clear();
|
||||
process.stdout.write("> ");
|
||||
process.stdin.on("data", data => {
|
||||
const input = data.toString().trim();
|
||||
await Shell.Instance?.execute(input);
|
||||
});
|
||||
|
||||
//export { Termos };
|
||||
|
||||
Reference in New Issue
Block a user