terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Preserve the cursor row during Clear Buffer

Open lhecker opened this issue 5 months ago • 2 comments

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 ✅

lhecker avatar May 28 '25 14:05 lhecker

wow, we actually have tests that this caused to fail!

DHowett avatar May 28 '25 18:05 DHowett

Still broke during tests (and now audit! may need to merge main)

DHowett avatar Jun 17 '25 17:06 DHowett

oh you merged main. alas

DHowett avatar Jun 17 '25 17:06 DHowett

PowerShell and CMD both resume writing input at the old cursor position after we clear the buffer this way:

image

DHowett avatar Jun 17 '25 17:06 DHowett

Clearing the buffer this way after the viewport scrolls down results in a loss of the prompt:

WindowsTerminal_NcoNMNUI7c

DHowett avatar Jun 17 '25 17:06 DHowett

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.

lhecker avatar Jun 17 '25 17:06 lhecker

That's already the case before this PR, though.

Huh. Was it the case before 1.22/the conPTY rewrite?

DHowett avatar Jun 17 '25 17:06 DHowett

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.

lhecker avatar Jun 17 '25 22:06 lhecker

/azp run

lhecker avatar Jun 18 '25 15:06 lhecker

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jun 18 '25 15:06 azure-pipelines[bot]

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.

j4james avatar Jun 25 '25 01:06 j4james

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…

lhecker avatar Jun 25 '25 01:06 lhecker