From 5d38551a598c79f6237dc17e1119ddf434390445 Mon Sep 17 00:00:00 2001 From: Paris Kasidiaris Date: Mon, 20 Mar 2017 12:37:10 +0200 Subject: [PATCH] Add cursor (position + style) and options in terminal state --- src/xterm.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/xterm.js b/src/xterm.js index 8d7e6e007a..e9105ba99d 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -250,6 +250,18 @@ function Terminal(options) { inherits(Terminal, EventEmitter); +/** + * Returns the current position and style of the terminal cursor. + * It returns an object in the following form: {position: [x, y], style: "cursorStyle"} + */ +Terminal.prototype._getCursor = function() { + return { + position: [this.x, this.y], + style: this.getOption('cursorStyle') + }; +}; + + /** * Returns the current mode of the terminal. Can be one of the following: * - application @@ -274,11 +286,21 @@ Terminal.prototype._getMode = function() { */ Terminal.prototype.getState = function() { const properties = Object.keys(this); + const availableOptions = [ + 'cursorBlink', 'disableStdin', 'scrollback', 'tabStopWidth', 'useFlowControl' + ]; + let state = { + cursor: this._getCursor(), geometry: this.geometry, - mode: this._getMode() + mode: this._getMode(), + options: {} }; + availableOptions.forEach(function (option) { + state.options[option] = term.getOption(option); + }); + // Iterate through all terminal properties to embed their state as well. for (let i in properties) { let key = properties[i];