feat: working filesystem
This commit is contained in:
@@ -15,6 +15,6 @@ export abstract class Shell {
|
||||
|
||||
abstract LoadProgram(program: Program, name: string): void
|
||||
abstract ExecuteProgram(name: string, args: string[]): void
|
||||
abstract Init(): void
|
||||
abstract Init(): Promise<void>
|
||||
abstract HandleKeyInput(key: string, isCharacter: boolean): void
|
||||
}
|
||||
|
||||
@@ -15,6 +15,12 @@ import { Ls } from '../program/Ls'
|
||||
import { Item } from '../fs/Item'
|
||||
import { Touch } from '../program/Touch'
|
||||
import { Sl } from '../program/Sl'
|
||||
import { Rm } from '../program/Rm'
|
||||
import { Rl } from '../program/Rl'
|
||||
import { ResetIndexedDb } from '../program/ResetIndexedDb'
|
||||
import { Cat } from '../program/Cat'
|
||||
import { Echo } from '../program/Echo'
|
||||
import { Mkdir } from '../program/Mkdir'
|
||||
|
||||
export class Wush extends Shell {
|
||||
public readonly Version = "0.1.0"
|
||||
@@ -33,12 +39,15 @@ export class Wush extends Shell {
|
||||
*/
|
||||
private execExitCode: number = 0
|
||||
|
||||
// workers
|
||||
private workersAllowed: boolean = false
|
||||
|
||||
// streams
|
||||
readonly stdin: SimpleStream<string>
|
||||
readonly stdout: SimpleStream<string>
|
||||
|
||||
private programs: { [name: string]: Program } = {}
|
||||
private workingDirectory: Item = Item.Root
|
||||
private workingDirectory: Item = null as unknown as Item // workdir is initialized in the Init so this should be safe
|
||||
|
||||
constructor(broadcaster: EventBroadcaster, terminal: Terminal) {
|
||||
super(broadcaster, terminal)
|
||||
@@ -48,11 +57,17 @@ export class Wush extends Shell {
|
||||
this.stdout = new SimpleStream<string>()
|
||||
}
|
||||
|
||||
Init() {
|
||||
async Init() {
|
||||
this.broadcaster.on('keydown', (key: string, isCharacter: boolean) =>
|
||||
this.HandleKeyInput(key, isCharacter),
|
||||
)
|
||||
|
||||
// load workdir
|
||||
this.workingDirectory = await Item.Root()
|
||||
|
||||
if (!this.workingDirectory.Exists())
|
||||
this.workingDirectory.Create()
|
||||
|
||||
// load core programs
|
||||
this.programs['clear'] = new Clear()
|
||||
this.programs['eval'] = new Eval()
|
||||
@@ -62,6 +77,12 @@ export class Wush extends Shell {
|
||||
this.programs['ls'] = new Ls()
|
||||
this.programs['touch'] = new Touch()
|
||||
this.programs['sl'] = new Sl()
|
||||
this.programs['rm'] = new Rm()
|
||||
this.programs['rl'] = new Rl()
|
||||
this.programs['rsindb'] = new ResetIndexedDb()
|
||||
this.programs['cat'] = new Cat()
|
||||
this.programs['echo'] = new Echo()
|
||||
this.programs['mkdir'] = new Mkdir()
|
||||
|
||||
this.stdout.on(data => this.WriteEscapedString(data))
|
||||
this.Prompt()
|
||||
@@ -85,8 +106,8 @@ export class Wush extends Shell {
|
||||
this.execExitCode = code != -1 ? code : -2
|
||||
})
|
||||
.catch((e) => {
|
||||
this.WriteEscapedString("lol")
|
||||
this.WriteEscapedString(`\n${String(e)}\n`)
|
||||
this.WriteEscapedString(`wush: command ${name} exited with the following exception\n`)
|
||||
this.WriteEscapedString(` | ${String(e)}\n`)
|
||||
})
|
||||
.finally(() => {
|
||||
// check if the exec actually exited with an exit code
|
||||
@@ -176,11 +197,13 @@ export class Wush extends Shell {
|
||||
}
|
||||
}
|
||||
|
||||
// todo: actual processing
|
||||
ProcessAdvancedControlCode(complex: string): boolean {
|
||||
if (!complex.match(/\\(.*;)/gm))
|
||||
return false
|
||||
|
||||
const code = matches[]
|
||||
return true
|
||||
// const code = matches[]
|
||||
}
|
||||
|
||||
HandleKeyInput(key: string, isCharacter: boolean) {
|
||||
|
||||
Reference in New Issue
Block a user