diff --git a/src/console/terminal.ts b/src/console/terminal.ts index 8892473..ec7acbe 100644 --- a/src/console/terminal.ts +++ b/src/console/terminal.ts @@ -38,8 +38,6 @@ const CSI = { class Pseudoterminal implements vscode.Pseudoterminal { constructor(private applyHandler: (data: string) => Promise) { - this.onDidWrite = this.writeEmitter.event; - this.queue(async () => { await this.waitOpen(); }); @@ -47,7 +45,7 @@ class Pseudoterminal implements vscode.Pseudoterminal { private writeEmitter = new vscode.EventEmitter(); - onDidWrite: vscode.Event; + onDidWrite = this.writeEmitter.event; private opened = false; async open() { @@ -130,12 +128,16 @@ class Pseudoterminal implements vscode.Pseudoterminal { } } - private async refreshLine(data: string, offset: number) { + private async refreshLine(data = this.inputedData, offset = this.curOffset) { this.saveUndoStack(); await this.refreshLineWithoutUndo(data, offset); } - private async refreshLineWithoutUndo(data: string, offset: number) { + private async refreshLineWithoutUndo(data = this.inputedData, offset = this.curOffset) { + if (this.needUpdateCursorPos) { + await this.updateCursorPos(); + this.needUpdateCursorPos = false; + } this.moveCursor(0); this.write(CSI.CLEAR_LINE); this.write(data); @@ -374,6 +376,16 @@ class Pseudoterminal implements vscode.Pseudoterminal { await this.refreshLineWithoutUndo(this.inputedData, this.curOffset); } + + private async updateCursorPos() { + let [row, col] = await this.requestCursorPos(); + this.headPos = [row, col]; + } + + private needUpdateCursorPos: boolean = false; + setDimensions(dimensions: vscode.TerminalDimensions) { + this.needUpdateCursorPos = true; + } } export class Terminal extends vscode.Disposable {