8000 Make Clear-Host clear the scrollback buffer too on all platforms · Issue #8606 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Make Clear-Host clear the scrollback buffer too on all platforms  #8606

@mklement0

Description

@mklement0

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:

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

No one assigned

    Labels

    Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Interactive-Consolethe console experienceWaiting - DotNetCorewaiting on a fix/change in .NET

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0