Files
str/src/index.ts

45 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-11-10 23:54:20 -06:00
import {log} from './log.js'
import {Lifecycle} from './util/lifecycle.js'
import {Input} from './vm/input.js'
import {Lexer} from "./vm/lexer.js";
import {Parser} from "./vm/parser.js";
import {commands} from "./vm/commands/index.js";
import {Executor} from "./vm/vm.js";
2026-02-21 19:20:22 -06:00
import {ConsoleDisplay, OutputManager, WlClipboard} from "./vm/output.js";
import {processPath} from "./vm/commands/command.js";
import * as fs from "node:fs";
2025-11-10 23:54:20 -06:00
;(async () => {
const lifecycle = new Lifecycle()
const input = new Input()
input.adoptLifecycle(lifecycle)
input.subscribe(line => log.verbose('input', { line }))
2025-11-10 23:54:20 -06:00
const lexer = new Lexer(input)
lexer.subscribe(token => log.verbose('token', token))
2025-11-10 23:54:20 -06:00
const parser = new Parser(commands, lexer)
parser.subscribe(exec => log.verbose('exec', exec))
2025-11-10 23:54:20 -06:00
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 rcFile = processPath('~/.str.rc')
if ( fs.existsSync(rcFile) ) {
log.verbose('rc', { rcFile })
2025-11-10 23:54:20 -06:00
const rcFileContent = fs.readFileSync(rcFile).toString()
await input.pushLines('\n' + rcFileContent)
}
input.setupPrompt()
process.on('SIGINT', () => lifecycle.close())
})()