sync: sync wip stuff

This commit is contained in:
2026-05-12 10:38:30 +02:00
parent dc706d6262
commit 97b9994594
21 changed files with 532 additions and 100 deletions

View File

@@ -1,3 +1,4 @@
import type { Program } from '../program/Program'
import type { Terminal } from '../terminal/Terminal'
import type { EventBroadcaster } from '../utils/EventBroadcaster'
@@ -12,6 +13,8 @@ export abstract class Shell {
this.terminal = terminal
}
abstract LoadProgram(program: Program, name: string): void
abstract ExecuteProgram(name: string, args: string[]): void
abstract Init(): void
abstract HandleKeyInput(key: string, isCharacter: boolean): void
}

View File

@@ -12,6 +12,9 @@ import { EventBroadcaster } from '../utils/EventBroadcaster'
import { SimpleStream } from '../utils/SimpleStream'
import { Shell } from './Shell'
import { Ls } from '../program/Ls'
import { Item } from '../fs/Item'
import { Touch } from '../program/Touch'
import { Sl } from '../program/Sl'
export class Wush extends Shell {
public readonly Version = "0.1.0"
@@ -35,6 +38,7 @@ export class Wush extends Shell {
readonly stdout: SimpleStream<string>
private programs: { [name: string]: Program } = {}
private workingDirectory: Item = Item.Root
constructor(broadcaster: EventBroadcaster, terminal: Terminal) {
super(broadcaster, terminal)
@@ -56,6 +60,8 @@ export class Wush extends Shell {
this.programs['lsprg'] = new Lsprg(this)
this.programs['info'] = new Info()
this.programs['ls'] = new Ls()
this.programs['touch'] = new Touch()
this.programs['sl'] = new Sl()
this.stdout.on(data => this.WriteEscapedString(data))
this.Prompt()
@@ -73,6 +79,26 @@ export class Wush extends Shell {
delete this.programs[name]
}
ExecuteProgram(name: string, args: string[]) {
this.programs[name].Exec(this.stdin, this.stdout, this.workingDirectory, args)
.then(code => {
this.execExitCode = code != -1 ? code : -2
})
.catch((e) => {
this.WriteEscapedString("lol")
this.WriteEscapedString(`\n${String(e)}\n`)
})
.finally(() => {
// check if the exec actually exited with an exit code
// and if not, set it to -2 to indicate that it didn't exit with a valid code
if (this.execExitCode === -1)
this.execExitCode = -2
// this.terminal.Write(`The program exited with exit code ${this.execExitCode}.`)
this.Prompt()
})
}
Prompt() {
this.terminal.Write(`hi [${this.execExitCode}] -> `)
}
@@ -84,7 +110,7 @@ export class Wush extends Shell {
WriteEscapedString(data: string) {
let buf = data.split('')
buf.forEach((char) => {
if (!this.ProcessControlCode(char))
if (!this.ProcessSimpleControlCode(char))
this.terminal.Write(char)
})
}
@@ -123,23 +149,7 @@ export class Wush extends Shell {
this.execExitCode = -1
if (this.programs[args[0]] instanceof Program) {
this.programs[args[0]].Exec(this.stdin, this.stdout, args)
.then(code => {
this.execExitCode = code != -1 ? code : -2
})
.catch((e) => {
this.WriteEscapedString("lol")
this.WriteEscapedString(`\n${String(e)}\n`)
})
.finally(() => {
// check if the exec actually exited with an exit code
// and if not, set it to -2 to indicate that it didn't exit with a valid code
if (this.execExitCode === -1)
this.execExitCode = -2
// this.terminal.Write(`The program exited with exit code ${this.execExitCode}.`)
this.Prompt()
})
this.ExecuteProgram(args[0], args)
} else {
this.execExitCode = 0
@@ -153,7 +163,7 @@ export class Wush extends Shell {
}
}
ProcessControlCode(code: string): boolean {
ProcessSimpleControlCode(code: string): boolean {
switch (code) {
case '\f':
this.terminal.NewPage()
@@ -166,6 +176,13 @@ export class Wush extends Shell {
}
}
ProcessAdvancedControlCode(complex: string): boolean {
if (!complex.match(/\\(.*;)/gm))
return false
const code = matches[]
}
HandleKeyInput(key: string, isCharacter: boolean) {
if (this.execExitCode === -1) console.log('program running')
if (!isCharacter) {