Skip to content

'clear' should leverage tput reset on *nix #8554

Closed
softagram/PowerShell
#4

Description

Summary of the new feature/enhancement

As as user, I want the same 'clear' experience in PowerShell on *nix, as I have in Windows. Currently, if I use 'clear' in Windows, this clears the buffer. Currently, in *nix, it appears to create a gap of blank lines and leaves the buffer mostly intact; so, I can scroll up to see the history.

I believe that this is because pwsh is leveraging terminal and when clear is input by the user, it is passed to the terminal. However, the behaviour one would expect should be the equivalent of 'tput reset' in the terminal window - as this would be the same experience seen in PowerShell in Windows.

Proposed technical implementation details (optional)

Instead of allowing 'clear' to pass to the terminal, translate the command to 'tput reset' and pass that to the terminal.

Activity

  1. SteveL-MSFT commented on Dec 28, 2018

    @SteveL-MSFT
    Member

    Clear-Host is just a function that calls the clear application. I don't see any reason not to change it to call tput reset instead as it would be consistent with Windows.

  2. SteveL-MSFT commented on Dec 28, 2018

    @SteveL-MSFT
    Member

    Interestingly, on macOS, tput reset doesn't clear the scrollback buffer. However, if I follow it with "`e[3J" to explicitly clear the scrollback buffer, I believe the result is the desired behavior. cc Michael Klement (@mklement0) who is more of an expert on this

  3. mklement0 commented on Dec 28, 2018

    @mklement0
    Contributor

    To get a consistent clear-screen-and-scrollback-buffer experience, I suggest using tput clear; $host.ui.Write("`e[3J"), as suggested in my review comments - this works with both iTerm2.app and Terminal.app on macOS and the standard terminal app on Ubuntu.

    That said: While consistency across platforms is nice, do note that macOS / Linux users may expect the scrollback buffer NOT to be cleared with clear, given that's what the native /usr/bin/clear utility does.

    So I wonder whether we should simply defer to the native utility on Unix-like platforms (i.e., remove the alias on Unix-like platforms).

    If we do that, users who want the Windows clear-screen-and-scrollback-buffer behavior on Unix must - as they currently do:

    • use tput reset on Ubuntu
    • use keyboard shortcut Command-K on macOS (both iTerm2.app and Terminal.app), because on macOS tput reset only clears the screen, without clearing the scrollback buffer.
  4. mklement0 commented on Dec 28, 2018

    @mklement0
    Contributor

    Assuming that cls is also an alias for Clear-Host currently, we could use that selectively to implement the clear-screen-and-buffer logic on Unix, while making clear defer to the native utility

  5. SteveL-MSFT commented on Dec 28, 2018

    @SteveL-MSFT
    Member

    Michael Klement (@mklement0) you make a good point that Unix users may expect the scroll back buffer not to be cleared since that is the default behavior of clear. Removing the clear alias might be the right thing to do while having cls aliased to clear-host which clears the scrollback buffer to have consistency with Windows.

  6. SteveL-MSFT commented on Jan 7, 2019

    @SteveL-MSFT
    Member

    @PowerShell/powershell-committee reviewed this and agrees to remove clear alias on non-Windows, but the cmdlet should only be calling [Console]::Clear() and depend on .NET CoreFX to do the "right thing" which is currently terminal specific.

  7. added
    Committee-ReviewedPS-Committee has reviewed this and made a decision
    and removed
    Review - CommitteeThe PR/Issue needs a review from the PowerShell Committee
    on Jan 7, 2019
  8. mklement0 commented on Jan 8, 2019

    @mklement0
    Contributor

    Steve Lee (@SteveL-MSFT): It would still be nice to at least allow opt-in via a switch to also clearing the scrollback buffer on Unix-like platforms - please see #8606

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Enhancementthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.WG-Cmdletsgeneral cmdlet issues

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions