如何在Powershell控制台中更改光标位置 [英] How to change cursor position in powershell console
问题描述
我目前将当前CursorPosition分配给Powershell中的一个变量,以便在执行倒数计时时可以覆盖相同的空间,例如在脚本中,如下所示:
I currently assign the current CursorPosition to a variable in Powershell so that I can overwrite the same space when performing a count down for example in a script, as below:
$errorPos = $host.UI.RawUI.CursorPosition
for ($i=5; $i -ge 0; $i--) {
$host.UI.RawUI.CursorPosition = $errorPos
Write-Host -NoNewline -BackgroundColor Yellow -ForegroundColor Black "$i"
Start-Sleep -Seconds 1
}
我想做的事情,它使用光标的当前位置并将其向前移动两个空格,然后将其分配给另一个变量。我可以使用:
What I'd like to do, it take the current position of the cursor and move it forward two spaces, then assign it to another variable. I could just use:
write-host " "
,但我不想覆盖当前占用该空间的文本。
but I don't want to overwrite the text currently occupying that space.
我认为可以使用X和Y合作,但并没有取得太大的成功。
I think it can be accomplished using X and Y co ords but am not having much success.
感谢您的协助。.
推荐答案
如果只想将'X'向前移动2,则只需在创建 errorPos
变量后执行此操作:
If you just want to move the 'X' forward by 2 you can just do this after creating your errorPos
variable:
$errorPos.X += 2
您可以使用 $ errorPos.X
和 .Y
直接修改变量。
You can modify the variable directly by using $errorPos.X
and .Y
.
这篇关于如何在Powershell控制台中更改光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!