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

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/5771
Author: @zadjii-msft
Created: 5/6/2020
Status: Merged
Merged: 5/8/2020
Merged by: @undefined

Base: masterHead: dev/migrie/b/5691-git_log_--pretty=oneline


📝 Commits (10+)

  • 5a41175 This should be a test for #5691 but they must implement scrolling weirdly
  • b5ba084 Huh, WriteCharsLegacy doesn't seemt to repro it...
  • 35e7779 These are useful test util helpers
  • 68230dc I tried to do a scrolling thing here, but I think that wasn't it
  • 66b80d9 I can't explain it, but only metadataSet5 fails in this version of the test. That's all we need, but man that's just weird
  • 84e2c20 um what the heck
  • da3aba4 Clean this test up. This test does catch a real regression, but it's definitely not the one that is actually reported in the bug. I'm gonna start fresh.
  • 576fa5b Again, this should be a test for this case. Why isn't it?
  • d438f29 Could this finally be a test for #5691??
  • 9f5a62d Holy crap, this fixed it

📊 Changes

5 files changed (+421 additions, -13 deletions)

View changed files

📝 .github/actions/spell-check/whitelist/alphabet.txt (+1 -0)
📝 src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp (+399 -0)
📝 src/cascadia/UnitTests_TerminalCore/TestUtils.h (+13 -0)
📝 src/renderer/vt/XtermEngine.cpp (+8 -2)
📝 src/renderer/vt/paint.cpp (+0 -11)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/5771 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 5/6/2020 **Status:** ✅ Merged **Merged:** 5/8/2020 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `dev/migrie/b/5691-git_log_--pretty=oneline` --- ### 📝 Commits (10+) - [`5a41175`](https://github.com/microsoft/terminal/commit/5a41175dac9e8407007061dfd7fff70d67d7b1ef) This _should_ be a test for #5691 but they must implement scrolling weirdly - [`b5ba084`](https://github.com/microsoft/terminal/commit/b5ba084b3b13876e3bfd8d9e030f6c0c3dfb03fc) Huh, WriteCharsLegacy doesn't seemt to repro it... - [`35e7779`](https://github.com/microsoft/terminal/commit/35e7779223ae5e49343a8d0b290de5254431dbe4) These are useful test util helpers - [`68230dc`](https://github.com/microsoft/terminal/commit/68230dc99118dd9fd36e295cb52db84ed5976a6a) I tried to do a scrolling thing here, but I think that wasn't it - [`66b80d9`](https://github.com/microsoft/terminal/commit/66b80d9abb8000e5f54c95bc5dd857ca9f94bd58) I can't explain it, but only metadataSet5 fails in this version of the test. That's all we need, but man that's just weird - [`84e2c20`](https://github.com/microsoft/terminal/commit/84e2c201ad189d004fe9a6cb5f392b92dcd0672c) um what the heck - [`da3aba4`](https://github.com/microsoft/terminal/commit/da3aba456611bcf81b679919cb91d6752ad78624) Clean this test up. This test does catch a real regression, but it's definitely not the one that is actually reported in the bug. I'm gonna start fresh. - [`576fa5b`](https://github.com/microsoft/terminal/commit/576fa5b2ddc4c75052873dfb493dcb99e930ecd9) Again, this should be a test for this case. Why isn't it? - [`d438f29`](https://github.com/microsoft/terminal/commit/d438f295595605b838a0e1fa9319353b073bb09c) Could this finally be a test for #5691?? - [`9f5a62d`](https://github.com/microsoft/terminal/commit/9f5a62d6febf047f3b249155499bb1b1c6c13c37) Holy crap, this fixed it ### 📊 Changes **5 files changed** (+421 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `.github/actions/spell-check/whitelist/alphabet.txt` (+1 -0) 📝 `src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp` (+399 -0) 📝 `src/cascadia/UnitTests_TerminalCore/TestUtils.h` (+13 -0) 📝 `src/renderer/vt/XtermEngine.cpp` (+8 -2) 📝 `src/renderer/vt/paint.cpp` (+0 -11) </details> ### 📄 Description ## 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:16:13 +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#26456