-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Update Clear-Host to simply call [Console]::Clear() on all platforms and remove clear alias on Unix systems
#8603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ar` alias from Unix
e878053 to
8e5e5fe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@SteveL-MSFT Please reword the PR description. We are not "removing on non-Windows" but "restoring on Windows". |
|
@SteveL-MSFT, while we're at it, perhaps we can make the function an advanced one so that it doesn't quietly accept and ignore arbitrary arguments (even though none of the common parameters make sense). E.g, the following is currently quietly accepted: Clear-Host -NoSuchParam |
|
@mklement0 What benefits we get? |
|
The benefit is an abstract, general one, for consistency and predictability: Don't make any command accept parameters that it is not designed to accept; in particular, don't make it quietly ignore such parameters. |
|
In general I would think it best practice for any "official" functions be thoroughly implemented, as @mklement0 says. It sets a bad example if we go around including low-quality code in official distributions, and it goes against years of best practices to widely distribute a function that quietly ignores arbitrary parameters. |
|
@iSazonov not sure what you mean by "restoring on Windows" since prior to this PR, the @mklement0 personally, I think we can consider extending |
|
@SteveL-MSFT Sorry, I lost the context. |
| & (Get-Command -CommandType Application clear | Select-Object -First 1).Definition | ||
| return @" | ||
| [Console]::Clear() | ||
| # .Link |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't going to work for non-console hosts like ISE, VSCode(?) and remoting. On those platforms, you still need to use the $RawUI portability APIs. A nice solution would be to actually add a new RawUI.Clear() API and then implement that using Console.Clear() in the console host but that may end up being a bunch of work...
PR Summary
Based on @PowerShell/powershell-committee decision, standardizing on
[Console]::Clear()on all platforms and removingclearalias on non-Windows.Fix #8554
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests