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 Mar 20, 2017
1 parent 45aa7eb commit 5d38551
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/xterm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
Expand Down

0 comments on commit 5d38551

Please sign in to comment.