4 ms·
If you're using PowerShell Core, add the following to Documents\PowerShell\Profile.ps1. If you're using legacy PowerShell, add it to Documents\PowerShell\Micro
by zenexer 7y ago
If you're using PowerShell Core, add the following to Documents\PowerShell\Profile.ps1. If you're using legacy PowerShell, add it to Documents\PowerShell\Microsoft.PowerShell_profile.ps1 instead.
Remove-Alias cls
function cls {
echo "$([char]27)c"
}
A similar solution was provided in the GitHub issue that works on older versions of Windows Terminal.
- recursive 7y agoI don't know if I'm using "Legacy" Powershell. `(Get-Host).Version` reports 5.1.18362.145. I added your workaround to both .ps1 files. It doesn't change any behavior in any obvious way. Even if it did, it's still a work-around at best. If this actually worked, I can't imagine a reason this shouldn't be built in to the product. But I really don't think it works. Regardless of whether any of these profile scripts are taking effect, invoking `echo "$([char]27)c"` directly also doesn't clear the scroll history, so I doubt it would even work even if I could figure out how create a profile script. I did notice that there were a number of other proposed work-arounds in the github thread. Each one of them seems to have some feedback saying that it doesn't work. In my opinion, this is shortcoming of this product.
- zenexer 7y agoIt looks like others have already given you long explanations of why PowerShell works this way. Nevertheless, the behavior you're describing can still be desirable at times. In the future, the following will probably work: echo "$([char]27)[3J$([char]27)[H$([char]27)[2J" This matches the output from `tput clear` in WSL. However, as of writing, it's a bit quirky when combined with other PowerShell commands; for example, the following behaves oddly: ls; echo "$([char]27)[3J$([char]27)[H$([char]27)[2J"; ls Unfortunately, I don't have a good solution at the moment.
- recursive 7y agoTo be honest, it's pretty much all over my head. I'm just a simple man, trying to clear my console. The only way to do it seems to be completely restart it, which I guess is ok, but certainly inconvenient. I'll probably check back in on Microsoft Terminal in a few months and see if any of the terminal wizards have discovered a way to clear the console.
- JdeBP 7y agoUsing the RIS control sequence is a bad idea. Its long-standing functionality has included completely resetting the serial communications at the terminal end. ED (Erase Display) is the control sequence to use for clearing the screen in systems with a terminal I/O paradigm. Emit it twice, as ED 2 to clear the whole main screen and as ED 3 to separately clear the scrollback buffer. * http://jdebp.uk./FGA/clearing-the-tui-screen.html http://jdebp.uk./FGA/clearing-the-tui-screen.html
- zenexer 7y agoNormally it's not what I'd use, but Windows Terminal still has some quirks. It was the only thing that seemed to work reliably. However, now that I've done additional testing, even that doesn't seem to work reliably. Keep in mind that the context here is finding a workaround for a specific terminal emulator. Very cool link and bit of history, though!
- JdeBP 7y agoThe workaround, which isn't really a workaround at all because it's the standard way of doing this (plus a fairly modest common extension that we terminal emulator authors have mostly agreed upon), has already been found. The Microsoft people in the GitHub issue said to use ED 2 and ED 3, as well. I merely additionally explained why your doing something that they did not suggest is wrong, not only for the reasons that the Microsoft people already said, but for the additional reasons that it has a standard function that is not what is desired here.
- zenexer 7y agoIt doesn't work, though, as I've already explained elsewhere in the comment tree. It works in naive examples, but fails to clear at the correct time in more complex situations.