專家, 我正在使用msbuild構建一個長長的Visual Studio項目列表。在隱藏msbuild輸出的同時,顯示基於某些字符的狀態和動畫,並在msbuild執行其作業時顯示。在這裏我的腳本生成使用的MSBuild和顯示的等待動畫(你一定會這樣的...):PowerShell:控制檯和SetCursorPosition中的角色動畫變得瘋狂
[email protected]("|","/","-","\","|") # Animation sequence characters
$ReturnCode = @{}
$BuildStatus="Building $(ProjectName)"
$CursorTop=[Console]::CursorTop #// Cursor position on Y axis
$CursorLeft=$BuildStatus.Length #// Cursor position on X axis
Write-Host $BuildStatus -ForegroundColor Cyan
#// starting the MsBuild job in background.
$MsbJob = [PowerShell]::Create().AddScript(
{
param($MsbArgs, $Result)
& msbuild $MsbArgs | Out-Null
$Result.Value = $LASTEXITCODE
}
).AddArgument($MsbArgs).AddArgument($ReturnCode)
$async = $MsbJob.BeginInvoke() #// start executing the job.
#// While above script block is doing its job in background, display status and animation in console window.
while (!$async.IsCompleted)
{
foreach ($item in $anim) #// looping on array containing characters to form animation
{
[Console]::SetCursorPosition($CursorLeft + 5,$CursorTop) #//setting position for cursor
Write-Host $item -ForegroundColor Yellow
Start-Sleep -m 50
}
}
$MsbJob.EndInvoke($async)
的大部分時間,它按預期工作即顯示,如狀態:
大廈MyProject的(角色動畫)..
但突然間,就變成這樣:
只發現解決方案:我能夠糾正這是爲了增加控制檯(控制檯屬性 - >佈局:屏幕緩衝區大小)的屏幕緩衝區大小爲1024.此外,我還增加了窗口大小以填寫監視器,並沒有像那樣突破。
我對Screen Buffer的評估是正確的嗎?或其他任何東西正在分手? 如果是,是否必須實際增加屏幕緩衝區大小,即從我的.psm1腳本內。
任何幫助將非常感激。
只是想知道爲什麼它按預期工作一段時間,即它確實重新定位光標,但是我無法弄清楚它忘記了光標位置的位置Y軸..... –