Fix save and restore cursor behavior

This broke in #717.

Fixes #818
This commit is contained in:
Daniel Imms 2017-07-27 16:28:27 -07:00
parent f36bd24e1e
commit 604959a319
3 changed files with 20 additions and 8 deletions

View File

@ -15,6 +15,9 @@ import { CircularList } from './utils/CircularList';
export class Buffer { export class Buffer {
public lines: CircularList<[number, string, number][]>; public lines: CircularList<[number, string, number][]>;
public savedY: number;
public savedX: number;
/** /**
* Create a new Buffer. * Create a new Buffer.
* @param {Terminal} terminal - The terminal the Buffer will belong to * @param {Terminal} terminal - The terminal the Buffer will belong to

View File

@ -948,7 +948,8 @@ export class InputHandler implements IInputHandler {
this._terminal.cursorHidden = false; this._terminal.cursorHidden = false;
break; break;
case 1049: // alt screen buffer cursor case 1049: // alt screen buffer cursor
this.saveCursor(params); // TODO: Not sure if we need to save/restore after switching the buffer
// this.saveCursor(params);
// FALL-THROUGH // FALL-THROUGH
case 47: // alt screen buffer case 47: // alt screen buffer
case 1047: // alt screen buffer case 1047: // alt screen buffer
@ -1118,9 +1119,10 @@ export class InputHandler implements IInputHandler {
case 1047: // normal screen buffer - clearing it first case 1047: // normal screen buffer - clearing it first
// Ensure the selection manager has the correct buffer // Ensure the selection manager has the correct buffer
this._terminal.buffers.activateNormalBuffer(); this._terminal.buffers.activateNormalBuffer();
if (params[0] === 1049) { // TODO: Not sure if we need to save/restore after switching the buffer
this.restoreCursor(params); // if (params[0] === 1049) {
} // this.restoreCursor(params);
// }
this._terminal.selectionManager.setBuffer(this._terminal.buffer.lines); this._terminal.selectionManager.setBuffer(this._terminal.buffer.lines);
this._terminal.refresh(0, this._terminal.rows - 1); this._terminal.refresh(0, this._terminal.rows - 1);
this._terminal.viewport.syncScrollArea(); this._terminal.viewport.syncScrollArea();
@ -1453,8 +1455,8 @@ export class InputHandler implements IInputHandler {
* Save cursor (ANSI.SYS). * Save cursor (ANSI.SYS).
*/ */
public saveCursor(params: number[]): void { public saveCursor(params: number[]): void {
this._terminal.buffers.active.x = this._terminal.buffer.x; this._terminal.buffer.savedX = this._terminal.buffer.x;
this._terminal.buffers.active.y = this._terminal.buffer.y; this._terminal.buffer.savedY = this._terminal.buffer.y;
} }
@ -1463,8 +1465,8 @@ export class InputHandler implements IInputHandler {
* Restore cursor (ANSI.SYS). * Restore cursor (ANSI.SYS).
*/ */
public restoreCursor(params: number[]): void { public restoreCursor(params: number[]): void {
this._terminal.buffer.x = this._terminal.buffers.active.x || 0; this._terminal.buffer.x = this._terminal.buffer.savedX || 0;
this._terminal.buffer.y = this._terminal.buffers.active.y || 0; this._terminal.buffer.y = this._terminal.buffer.savedY || 0;
} }
} }

View File

@ -184,6 +184,10 @@ export class Parser {
public parse(data: string): ParserState { public parse(data: string): ParserState {
let l = data.length, j, cs, ch, code, low; let l = data.length, j, cs, ch, code, low;
if (this._terminal.debug) {
this._terminal.log('data: ' + data);
}
this._position = 0; this._position = 0;
// apply leftover surrogate high from last write // apply leftover surrogate high from last write
if (this._terminal.surrogate_high) { if (this._terminal.surrogate_high) {
@ -458,6 +462,9 @@ export class Parser {
case ParserState.CSI: case ParserState.CSI:
if (ch in csiStateHandler) { if (ch in csiStateHandler) {
if (this._terminal.debug) {
this._terminal.log(`CSI ${this._terminal.prefix ? this._terminal.prefix : ''} ${this._terminal.params ? this._terminal.params.join(';') : ''} ${this._terminal.postfix ? this._terminal.postfix : ''} ${ch}`);
}
csiStateHandler[ch](this._inputHandler, this._terminal.params, this._terminal.prefix, this._terminal.postfix, this); csiStateHandler[ch](this._inputHandler, this._terminal.params, this._terminal.prefix, this._terminal.postfix, this);
} else { } else {
this._terminal.error('Unknown CSI code: %s.', ch); this._terminal.error('Unknown CSI code: %s.', ch);