Clear-Host does not clear the entire Windows Terminal contents #18395

Closed
opened 2026-01-31 06:12:35 +00:00 by claunia · 5 comments
Owner

Originally created by @theJasonHelmick on GitHub (Sep 7, 2022).

Windows Terminal version

No response

Windows build number

10.0.22000.0

Other Software

No response

Steps to reproduce

Please see https://github.com/PowerShell/PowerShell/issues/15432

After terminating Rick-roll, clear-host should clear the terminal, but does not.

Expected Behavior

Clear-Host to clear the terminal

Actual Behavior

Does not clear

Originally created by @theJasonHelmick on GitHub (Sep 7, 2022). ### Windows Terminal version _No response_ ### Windows build number 10.0.22000.0 ### Other Software _No response_ ### Steps to reproduce Please see https://github.com/PowerShell/PowerShell/issues/15432 After terminating Rick-roll, clear-host should clear the terminal, but does not. ### Expected Behavior Clear-Host to clear the terminal ### Actual Behavior Does not clear
claunia added the Issue-BugResolution-Duplicate labels 2026-01-31 06:12:35 +00:00
Author
Owner

@DHowett commented on GitHub (Sep 7, 2022):

Hmm. @theJasonHelmick are you using PowerShell installed as a dotnet global tool?

@DHowett commented on GitHub (Sep 7, 2022): _Hmm._ @theJasonHelmick are you using PowerShell installed as a `dotnet global` tool?
Author
Owner

@daxian-dbw commented on GitHub (Sep 8, 2022):

@DHowett The root cause is that calling SetConsoleWindowInfo to change the window size doesn't work in Windows Terminal.

A simple repro can be found at https://github.com/PowerShell/PowerShell/issues/15432#issuecomment-846295116. It attempts to change the windows size by setting $host.UI.RawUI.WindowSize in PowerShell. The setter of that WindowSize property calls into the SetConsoleWindowInfo to change the window size, which works in console host, but not in Windows Terminal.

In Windows Terminal, after calling SetConsoleWindowInfo, it turns out the .NET Console.BufferHeight, Console.BufferWidth, Console.WindowHeight, and WindowWidth all reflect the specified value, but the Windows Terminal window doesn't change, and that causes the text on the exceeding part of the window to linger around and cannot be cleared. Here is a screenshot to demonstrate the problem:

image

@daxian-dbw commented on GitHub (Sep 8, 2022): @DHowett The root cause is that calling [SetConsoleWindowInfo](https://docs.microsoft.com/en-us/windows/console/setconsolewindowinfo) to change the window size doesn't work in Windows Terminal. A simple repro can be found at https://github.com/PowerShell/PowerShell/issues/15432#issuecomment-846295116. It attempts to change the windows size by setting `$host.UI.RawUI.WindowSize` in PowerShell. The setter of that `WindowSize` property calls into the `SetConsoleWindowInfo` to change the window size, which works in console host, but not in Windows Terminal. In Windows Terminal, after calling `SetConsoleWindowInfo`, it turns out the .NET `Console.BufferHeight`, `Console.BufferWidth`, `Console.WindowHeight`, and `WindowWidth` all reflect the specified value, but the Windows Terminal window doesn't change, and that causes the text on the exceeding part of the window to linger around and cannot be cleared. Here is a screenshot to demonstrate the problem: ![image](https://user-images.githubusercontent.com/127450/189005314-38c3aac0-6f28-4032-8e0d-0ce428b3709f.png)
Author
Owner

@j4james commented on GitHub (Sep 8, 2022):

The root cause is that calling SetConsoleWindowInfo to change the window size doesn't work in Windows Terminal.

That's essentially issue #5094.

@j4james commented on GitHub (Sep 8, 2022): > The root cause is that calling [SetConsoleWindowInfo](https://docs.microsoft.com/en-us/windows/console/setconsolewindowinfo) to change the window size doesn't work in Windows Terminal. That's essentially issue #5094.
Author
Owner

@zadjii-msft commented on GitHub (Sep 8, 2022):

Oh yea, for sure. /dup #5094

@zadjii-msft commented on GitHub (Sep 8, 2022): Oh yea, for sure. /dup #5094
Author
Owner

@ghost commented on GitHub (Sep 8, 2022):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost commented on GitHub (Sep 8, 2022): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#18395