fixed visual layout of readline prompts

This commit is contained in:
Eugene Pankov 2021-07-12 22:31:17 +02:00
parent 3be98e6244
commit 8f55333d23
No known key found for this signature in database
GPG key ID: 5896FCBBDD1CF4F4

View file

@ -33,19 +33,9 @@ export class TerminalStreamProcessor {
constructor (private options: StreamProcessingOptions) {
this.inputReadlineInStream = new PassThrough()
this.inputReadlineOutStream = new PassThrough()
this.inputReadline = createReadline({
input: this.inputReadlineInStream,
output: this.inputReadlineOutStream,
terminal: true,
prompt: this.options.inputMode === 'readline-hex' ? 'hex> ' : '> ',
} as any)
this.inputReadlineOutStream.on('data', data => {
this.outputToTerminal.next(Buffer.from(data))
})
this.inputReadline.on('line', line => {
this.onTerminalInput(Buffer.from(line + '\n'))
this.resetInputPrompt()
})
this.outputToTerminal$.pipe(debounce(() => interval(500))).subscribe(() => {
if (this.started) {
this.onOutputSettled()
@ -54,14 +44,24 @@ export class TerminalStreamProcessor {
}
start (): void {
this.inputReadline = createReadline({
input: this.inputReadlineInStream,
output: this.inputReadlineOutStream,
terminal: true,
prompt: this.options.inputMode === 'readline-hex' ? 'hex> ' : '> ',
} as any)
this.inputReadline.on('line', line => {
this.onTerminalInput(Buffer.from(line + '\n'))
this.resetInputPrompt()
})
this.started = true
this.onOutputSettled()
}
feedFromSession (data: Buffer): void {
if (this.options.inputMode?.startsWith('readline')) {
if (this.inputPromptVisible) {
clearLine(this.inputReadlineOutStream, 0)
this.outputToTerminal.next(Buffer.from('\r'))
this.inputPromptVisible = false
}
}