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