Skip to content

Commit

Permalink
处理终端窗口大小变化
Browse files Browse the repository at this point in the history
这处理也太麻烦了
  • Loading branch information
sumneko committed Jun 17, 2024
1 parent 4c6e912 commit fac2197
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/console/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ const CSI = {

class Pseudoterminal implements vscode.Pseudoterminal {
constructor(private applyHandler: (data: string) => Promise<void>) {
this.onDidWrite = this.writeEmitter.event;

this.queue(async () => {
await this.waitOpen();
});
}

private writeEmitter = new vscode.EventEmitter<string>();

onDidWrite: vscode.Event<string>;
onDidWrite = this.writeEmitter.event;

private opened = false;
async open() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit fac2197

Please sign in to comment.