Skip to content

Commit

Permalink
Make sure conpty is flushed before clearing scrollback (#13324)
Browse files Browse the repository at this point in the history
## Summary of the Pull Request

When you execute a `cls` in the cmd shell, or `Clear-Host` in
PowerShell, we have a pair of shims that attempt to detect those
operations and forward an `ED3` sequence to conpty to clear the
scrollback.

If there was a linefeed at the bottom of the viewport immediately 
prior to those functions being called, that event might still be
pending, and only forwarded to conpty after the `ED3`. The result
then is a line pushed into the scrollback that shouldn't be there.

This PR tries to avoid that situation by forcing the renderer to
flush before the `ED3` sequence is sent.

## References

The `cls` and `Clear-Host` shims were originally added in PR #5627.

## PR Checklist
* [x] Closes #5770
* [x] Closes #13320
* [x] CLA signed.
* [ ] Tests added/passed
* [ ] Documentation updated.
* [ ] Schema updated.
* [ ] I've discussed this with core contributors already. If not
checked, I'm ready to accept this work might be rejected in favor of a
different grand plan. Issue number where discussion took place: #xxx

## Validation Steps Performed

I've manually tested in PowerShell with `echo Hello; Clear-Host` (this
is the only way I could reliably reproduce the original problem), and in
the cmd shell with `cls`. Both cases are now working as expected.
  • Loading branch information
j4james authored Jun 20, 2022
1 parent a5fb91d commit 08c2f35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/host/_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ void WriteToScreen(SCREEN_INFORMATION& screenInfo, const Viewport& region)

if (wroteWholeBuffer && startedAtOrigin && wroteSpaces)
{
// It's important that we flush the renderer at this point so we don't
// have any pending output rendered after the scrollback is cleared.
ServiceLocator::LocateGlobals().pRender->TriggerFlush(false);
hr = gci.GetVtIo()->ManuallyClearScrollback();
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/host/getset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,9 @@ void ApiRoutines::GetLargestConsoleWindowSizeImpl(const SCREEN_INFORMATION& cont

if (sourceIsWholeBuffer && targetIsNegativeBufferHeight && noClipProvided && fillIsBlank)
{
// It's important that we flush the renderer at this point so we don't
// have any pending output rendered after the scrollback is cleared.
ServiceLocator::LocateGlobals().pRender->TriggerFlush(false);
hr = gci.GetVtIo()->ManuallyClearScrollback();
}
}
Expand Down

0 comments on commit 08c2f35

Please sign in to comment.