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

Windows Terminal Preview scroll bar doesn't respect the buffer size on Windows 11. #18148

Closed
BDisp opened this issue Nov 4, 2024 · 5 comments
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Attention The core contributors need to come back around and look at this ASAP. Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting

Comments

@BDisp
Copy link

BDisp commented Nov 4, 2024

We should continue this discussion in another issue, since there are over 20 people subscribed to this one. Do you mind filing an issue? It would be great if you could include reproduction steps.

BTW: I'm also confused why you mention the need to resize the buffer. The terminal resizes the buffer for you when the window size changes. There should be no need for you to call anything (nor use CSI t) during a maximize/restore. The alternate screen buffer always has the size of the window.

Originally posted by @lhecker in #5094

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Nov 4, 2024
@lhecker lhecker added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Nov 4, 2024
@BDisp
Copy link
Author

BDisp commented Nov 4, 2024

@lhecker thanks for the clarification. Yes it's true. Now the window buffer size always have the window size, but the scroll bar doesn't reflect that. When the buffer size is equal to the window size the scroll bar size should be zero and not allowing scrolling the buffer. If use my changed branch gui-cs/Terminal.Gui#3768 the buffer size always reflects the window size but not the scroll bar.

Image

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Nov 4, 2024
@BDisp
Copy link
Author

BDisp commented Nov 4, 2024

In the WT version 1.21 the change I made to my branch is working fine only using the \x1b[?1049h and \x1b[?1049l. which in the gui-cs are named as EscSeqUtils.CSI_SaveCursorAndActivateAltBufferNoBackscroll and EscSeqUtils.CSI_RestoreCursorAndRestoreAltBufferWithBackscroll, respectively.

@lhecker
Copy link
Member

lhecker commented Nov 4, 2024

I just remembered that we had another gui-cs issues reported on us a while ago: #17949
The summary is that gui-cs has various imperfections and bugs around the usage of the Console API. One of the bugs is that it calls SetConsoleScreenBufferSize with the information gained from GetConsoleScreenBufferInfoEx without realizing that this results in an off-by-one error.

Generally speaking: Do not ever resize the buffer because the window was resized. This is true without the alternate screen-buffer but it's especially true if you do use it.

I'll continue to investigate.

@lhecker
Copy link
Member

lhecker commented Nov 5, 2024

tl;dr: When you use SetConsoleActiveScreenBuffer you leave the alternate screen-buffer.

The issue is caused due to the usage of SetConsoleActiveScreenBuffer. That function used to have a pretty much undefined (random) behavior up until 1.21. Starting 1.22 it does what it's supposed to do: It switches the console screen buffer. But doing so means that you also leave the previously set alternate screen-buffer (ASB). This causes a scrollbar to show up because you aren't in the ASB anymore.

I would recommend removing all usage of the _screenBuffer member variable. While it's possible that I misunderstood your code, I don't think it should be used in the way you're doing it. Most functions can just use _outputHandle and _inputHandle directly. I don't think I understand the purpose of ReadFromConsoleOutput. Every time it gets called, it creates an entire, new text buffer (= very very expensive) and then reads from it. This will always return whitespace because there's nothing in that new text buffer. You should probably pass the _outputHandle there.

Let me know if I can help any other way.

@lhecker lhecker added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Attention The core contributors need to come back around and look at this ASAP. labels Nov 5, 2024
@BDisp
Copy link
Author

BDisp commented Nov 5, 2024

Thank you very much. Removing the _screenBuffer variable and only using the _outputHandle variable in conjunction with the alternated screen solves the issue. I really appreciated your help. If you want please see my changed PR.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Nov 5, 2024
@BDisp BDisp closed this as completed Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Attention The core contributors need to come back around and look at this ASAP. Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting
Projects
None yet
Development

No branches or pull requests

2 participants