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) { constructor (private options: StreamProcessingOptions) {
this.inputReadlineInStream = new PassThrough() this.inputReadlineInStream = new PassThrough()
this.inputReadlineOutStream = 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.inputReadlineOutStream.on('data', data => {
this.outputToTerminal.next(Buffer.from(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(() => { this.outputToTerminal$.pipe(debounce(() => interval(500))).subscribe(() => {
if (this.started) { if (this.started) {
this.onOutputSettled() this.onOutputSettled()
@ -54,14 +44,24 @@ export class TerminalStreamProcessor {
} }
start (): void { 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.started = true
this.onOutputSettled()
} }
feedFromSession (data: Buffer): void { feedFromSession (data: Buffer): void {
if (this.options.inputMode?.startsWith('readline')) { if (this.options.inputMode?.startsWith('readline')) {
if (this.inputPromptVisible) { if (this.inputPromptVisible) {
clearLine(this.inputReadlineOutStream, 0) clearLine(this.inputReadlineOutStream, 0)
this.outputToTerminal.next(Buffer.from('\r'))
this.inputPromptVisible = false this.inputPromptVisible = false
} }
} }