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

Closed
opened 2026-01-31 08:15:06 +00:00 by claunia · 5 comments
Owner

Originally created by @BDisp on GitHub (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

Originally created by @BDisp on GitHub (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](https://github.com/microsoft/terminal/issues/5094#issuecomment-2455818231)_
claunia added the Needs-TriageIssue-BugNeeds-Tag-FixNeeds-Attention labels 2026-01-31 08:15:07 +00:00
Author
Owner

@BDisp commented on GitHub (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 https://github.com/gui-cs/Terminal.Gui/pull/3768 the buffer size always reflects the window size but not the scroll bar.

Image

@BDisp commented on GitHub (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 https://github.com/gui-cs/Terminal.Gui/pull/3768 the buffer size always reflects the window size but not the scroll bar. ![Image](https://github.com/user-attachments/assets/1f066327-1cc2-4535-a029-aab86acf6af2)
Author
Owner

@BDisp commented on GitHub (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.

@BDisp commented on GitHub (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.
Author
Owner

@lhecker commented on GitHub (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 commented on GitHub (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.
Author
Owner

@lhecker commented on GitHub (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 commented on GitHub (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.
Author
Owner

@BDisp commented on GitHub (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.

@BDisp commented on GitHub (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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#22495