terminal
terminal copied to clipboard
Preserve the cursor row during Clear Buffer
Introduces an ABI change to the ConptyClearPseudoConsole signal. Otherwise, we have to make it so that the API call always retains the row the cursor is on, but I feel like that makes it worse.
Closes #18732 Closes #18878
Validation Steps Performed
- Launch
ConsoleMonitor.exe - Create some text above & below the cursor in PowerShell
- Clear Buffer
- Buffer is cleared except for the cursor row ✅
- ...same in ConPTY ✅
wow, we actually have tests that this caused to fail!
Still broke during tests (and now audit! may need to merge main)
oh you merged main. alas
PowerShell and CMD both resume writing input at the old cursor position after we clear the buffer this way:
Clearing the buffer this way after the viewport scrolls down results in a loss of the prompt:
Right, forgot about the tests.
PowerShell and CMD both resume writing input at the old cursor position after we clear the buffer this way:
That's already the case before this PR, though.
That's already the case before this PR, though.
Huh. Was it the case before 1.22/the conPTY rewrite?
Huh. Was it the case before 1.22/the conPTY rewrite?
No, I mean just before this PR, on main. It did work in 1.21 because the CMD prompt relied heavily on the conhost TextBuffer. PowerShell 5 is broken in 1.21 too, though.
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
FWIW, it still destroys the content of the line when it is the last line on the screen.
This is the off-by-one error I mentioned in the branch here:
// Erase any viewport contents below (but not including) the cursor row.
if (viewport.Height() - cursor.y > 0)
I think that test should be viewport.Height() - cursor.y > 1.
Oh that's how to repro the off-by-one issue. Duh. It's really obvious in hindsight. Even though you (j4james) described it correctly, I misunderstood it as "doesn't clear the last line of the viewport" somehow. Too much context switching. 🫠
Edit: Ironically I even rewrote the if condition so I could use > 1 and then promptly forgot about it…