From 6810de85e12b4a590ffbe4a0e970116b37256ac7 Mon Sep 17 00:00:00 2001 From: Aleksandr Andrienko Date: Sun, 25 Jun 2017 21:42:31 +0300 Subject: [PATCH] Fix turning from alt screen to normal screen and vice versa. Fix https://github.com/sourcelair/xterm.js/issues/229 . --- src/BufferSet.ts | 12 ++---------- src/InputHandler.ts | 25 +++++++++++++------------ src/xterm.js | 15 +++++++++------ 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/BufferSet.ts b/src/BufferSet.ts index 0429c52..c9022a9 100644 --- a/src/BufferSet.ts +++ b/src/BufferSet.ts @@ -30,21 +30,13 @@ export class BufferSet extends EventEmitter { return this._normal; } - private resetTerminal() { - this._terminal.reset(); - this._terminal.viewport.syncScrollArea(); - this._terminal.showCursor(); - } - public activateNormalBuffer(): void { this._activeBuffer = this._normal; - this.resetTerminal(); - this.emit('activate', this._normal); + this.emit('activate', this._normal); // todo maybe simpler this._terminal.buffer = this._terminal.buffers.normal than using EventEmitter? } public activateAltBuffer(): void { this._activeBuffer = this._alt; - this.resetTerminal(); - this.emit('activate', this._alt); + this.emit('activate', this._alt); // todo maybe simpler this._terminal.buffer = this._terminal.buffers.alt than using EventEmitter? } } diff --git a/src/InputHandler.ts b/src/InputHandler.ts index bf5b651..c9b5844 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -942,16 +942,14 @@ export class InputHandler implements IInputHandler { this._terminal.cursorHidden = false; break; case 1049: // alt screen buffer cursor - // this._terminal.saveCursor(); - ; // FALL-THROUGH + this.saveCursor(params); + // FALL-THROUGH case 47: // alt screen buffer case 1047: // alt screen buffer - if (!this._terminal.normal) { - let normal = { - scrollBottom: this._terminal.buffer.scrollBottom, - }; - this._terminal.buffers.activateAltBuffer(); - } + this._terminal.buffers.activateAltBuffer(); + this._terminal.reset(); + this._terminal.viewport.syncScrollArea(); + this._terminal.showCursor(); break; } } @@ -1114,6 +1112,9 @@ export class InputHandler implements IInputHandler { case 1047: // normal screen buffer - clearing it first // Ensure the selection manager has the correct buffer this._terminal.buffers.activateNormalBuffer(); + if (params[0] === 1049) { + this.restoreCursor(params); + } this._terminal.selectionManager.setBuffer(this._terminal.buffer.lines); this._terminal.refresh(0, this._terminal.rows - 1); this._terminal.viewport.syncScrollArea(); @@ -1446,8 +1447,8 @@ export class InputHandler implements IInputHandler { * Save cursor (ANSI.SYS). */ public saveCursor(params: number[]): void { - this._terminal.savedX = this._terminal.buffer.x; - this._terminal.savedY = this._terminal.buffer.y; + this._terminal.buffers.active.x = this._terminal.buffer.x; + this._terminal.buffers.active.y = this._terminal.buffer.y; } @@ -1456,8 +1457,8 @@ export class InputHandler implements IInputHandler { * Restore cursor (ANSI.SYS). */ public restoreCursor(params: number[]): void { - this._terminal.buffer.x = this._terminal.savedX || 0; - this._terminal.buffer.y = this._terminal.savedY || 0; + this._terminal.buffer.x = this._terminal.buffers.active.x || 0; + this._terminal.buffer.y = this._terminal.buffers.active.y || 0; } } diff --git a/src/xterm.js b/src/xterm.js index d1406cc..5fb5ea7 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -161,7 +161,6 @@ function Terminal(options) { this.originMode = false; this.insertMode = false; this.wraparoundMode = true; // defaults: xterm - true, vt100 - false - this.normal = null; // charset this.charset = null; @@ -228,10 +227,12 @@ function Terminal(options) { this.surrogate_high = ''; // Create the terminal's buffers and set the current buffer - this.buffers = new BufferSet(this); - this.buffer = this.buffers.active; // Convenience shortcut; + if (!this.buffers) { + this.buffers = new BufferSet(this); + this.buffer = this.buffers.active; // Convenience shortcut; + } this.buffers.on('activate', function (buffer) { - this.buffer = buffer; + this._terminal.buffer = buffer; }); /** @@ -2026,8 +2027,6 @@ Terminal.prototype.resize = function(x, y) { this.refresh(0, this.rows - 1); - this.normal = null; - this.geometry = [this.cols, this.rows]; this.emit('resize', {terminal: this, cols: x, rows: y}); }; @@ -2305,9 +2304,13 @@ Terminal.prototype.reset = function() { this.options.cols = this.cols; var customKeyEventHandler = this.customKeyEventHandler; var cursorBlinkInterval = this.cursorBlinkInterval; + var inputHandler = this.inputHandler; + var buf = this.buffers; Terminal.call(this, this.options); this.customKeyEventHandler = customKeyEventHandler; this.cursorBlinkInterval = cursorBlinkInterval; + this.inputHandler = inputHandler; + this.buffers = buf; this.refresh(0, this.rows - 1); this.viewport.syncScrollArea(); }; -- 2.39.5