[PR #5294] [MERGED] Emit lines wrapped due to spaces at the end correctly #26239

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/5294
Author: @zadjii-msft
Created: 4/9/2020
Status: Merged
Merged: 4/15/2020
Merged by: @undefined

Base: masterHead: dev/migrie/5291-vim-is-horrible


📝 Commits (10+)

  • f50bf15 add a test for #5291, and a theory on why it's busted
  • 54942c3 Well touching conhost is always terrifying
  • 12018e4 Bet you could spae this coming
  • f0f5b0c Merge remote-tracking branch 'origin/master' into dev/migrie/5291-vim-is-horrible
  • 238e61d Add a \r\n case to this test as well, why not
  • 6ea74d6 Hey lets do it this way too, just to make sure
  • 297fcea This is a more acceptable abbreviation
  • cb01398 more test cases for dustin
  • 8284bfb Merge remote-tracking branch 'origin/master' into dev/migrie/5291-vim-is-horrible
  • 1a9fa14 I guess I didn't have to touch the host bits of conhost at all

📊 Changes

4 files changed (+199 additions, -21 deletions)

View changed files

📝 .github/actions/spell-check/dictionary/dictionary.txt (+0 -16)
📝 src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp (+173 -0)
📝 src/host/screenInfo.cpp (+13 -0)
📝 src/renderer/vt/paint.cpp (+13 -5)

📄 Description

Summary of the Pull Request

When WSL vim prints the initial empty buffer (the one that's just a bunch of '~'s), it prints this by doing the following:

  • Print '~' followed by enough spaces to clear the line
  • Use CUP (^[[H) to move the cursor to the start of the next line
  • repeat until the buffer is full

When we'd get the line of "~ "... in conhost, we'd mark that line as wrapped.

Logically, it doesn't really make any sense that when we follow that up by moving the cursor, the line is wrapped. However, this is just how conhost is right now.
This wasn't ever a problem in just conhost before, because we really didn't care if lines in the alt buffer were "wrapped" or not. Plus, when vim would get resized, it would just reprint it's own buffer anyways. Nor was this a problem in conpty before this year (2020). We've only just recently added logic to conpty to try and preserve wrapped lines.

Initially, I tried fixing this by breaking the line manually when the cursor was moved. This seemed to work great, except for the win32 vim.exe. Vim.exe doesn't emit a newline or a CUP to get to the next line. It just goes for it and keeps printing. So there's no way for us to know the line broke, because they're essentially just printing one long line, assuming we'll automatically move the cursor.

So instead, I'm making sure to emit the proper number of spaces at the end of a line when the line is wrapped. We won't do any funny business in that scenario and try to optimize for them, we'll just print the spaces.

References

  • #5181 - This change regressed this
  • #4415 - Actually implemented wrapped lines in conpty

PR Checklist

Validation Steps Performed

  • Wrote a unittest first and foremost
  • Checked vtpipeterm to make sure vim still works
  • checked Terminal to make sure vim still works

🔄 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/5294 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 4/9/2020 **Status:** ✅ Merged **Merged:** 4/15/2020 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `dev/migrie/5291-vim-is-horrible` --- ### 📝 Commits (10+) - [`f50bf15`](https://github.com/microsoft/terminal/commit/f50bf1576e83a4b16d16a9328670eccb76e6aa89) add a test for #5291, and a theory on why it's busted - [`54942c3`](https://github.com/microsoft/terminal/commit/54942c3e00106f9d539dcc0d6c5d3c77b3ba5fc9) Well touching conhost is always terrifying - [`12018e4`](https://github.com/microsoft/terminal/commit/12018e40c58195f51845e9ff16b840fb5be34597) Bet you could spae this coming - [`f0f5b0c`](https://github.com/microsoft/terminal/commit/f0f5b0c2151a481c543a30f7e6ce6d749932b404) Merge remote-tracking branch 'origin/master' into dev/migrie/5291-vim-is-horrible - [`238e61d`](https://github.com/microsoft/terminal/commit/238e61d16dc6c160fecd550a46a744563031eb0a) Add a \r\n case to this test as well, why not - [`6ea74d6`](https://github.com/microsoft/terminal/commit/6ea74d6f35070bc0e868fede3b458cd39d1acb62) Hey lets do it this way too, just to make sure - [`297fcea`](https://github.com/microsoft/terminal/commit/297fceabe1291c3808d545550ad6a15c6ada9eb7) This is a more acceptable abbreviation - [`cb01398`](https://github.com/microsoft/terminal/commit/cb013988a30eb5eca7892de2af24e98e37c57d57) more test cases for dustin - [`8284bfb`](https://github.com/microsoft/terminal/commit/8284bfb96aaece7b2a0b8ecc870cac66bb860453) Merge remote-tracking branch 'origin/master' into dev/migrie/5291-vim-is-horrible - [`1a9fa14`](https://github.com/microsoft/terminal/commit/1a9fa14de7c30e78ace05df409e8ea3f24ed3c57) I guess I didn't have to touch the _host_ bits of conhost at all ### 📊 Changes **4 files changed** (+199 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `.github/actions/spell-check/dictionary/dictionary.txt` (+0 -16) 📝 `src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp` (+173 -0) 📝 `src/host/screenInfo.cpp` (+13 -0) 📝 `src/renderer/vt/paint.cpp` (+13 -5) </details> ### 📄 Description ## Summary of the Pull Request When WSL vim prints the initial empty buffer (the one that's just a bunch of '\~'s), it prints this by doing the following: * Print '\~' followed by enough spaces to clear the line * Use CUP (`^[[H`) to move the cursor to the start of the next line * repeat until the buffer is full When we'd get the line of "\~ "... in conhost, we'd mark that line as wrapped. Logically, it doesn't really make any sense that when we follow that up by moving the cursor, the line is wrapped. However, this is just how conhost is right now. This wasn't ever a problem in just conhost before, because we really didn't care if lines in the alt buffer were "wrapped" or not. Plus, when vim would get resized, it would just reprint it's own buffer anyways. Nor was this a problem in conpty before this year (2020). We've only just recently added logic to conpty to try and preserve wrapped lines. Initially, I tried fixing this by breaking the line manually when the cursor was moved. This seemed to work great, except for the win32 vim.exe. Vim.exe doesn't emit a newline or a CUP to get to the next line. It just _goes for it_ and keeps printing. So there's _no way_ for us to know the line broke, because they're essentially just printing one long line, assuming we'll automatically move the cursor. So instead, I'm making sure to emit the proper number of spaces at the end of a line when the line is wrapped. We won't do any funny business in that scenario and try to optimize for them, we'll _just print the spaces_. ## References * #5181 - This change regressed this * #4415 - Actually implemented wrapped lines in conpty ## PR Checklist * [x] Closes #5291 * [x] I work here * [x] Tests added/passed * [n/a] Requires documentation to be updated ## Validation Steps Performed * Wrote a unittest first and foremost * Checked vtpipeterm to make sure vim still works * checked Terminal to make sure vim still works --- <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:14:51 +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#26239