65 lines
2.8 KiB
Markdown
65 lines
2.8 KiB
Markdown
# Termos
|
|
|
|
This library allows running a fully contained unix-like operating system written in pure typescript.
|
|
|
|
It supports all the basic operations like saving and reading files, creating new files and folders.
|
|
It has support for users and permissions and can handle multiple user sessions at the same time.
|
|
It doesnt implement a website friendly interface on its own. Thats one of the desing choices in this project, to make it as versatile as possible. But it shares a easy to use interface that you can plug into your frontend code to interact with it properly.
|
|
|
|
> [!NOTE]
|
|
> Right now the project is still in alpha and this is just a small portion of whats to come that serves for demonstration purposes. The code and design will change in the future so most of this is not set in stone
|
|
|
|
## Prerequisites
|
|
|
|
- [Node.js](https://nodejs.org/) installed (version 22 or higher)
|
|
- [pnpm](https://pnpm.io/) installed (version 12 or higher)
|
|
|
|
## Installation
|
|
|
|
> [!NOTE]
|
|
> If youre using Windows or MacOS as your operating system then the installation process might be different.
|
|
> Refer to [this website][ref1] on how to install nodejs on your operating system
|
|
> and [this website][ref2] for pnpm accordingly.
|
|
|
|
[ref1]: https://nodejs.org/en/download
|
|
[ref2]: https://pnpm.io/installation
|
|
|
|
```bash
|
|
pnpm add "https://git.gornodox.dev/ChaosMaker/termos/releases/download/0.1.0/termos-0.1.0.tgz"
|
|
```
|
|
|
|
## Minimal usecase
|
|
|
|
```typescript
|
|
import { Termos } from "termos";
|
|
|
|
const shell = await Termos.getShell({
|
|
filesystem: {
|
|
// an example json representation of the filesystem
|
|
json: `{"dev": [{"id":0,"tree": {"atime": 1788458541,"children": [{"atime": 1794947961,"children": [],"content": [87,101,108,99,111,109,101,32,116,111,32,84,101,114,109,111,115,33,32,240,144,148,140,213,158,46,32,46,213,158,240,144,166,175,10],"ctime": 1794948078,"group": 0,"inode": 1,"link_count": 1,"mode": 420,"mtime": 1794948078,"name": "hello_world.txt","owner": 0,"parent": 0,"size": 35,"type": "regular"}],"content": null,"ctime": 1794947961,"group": 0,"inode": 0,"link_count": 2,"mode": 493,"mtime": 1794947961,"name": "root","owner": 0,"parent": 0,"size": 29,"type": "directory"}}]}`,
|
|
},
|
|
users: [{ username: "root", groups: ["root"], home: "/" }],
|
|
groups: ["root"],
|
|
general: { user: "root" },
|
|
});
|
|
|
|
// Subscribtion needed to recive command results and print out error messages
|
|
shell.on("result", payload => {
|
|
if (payload.result.type === "error") {
|
|
console.log(payload.result.error.message + "\n");
|
|
}
|
|
process.stdout.write("\n" + "Hello~\n> ");
|
|
});
|
|
|
|
// Subscribtion needed to recieve stdout buffer contents from shell
|
|
shell.on("stdout", payload => {
|
|
const decoded = new TextDecoder().decode(payload.data);
|
|
process.stdout.write(decoded);
|
|
});
|
|
|
|
// Takes in a string and executes it as a command
|
|
shell.execute("ls -l");
|
|
```
|
|
|
|
For more information, reference the [wiki]()
|