Get All terminal content #4467
-
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
You might want to have a look at the serialize addon, it preserves most of the terminal buffer state and operation modes. It returns a string, that can be fed back to your newly created terminal: const serializeAddon = new SerializeAddon();
oldTerminal.loadAddon(serializeAddon);
...
const terminalState = serializeAddon.serialize();
...
const newTerminal = new Terminal(...);
newTerminal.write(terminalState); Sidenote: To avoid deserialization artefacts it might be needed to give the new terminal the same size as the old one at the time of serialization (simply resize the new terminal into proper shape afterwards). |
Beta Was this translation helpful? Give feedback.
-
Ok, Thanks for help |
Beta Was this translation helpful? Give feedback.
-
Yes , it generates all the terminal content but I am using this inside my websocket.onmessage function and trying to save all available content of terminal into a file on new message, but it doesn't save every time, but when i console log the the serializer data ( means terminal data ) then it logs data one by one. I am using something like this : this.ws.onmessage = (event) => {
this.$terminal.write(event.data, () => {
let terminalState = this.$serializerAddon.serialize();
// Code for save the terminal data in a file
await fs(file path).writeFile(terminalState);
})
} Edit: |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Unless you want to write a terminal recorder, invoking the serializer on every incoming chunk of data is def. the wrong approach. And even for a terminal recorder that is most likely not the best way to do things, as it will re-serialize higher up lines over and over creating very bad runtime.
Not sure what you mean by that. The serializer walks the buffer cells line-wise yes, but it creates a full dump of the buffer content in a single string. The string is meant to restore most of the terminal state at the time of serialization, thus will contain multiple lines, if there were more than a single line.
Your code above look…