-
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
Support saving and restoring of terminal state #595
Comments
@vincentwoo I can see this being pretty useful, do you have an idea of what such an API would look like? |
I think you would likely want another constructor like |
@vincentwoo would some way of serializing state on the server and sending that over the wire to the client also work? Recently I made it so you don't need to open xterm on an element to get it to retain the buffer, so that might be enough? |
Yeah, serialization is basically what I mean by "getState", as long as what's produced can be consumed by the client. Regarding just using the regular xterm without an element, that might work. I can give it a shot on node, later. |
I think #266 means it's essentially running as headless before |
Cool. Any thoughts on how exporting state might work? |
Depends what needs to be retained, just the buffer and cursor? |
I'm not sure myself, this is why this was a request. I don't know what the xterm state machine looks like internally, nor exactly what you mean by "buffer" and "cursor". |
This is a great proposal @vincentwoo, thanks! I think the best part of it is the serialization of the state (which is the main part of this discussion as well). IMO a good start towards this is introducing a private property (e.g. named
This property should be used internally to "set" the state of the terminal at each time (and be consulted by the terminal's internals to see what's happening when needed), but it should be read-only by the outside world (e.g. How does this sound? |
Sounds good to me! I'm not an expert in knowing exactly every state variable that uniquely identifies the state of |
Some more things we probably want to serialize:
@parisk I was thinking a Terminal.prototype.getState() {
const state = {};
// this.serializableComponents is an ISerializable[] which ensures they
// have componentKey/getState()
this.serializableComponents.forEach(c => {
state[c.componentKey] = c.getState();
});
// TODO: Add anything owned by Terminal to state
// ...
return state;
}
// Restore using something like this which would do the reverse
Terminal.prototype.restoreState(state: Object): void;
// A static method that returns a Terminal might be better:
Terminal.restoreTerminal(state: Object): Terminal; |
That's an interesting approach 👍 . I am opening up a branch to give this a go. |
Any updates on this one? I am also having a similar use case. |
Copying and pasting the proposal to fix this issue from #2213 (comment) below I had a chat with @jerch about this and we see these problems with the current approach of including it into core:
Given this, we think the best way to approach this feature is to use an addon (example /**
* Serializes terminal rows into a string that can be written back to the terminal
* to restore the state. The cursor will also be positioned to the correct cell.
* When restoring a terminal it is best to do before `Terminal.open` is called
* to avoid wasting CPU cycles rendering incomplete frames.
* @param rows The number of rows to serialize, starting from the bottom of the
* terminal. This defaults to the number of rows in the viewport.
*/
serialize(rows?: number): string; If you're unfamiliar with terminals the resulting string would look something like this This has a bunch of benefits:
Note that this would not be able to support color or other styles until we expose attributes in the API but that's something we want to do and could improve upon it at a later time. |
Removed headless mode from title as xterm.js kind of already supports that by working fine without calling |
We now have the serialize addon as well as xterm-headless which covers this. Any issues with them should be reported as new issues. |
Hi everyone,
With
xterm.js
maturing, I think a great feature to expand the range of applicationsxterm.js
could be useful for would be the formalization of a headless mode. What do I mean? Well basically, for the ability to:Right now, the only way to reliably "set" the state of a client is to replay the set of all commands that produced that editor's state (at least via the public API). However, you could easily imagine wanting to do things like:
A lot of this is basically almost already possible if you just serialize
term.rows
and assorted state flags, but the adoption of a formal API would help a lot. It may also help improve the testability and robustness of the core library, too!Thoughts?
Vincent
The text was updated successfully, but these errors were encountered: