Skip to content

Commit

Permalink
Fix turning from alt screen to normal screen and vice versa. Fix xter…
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrienkoAleksandr committed Jun 25, 2017
1 parent 0e97e7d commit 5b3f724
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
12 changes: 2 additions & 10 deletions src/BufferSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
}
25 changes: 13 additions & 12 deletions src/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,16 +936,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;
}
}
Expand Down Expand Up @@ -1108,6 +1106,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();
Expand Down Expand Up @@ -1440,8 +1441,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;
}


Expand All @@ -1450,8 +1451,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;
}
}

Expand Down
15 changes: 9 additions & 6 deletions src/xterm.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,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;
Expand Down Expand Up @@ -221,10 +220,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;
});

/**
Expand Down Expand Up @@ -1947,8 +1948,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});
};
Expand Down Expand Up @@ -2221,9 +2220,13 @@ Terminal.prototype.reset = function() {
this.options.cols = this.cols;
var customKeydownHandler = this.customKeydownHandler;
var cursorBlinkInterval = this.cursorBlinkInterval;
var inputHandler = this.inputHandler;
var buf = this.buffers;
Terminal.call(this, this.options);
this.customKeydownHandler = customKeydownHandler;
this.cursorBlinkInterval = cursorBlinkInterval;
this.inputHandler = inputHandler;
this.buffers = buf;
this.refresh(0, this.rows - 1);
this.viewport.syncScrollArea();
};
Expand Down

0 comments on commit 5b3f724

Please sign in to comment.