You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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
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.
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
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.
@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.
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
Activity
SteveL-MSFT commentedon Dec 28, 2018
Clear-Hostis just a function that calls theclearapplication. I don't see any reason not to change it to calltput resetinstead as it would be consistent with Windows.SteveL-MSFT commentedon Dec 28, 2018
Interestingly, on macOS,
tput resetdoesn'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 thismklement0 commentedon Dec 28, 2018
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/clearutility 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:
tput reseton Ubuntutput resetonly clears the screen, without clearing the scrollback buffer.mklement0 commentedon Dec 28, 2018
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
cleardefer to the native utilitySteveL-MSFT commentedon Dec 28, 2018
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 theclearalias might be the right thing to do while havingclsaliased toclear-hostwhich clears the scrollback buffer to have consistency with Windows.SteveL-MSFT commentedon Jan 7, 2019
@PowerShell/powershell-committee reviewed this and agrees to remove
clearalias 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.mklement0 commentedon Jan 8, 2019
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