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

Reuse allocations if available when swapping alternate state #3182

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tgross35
Copy link

@tgross35 tgross35 commented Mar 5, 2024

This just does what I suggested in #1625 (comment) - instead of dropping and recreating the collections, reset them so future use doesn't need to reallocate.

Tests pass; however, I need some help figuring out what action actually exercises this code path via the binary.

@imsnif
Copy link
Member

imsnif commented Mar 6, 2024

Hey @tgross35 - thanks for looking into this! I'll try to make some time for a detailed review in the coming weeks, but for now - you can test the alternate screen either manually by sending the following ANSI codes from within a Zellij pane like so:

echo -e "\033[?1049h" # enter alternate screen
echo -e "\033[?1049l" # leave alternate screen

Or start some sort of TUI program that does this for you (eg. vim, htop, etc.)

@imsnif
Copy link
Member

imsnif commented Mar 25, 2024

Hey @tgross35 - so I'm finally getting to this, thank you for your patience!

So first, a bit of terminal lore just to make sure we're on the same page:
The alternate buffer of a terminal is often used by "full screen" terminal applications in order to render themselves on the full viewport while still preserving our terminal history when we exit them.

So when the application sends the terminal the <CSI>?1049h instruction, we save all the current terminal state, place it aside and give it a fresh new-one to render itself on (minus the scrollback since it only needs the viewport). When the application sends us the <CSI>?1049l instruction, we switch everything back - erasing the intermediate alternate buffer.

While it's technically possible to enter an alternate buffer on top of an already existing alternate buffer - I have never encountered an application that does this.

So now to these changes: it seems to me that the only occasion in which these changes will have an effect (essentially this branch being used: https://github.com/zellij-org/zellij/pull/3182/files#diff-758384aed3fe1bc47b267810b52b79e7377b5daf22cd72515710c8cd2a5f89ecR2639) is when entering an alternate buffer on top of an already existing alternate buffer. The reason being that when we leave an alternate buffer, we make sure (I hope) to drop it. This happens here:

So this leaves me with a question I hope you can help me out with: do we properly drop the alternate buffer state when leaving it?

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.

None yet

2 participants