chore: make webfs usable
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import type { Item } from '../fs/Item'
|
||||
import type { Program } from '../program/Program'
|
||||
import type { Terminal } from '../terminal/Terminal'
|
||||
import type { EventBroadcaster } from '../utils/EventBroadcaster'
|
||||
@@ -17,4 +18,5 @@ export abstract class Shell {
|
||||
abstract ExecuteProgram(name: string, args: string[]): void
|
||||
abstract Init(): Promise<void>
|
||||
abstract HandleKeyInput(key: string, isCharacter: boolean): void
|
||||
abstract SetWorkingDirectory(directory: Item): Promise<void>
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import { ResetIndexedDb } from '../program/ResetIndexedDb'
|
||||
import { Cat } from '../program/Cat'
|
||||
import { Echo } from '../program/Echo'
|
||||
import { Mkdir } from '../program/Mkdir'
|
||||
import { Pwd } from '../program/Pwd'
|
||||
import { Cd } from '../program/Cd'
|
||||
|
||||
export class Wush extends Shell {
|
||||
public readonly Version = "0.1.0"
|
||||
@@ -47,7 +49,7 @@ export class Wush extends Shell {
|
||||
readonly stdout: SimpleStream<string>
|
||||
|
||||
private programs: { [name: string]: Program } = {}
|
||||
private workingDirectory: Item = null as unknown as Item // workdir is initialized in the Init so this should be safe
|
||||
private workingDirectory: Item = null as unknown as Item // workdir is initialized in Init so this should be safe
|
||||
|
||||
constructor(broadcaster: EventBroadcaster, terminal: Terminal) {
|
||||
super(broadcaster, terminal)
|
||||
@@ -65,9 +67,6 @@ export class Wush extends Shell {
|
||||
// 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()
|
||||
@@ -83,6 +82,8 @@ export class Wush extends Shell {
|
||||
this.programs['cat'] = new Cat()
|
||||
this.programs['echo'] = new Echo()
|
||||
this.programs['mkdir'] = new Mkdir()
|
||||
this.programs['pwd'] = new Pwd()
|
||||
this.programs['cd'] = new Cd(this)
|
||||
|
||||
this.stdout.on(data => this.WriteEscapedString(data))
|
||||
this.Prompt()
|
||||
@@ -121,7 +122,19 @@ export class Wush extends Shell {
|
||||
}
|
||||
|
||||
Prompt() {
|
||||
this.terminal.Write(`hi [${this.execExitCode}] -> `)
|
||||
this.terminal.Write(`boykisser in ${this.workingDirectory.GetPath()} -> `)
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the working directory
|
||||
* @param directory the directory to enter into
|
||||
* @throws an error if the directory cannot be opened
|
||||
*/
|
||||
async SetWorkingDirectory(directory: Item) {
|
||||
if (!(await directory.Exists()) || !directory.IsDirectory())
|
||||
throw new Error(`Directory ${directory.GetPath()} doesn't exist`)
|
||||
|
||||
this.workingDirectory = directory
|
||||
}
|
||||
|
||||
WriteStdin(data: string) {
|
||||
|
||||
Reference in New Issue
Block a user