feat: add some utilities
This commit is contained in:
10
src/program/Clear.ts
Normal file
10
src/program/Clear.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { SimpleStream } from '../utils/SimpleStream'
|
||||
import { Program } from './Program'
|
||||
|
||||
export class Clear extends Program {
|
||||
async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, __: string[]): Promise<number> {
|
||||
stdout.emit('\f')
|
||||
|
||||
return 0
|
||||
}
|
||||
}
|
||||
17
src/program/Eval.ts
Normal file
17
src/program/Eval.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { SimpleStream } from '../utils/SimpleStream'
|
||||
import { Program } from './Program'
|
||||
|
||||
export class Eval extends Program {
|
||||
async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, args: string[]): Promise<number> {
|
||||
const javascript = args.slice(1).join(' ')
|
||||
|
||||
try {
|
||||
eval(javascript)
|
||||
} catch (e) {
|
||||
stdout.emit(`${String(e)}\n`)
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
}
|
||||
29
src/program/Loadprg.ts
Normal file
29
src/program/Loadprg.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import type { Wush } from '../shell/Wush'
|
||||
import type { SimpleStream } from '../utils/SimpleStream'
|
||||
import { Program } from './Program'
|
||||
|
||||
export class Loadprg extends Program {
|
||||
// private wush: Wush
|
||||
|
||||
constructor(_: Wush) {
|
||||
super()
|
||||
// this.wush = wush
|
||||
}
|
||||
|
||||
async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, args: string[]): Promise<number> {
|
||||
stdout.emit('Not implemented yet.\n')
|
||||
return 0
|
||||
|
||||
const javascript = args.slice(1).join(' ')
|
||||
|
||||
try {
|
||||
eval(javascript)
|
||||
} catch (e) {
|
||||
stdout.emit(`${String(e)}\n`)
|
||||
stdout.emit(`${String((e as Error).stack)}\n`)
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
}
|
||||
19
src/program/Lsprg.ts
Normal file
19
src/program/Lsprg.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { Wush } from '../shell/Wush'
|
||||
import type { SimpleStream } from '../utils/SimpleStream'
|
||||
import { Program } from './Program'
|
||||
|
||||
export class Lsprg extends Program {
|
||||
private wush: Wush
|
||||
|
||||
constructor(wush: Wush) {
|
||||
super()
|
||||
this.wush = wush
|
||||
}
|
||||
|
||||
async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, __: string[]): Promise<number> {
|
||||
for (const program in this.wush.GetPrograms())
|
||||
stdout.emit(`${program}\n`)
|
||||
|
||||
return 0
|
||||
}
|
||||
}
|
||||
5
src/program/Program.ts
Normal file
5
src/program/Program.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { SimpleStream } from "../utils/SimpleStream";
|
||||
|
||||
export abstract class Program {
|
||||
abstract Exec(stdin: SimpleStream<string>, stdout: SimpleStream<string>, args: string[]): Promise<number>
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { SimpleStream } from '../utils/SimpleStream'
|
||||
|
||||
export const ClearExec = async (stdin: SimpleStream<string>, stdout: SimpleStream<string>): Promise<number> => {
|
||||
stdout.emit("\f")
|
||||
|
||||
return 0
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// stdlibwsh - (st)andard (lib)rary (w)eb (sh)ell
|
||||
// - céčkoismy at their peak
|
||||
|
||||
import type { SimpleStream } from '../utils/SimpleStream'
|
||||
|
||||
export const io = {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user