-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement getState method #613
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,6 +265,87 @@ 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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file should be deleted since we're on v3 now. |
||
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 normalBuffer = this.lines._array; | ||
let altBuffer = null; | ||
|
||
// This means that the alt buffer is active | ||
if (this.normal) { | ||
altBuffer = normalBuffer; | ||
normalBuffer = this.normal.lines._array; | ||
} | ||
|
||
let state = { | ||
buffers: { | ||
normal: normalBuffer, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should create a With the 24 lines from the CircularList it should be easy to create a new CircularList constructor or |
||
alt: altBuffer | ||
}, | ||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this retrieve any data yet? Maybe we should comment it out if it's not used yet? |
||
let key = properties[i]; | ||
let value = this[key]; | ||
|
||
if (!value) { | ||
continue; | ||
} | ||
|
||
if (typeof value.getState == 'function') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should move forward with this and implement an |
||
state[key] = value.getState(); | ||
} | ||
} | ||
|
||
return state; | ||
}; | ||
|
||
/** | ||
* back_color_erase feature for xterm. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the
, true
as this arg was removed