1
0
forked from noxious/server

Renamed command manager to console manager, improved log reading

This commit is contained in:
2024-12-28 21:24:59 +01:00
parent 0b99d4098e
commit 4f1b9cf024
8 changed files with 236 additions and 114 deletions

View File

@ -0,0 +1,33 @@
import * as readline from 'readline'
export class ConsolePrompt {
private readonly rl: readline.Interface
private isClosed: boolean = false
constructor(private readonly commandHandler: (command: string) => void) {
this.rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
this.rl.on('close', () => {
this.isClosed = true
})
}
public start(): void {
if (this.isClosed) return
this.promptCommand()
}
public close(): void {
this.rl.close()
}
private promptCommand(): void {
this.rl.question('> ', (command: string) => {
this.commandHandler(command)
this.promptCommand()
})
}
}