-
Notifications
You must be signed in to change notification settings - Fork 102
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
Assigning to Screen.buffer to restore its state #155
Comments
Most of the state of If the PR #160 is accepted, then copying Could you give details of why you need this "backup and restore" feature? |
That’d be great. Any supported mechanism for doing this should meet my needs.
A tool I’m developing does a form of terminal recording (similar in some ways to what’s mentioned in #160), and it includes support for adding ‘annotations’ and ‘highlights’ to what’s shown in the terminal. Before adding annotations (which can really be arbitrary modifications to the terminal contents) we store the terminal state; when removing them, we restore the state. |
The control codes used for full screen applications such as tmux or vim make use of a 'normal' and 'alternate' screen buffer. Switching between these buffers feels like a similar operation to making a backup of the screen state and later restoring it. Perhaps handling of those codes isn't something currently supported by pyte, but there may be those that have subclassed some of the pyte classes to implement it themselves. |
@abingham So the idea would be: you have a screen with data written by the terminal app, at some moment you stop feeding the streamer but update yourself the screen with some annotations. Because you want to remove the annotations before restarting the feeding, you store the screen's buffer before the annotations and restore it after. In this sense the annotations or any "temporal" modification to the screen work more as a "stack": you start with a screen with a given buffer (0) and when you are about to do some temporal writing you push a new buffer state (1) which it's in principle, a copy of the former (0). Once you are done, you can restore the previous buffer doing a pop on the stack. What @altoidbox suggests I think it would not work. The alternate buffer is meant as a second independent buffer to switch back and forward with no content shared between. Think in an array of 2 different buffers. In the case of the stack you implicitly have that the content of the buffet at the top is a copy of the previous buffer. Does this make sense? @altoidbox do you know a program that requires alternate buffer? |
@eldipa As far as applications that run in a terminal environment, the primary ones that come to mind are |
Yes, I was thinking in I will give it a try to the restore buffer/alternate buffer things probably the next month. By the way, if you have some extra time to review and/or test the #160 it would be nice. Thanks to both for the replies. |
@eldipa Yes, the stack analogy is exactly correct; in fact ‘push’ and ‘pop’ are the verbs we use in our code for these operations. We need to be able to put any number of states on the stack and return to them. |
I have a situation where I need to store the state of the terminal at some point and restore it later. For pyte's
Screen
, is it sufficient that I a) deep copyScreen.buffer
at the point I want to save and b) assign toScreen.buffer
when I want to restore it? Is this officially support behavior? Is there anything else I need to do? Thanks!The text was updated successfully, but these errors were encountered: