fixed #6349 - enable xterm flow control

This commit is contained in:
Eugene Pankov 2022-05-09 21:50:06 -07:00
parent 5f4a7c4d39
commit c1bd2a720d
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
4 changed files with 18 additions and 17 deletions

View File

@ -141,6 +141,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
private toolbarRevealTimeout = new ResettableTimeout(() => { private toolbarRevealTimeout = new ResettableTimeout(() => {
this.revealToolbar = false this.revealToolbar = false
}, 1000) }, 1000)
private frontendWriteLock = Promise.resolve()
get input$ (): Observable<Buffer> { get input$ (): Observable<Buffer> {
if (!this.frontend) { if (!this.frontend) {
@ -373,14 +374,14 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
}) })
} }
protected onFrontendReady (): void { protected async onFrontendReady (): Promise<void> {
this.frontendIsReady = true this.frontendIsReady = true
if (this.savedState) { if (this.savedState) {
this.frontend!.restoreState(this.savedState) this.frontend!.restoreState(this.savedState)
if (!this.savedStateIsLive) { if (!this.savedStateIsLive) {
this.frontend!.write('\r\n\r\n') await this.frontend!.write('\r\n\r\n')
this.frontend!.write(colors.bgWhite.black(' * ') + colors.bgBlackBright.white(' History restored ')) await this.frontend!.write(colors.bgWhite.black(' * ') + colors.bgBlackBright.white(' History restored '))
this.frontend!.write('\r\n\r\n') await this.frontend!.write('\r\n\r\n')
} }
} }
} }
@ -411,13 +412,13 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
/** /**
* Feeds input into the terminal frontend * Feeds input into the terminal frontend
*/ */
write (data: string): void { async write (data: string): Promise<void> {
this.withSpinnerPaused(() => { this.frontendWriteLock = this.frontendWriteLock.then(() =>
this.writeRaw(data) this.withSpinnerPaused(() => this.writeRaw(data)))
}) await this.frontendWriteLock
} }
protected writeRaw (data: string): void { protected async writeRaw (data: string): Promise<void> {
if (!this.frontend) { if (!this.frontend) {
throw new Error('Frontend not ready') throw new Error('Frontend not ready')
} }
@ -434,7 +435,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
} }
} }
this.frontend.write(data) await this.frontend.write(data)
} }
async paste (): Promise<void> { async paste (): Promise<void> {
@ -780,10 +781,10 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
this.spinnerActive = false this.spinnerActive = false
} }
protected withSpinnerPaused (work: () => void): void { protected async withSpinnerPaused (work: () => any): Promise<void> {
const wasActive = this.spinnerActive const wasActive = this.spinnerActive
this.stopSpinner() this.stopSpinner()
work() await work()
if (wasActive) { if (wasActive) {
this.startSpinner() this.startSpinner()
} }

View File

@ -121,7 +121,7 @@ export class DebugDecorator extends TerminalDecorator {
private async doLoadOutput (terminal: BaseTerminalTabComponent) { private async doLoadOutput (terminal: BaseTerminalTabComponent) {
const data = await this.loadFile() const data = await this.loadFile()
if (data) { if (data) {
terminal.frontend?.write(data) await terminal.frontend?.write(data)
} }
} }
@ -131,7 +131,7 @@ export class DebugDecorator extends TerminalDecorator {
if (data.startsWith('`')) { if (data.startsWith('`')) {
data = data.substring(3, data.length - 3) data = data.substring(3, data.length - 3)
} }
terminal.frontend?.write(JSON.parse(data)) await terminal.frontend?.write(JSON.parse(data))
} }
} }
} }

View File

@ -72,7 +72,7 @@ export abstract class Frontend {
abstract selectAll (): void abstract selectAll (): void
abstract clearSelection (): void abstract clearSelection (): void
abstract focus (): void abstract focus (): void
abstract write (data: string): void abstract write (data: string): Promise<void>
abstract clear (): void abstract clear (): void
abstract visualBell (): void abstract visualBell (): void
abstract scrollToBottom (): void abstract scrollToBottom (): void

View File

@ -247,8 +247,8 @@ export class XTermFrontend extends Frontend {
setTimeout(() => this.xterm.focus()) setTimeout(() => this.xterm.focus())
} }
write (data: string): void { async write (data: string): Promise<void> {
this.xterm.write(data) await new Promise<void>(r => this.xterm.write(data, r))
} }
clear (): void { clear (): void {