Skip to content
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

Add marshalling methods for recreating terminal state #1

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

djnalluri
Copy link

The current render methods change the output in a way that's maybe easier to render to an image. However, this behavior makes it difficult to dump the contents of a midterm emulated terminal to a TUI and have the state accurately represented. For example, cursor state is currently rendered directly as the cell's format.

This PR provides a MarshalBinary method that attempts to produce an output such that, if it is read back into a fresh midterm instance, the state should be identical. A use case for this is to have midterm receive input with a TUI connecting later and being able to reproduce output as if it had received the original input stream. This is probably a far from perfect implementation but it works for me for an "alternate screen" type program.

@vito
Copy link
Owner

vito commented Nov 6, 2024

Thanks for the PR! My only real hesitation is that I'm not too confident I'll be able to keep this working through the many refactors this repo has gone through, since I'm not 100% familiar with the use case and don't have anything that would exercise it myself.

Do you think you'd be able to add some sort of test? Maybe even a really high level one that checks for the property you want: given a Terminal with some state, I can call MarshalBinary and write that output to a fresh Terminal and end up with the identical state.

Thanks again!

@djnalluri
Copy link
Author

Took a bit of effort but I've managed to get a test going that runs through all of the existing data and compares at each frame that a cloned terminal is deeply equal to the original terminal. It works for most of the data except for the "writing-readme" set.

@djnalluri
Copy link
Author

Let me know if any of the approaches I took don't seem like the right direction. I added a small custom RGB implementation for termenv.Color to work around termenv losing accuracy in floating point math. It improves reproducibility but breaks the golden-based tests.

@djnalluri
Copy link
Author

I've moved the termenv.Color workaround to not affect existing behavior so now all the golden tests work again.

@vito
Copy link
Owner

vito commented Nov 21, 2024

Thanks for keeping this alive - sorry I haven't had time to review yet, haven't forgotten! (The tab remains open...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants