保留缓冲区的 Powershell Clear-Host 替代方案

krm*_*l87 5 windows powershell buffer newline

我想要像 Clear-Host 这样的东西,但想要回滚。

到目前为止,我所拥有的基本上是添加换行符,直到屏幕清晰。虽然当我这样做时,光标开始在页面底部书写(正如预期的那样 - 虽然不是需要的)。

我希望从页面顶部开始写作(对于菜单等——这是很自然的事情)

这是打印新行动态计数的代码:

do {Write-Host ""; $i++}
while ($i -ne $Host.UI.RawUI.WindowSize.Height)
Run Code Online (Sandbox Code Playgroud)

我确实看到了一些关于 Transcript 模块的内容,但不希望看到。

提前致谢。

Mik*_*ard 4

这是一行字,它准确地给出了您正在寻找的内容:

[System.Console]::SetWindowPosition(0,[System.Console]::CursorTop)
Run Code Online (Sandbox Code Playgroud)

从这里: http://tommymaynard.com/ql-clear-host-without-clearning-the-host/

链接的文章还展示了如何在函数中使用它以便在脚本中重复使用。

  • 那很完美!对于那些不想读几页的人:`[System.Console]::SetWindowPosition(0,[System.Console]::CursorTop)` (3认同)