[PR #5771] Fix wrapped lines in less in Git for Windows #26461

Open
opened 2026-01-31 09:16:14 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/5771

State: closed
Merged: Yes


Summary of the Pull Request

This PR resolves an issue with the Git for Windows (MSYS) version of less. It doesn't use VT processing for emitting text tothe buffer, so when it hits WriteCharsLegacy, WC_DELAY_EOL_WRAP is NOT set.

When this happens, less is writing some text that's longer than the width of the buffer to the last line of the buffer. We're hitting the

    Status = AdjustCursorPosition(screenInfo, CursorPosition, WI_IsFlagSet(dwFlags, WC_KEEP_CURSOR_VISIBLE), psScrollY);

call in _stream.cpp:560.

The cursor is currently at {40, 29}, the start of the run of text that wrapped. We're trying to adjust it to {0, 30}, which would be the start of the next line of the buffer. However, the buffer is only 30 lines tall, so we've got to IncrementCircularBuffer first, so we can move the cursor there.

When that happens, we're going to paint frame. At the end of that frame, we're going to try and paint the cursor position. The cursor is still at {40, 29} here, so unfortunately, the cursorIsInDeferredWrap check in XtermEngine::PaintCursor is false. That means, conpty is going to try to move the cursor to where the console thinks the cursor actually is at the end of this frame, which is {40, 29}.

If we're painting the frame because we circled the buffer, then the cursor might still be in the position it was before the text was written to the buffer to cause the buffer to circle. In that case, then we DON'T want to paint the cursor here either, because it'll cause us to manually break this line. That's okay though, the frame will be painted again, after the circling is complete.

PR Checklist

Detailed Description of the Pull Request / Additional comments

I suppose that's the detailed description above

Validation Steps Performed

  • ran tests
  • checked that the bug was actually fixed in the Terminal
**Original Pull Request:** https://github.com/microsoft/terminal/pull/5771 **State:** closed **Merged:** Yes --- ## Summary of the Pull Request This PR resolves an issue with the Git for Windows (MSYS) version of `less`. It _doesn't_ use VT processing for emitting text tothe buffer, so when it hits `WriteCharsLegacy`, `WC_DELAY_EOL_WRAP` is NOT set. When this happens, `less` is writing some text that's longer than the width of the buffer to the last line of the buffer. We're hitting the ```c++ Status = AdjustCursorPosition(screenInfo, CursorPosition, WI_IsFlagSet(dwFlags, WC_KEEP_CURSOR_VISIBLE), psScrollY); ``` call in `_stream.cpp:560`. The cursor is _currently_ at `{40, 29}`, the _start_ of the run of text that wrapped. We're trying to adjust it to `{0, 30}`, which would be the start of the next line of the buffer. However, the buffer is only 30 lines tall, so we've got to `IncrementCircularBuffer` first, so we can move the cursor there. When that happens, we're going to paint frame. At the end of that frame, we're going to try and paint the cursor position. The cursor is still at `{40, 29}` here, so unfortunately, the `cursorIsInDeferredWrap` check in `XtermEngine::PaintCursor` is `false`. That means, conpty is going to try to move the cursor to where the console thinks the cursor actually is at the end of this frame, which is `{40, 29}`. If we're painting the frame because we circled the buffer, then the cursor might still be in the position it was before the text was written to the buffer to cause the buffer to circle. In that case, then we DON'T want to paint the cursor here either, because it'll cause us to manually break this line. That's okay though, the frame will be painted again, after the circling is complete. ## PR Checklist * [x] Closes #5691 * [x] I work here * [x] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments I suppose that's the detailed description above ## Validation Steps Performed * ran tests * checked that the bug was actually fixed in the Terminal
claunia added the pull-request label 2026-01-31 09:16:14 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#26461