-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Update:
The decision in #8603 to rely on Console.Clear() amounts to inconsistent behavior across platforms, for no good reason (there's no native behavior that needs to be emulated; native behavior, if desired, is accessible via the external clear utility).
If there's consensus that the desired behavior is to consistently clear the screen and the scrollback buffer on all platforms, we have two options:
-
Wait for
Console.Clear()to be fixed, if ever - see https://github.com/dotnet/corefx/issues/34463 -
Roll our own solution in PowerShell [in the meantime].
The original proposal below was written under the assumption that platform-dependent behavior was intended, and therefore suggested an opt-in mechanism.
Summary of the new feature/enhancement
Implement a switch named -All to direct Clear-Host to clear not only the current screen of terminal (console) hosts but to clear the scrollback buffer (the output history) as well.
Clear-Host now uses [Console]::Clear() (see #8603), which results in platform-specific behavior:
- Unix-like platforms: clears the current screen (terminal-window content) only.
- Windows: clears the current screen and the scroll-back buffer.
That is, also clearing the scrollback buffer is invariably implied on Windows, whereas it is currently unavailable on Unix-like platforms.
Implementing -All would allow users to at least opt into a consistent cross-platform experience, e.g. via a user-defined function such as function clsa { Clear-Host -All }.
Note: As before, this means that in the Windows console you do not have the option to selectively clear the current screen only, without erasing the scrollback buffer.
Proposed technical implementation details (optional)
If -All is specified:
- on Windows: do nothing, because clearing the scrollback buffer is invariably performed anyway.
- on Unix-like platforms, execute
$host.ui.Write("`e[3J")after[Console]::Clear()to also clear the scrollback buffer.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status