Skip to content

Commit

Permalink
Add cursor (position + style) and options in terminal state
Browse files Browse the repository at this point in the history
  • Loading branch information
parisk committed May 6, 2017
1 parent 2221f70 commit 7f8f8ff
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/xterm.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,74 @@ 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
* - insert
* - normal
*/
Terminal.prototype._getMode = function() {
if (this.applicationKeypad) {
return 'application';
} else if (this.insertMode) {
return 'insert';
}

return 'normal';
};


/**
* Serialize and return the terminal's state as a JSON object.
* Also iterate through all terminal properties that have a `getState` methods and embed their
* state as well.
*/
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(),
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];
let value = this[key];

if (!value) {
continue;
}

if (typeof value.getState == 'function') {
state[key] = value.getState();
}
}

return state;
};

/**
* back_color_erase feature for xterm.
*/
Expand Down

0 comments on commit 7f8f8ff

Please sign in to comment.