Implement runfile and support for .str.rc
This commit is contained in:
46
src/index.ts
46
src/index.ts
@@ -6,27 +6,39 @@ import {Parser} from "./vm/parser.js";
|
||||
import {commands} from "./vm/commands/index.js";
|
||||
import {Executor} from "./vm/vm.js";
|
||||
import {ConsoleDisplay, OutputManager, WlClipboard} from "./vm/output.js";
|
||||
import {processPath} from "./vm/commands/command.js";
|
||||
import * as fs from "node:fs";
|
||||
|
||||
const lifecycle = new Lifecycle()
|
||||
const input = new Input()
|
||||
input.adoptLifecycle(lifecycle)
|
||||
input.subscribe(line => log.verbose('input', { line }))
|
||||
;(async () => {
|
||||
const lifecycle = new Lifecycle()
|
||||
const input = new Input()
|
||||
input.adoptLifecycle(lifecycle)
|
||||
input.subscribe(line => log.verbose('input', { line }))
|
||||
|
||||
const lexer = new Lexer(input)
|
||||
lexer.subscribe(token => log.verbose('token', token))
|
||||
const lexer = new Lexer(input)
|
||||
lexer.subscribe(token => log.verbose('token', token))
|
||||
|
||||
const parser = new Parser(commands, lexer)
|
||||
parser.subscribe(exec => log.verbose('exec', exec))
|
||||
const parser = new Parser(commands, lexer)
|
||||
parser.subscribe(exec => log.verbose('exec', exec))
|
||||
|
||||
const output: OutputManager = {
|
||||
display: new ConsoleDisplay,
|
||||
clipboard: new WlClipboard,
|
||||
}
|
||||
const output: OutputManager = {
|
||||
display: new ConsoleDisplay,
|
||||
clipboard: new WlClipboard,
|
||||
}
|
||||
|
||||
const exec = new Executor(output, parser, input)
|
||||
exec.adoptLifecycle(lifecycle)
|
||||
exec.subscribe(state => state.outputSubject())
|
||||
const exec = new Executor(output, parser, input)
|
||||
exec.adoptLifecycle(lifecycle)
|
||||
exec.subscribe(state => state.outputSubject())
|
||||
|
||||
input.setupPrompt()
|
||||
const rcFile = processPath('~/.str.rc')
|
||||
if ( fs.existsSync(rcFile) ) {
|
||||
log.verbose('rc', { rcFile })
|
||||
|
||||
process.on('SIGINT', () => lifecycle.close())
|
||||
const rcFileContent = fs.readFileSync(rcFile).toString()
|
||||
await input.pushLines('\n' + rcFileContent)
|
||||
}
|
||||
|
||||
input.setupPrompt()
|
||||
|
||||
process.on('SIGINT', () => lifecycle.close())
|
||||
})()
|
||||
|
||||
Reference in New Issue
Block a user