Skip to content

Commit

Permalink
Add PoC Terminal.prototype.getState
Browse files Browse the repository at this point in the history
  • Loading branch information
parisk committed Mar 17, 2017
1 parent ef1b1c8 commit 45aa7eb
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/xterm.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,52 @@ function Terminal(options) {

inherits(Terminal, EventEmitter);

/**
* 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);
let state = {
geometry: this.geometry,
mode: this._getMode()
};

// 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 45aa7eb

Please sign in to comment.