问题描述
嗨专家,
我正在使用msbuild构建一长串Visual Studio项目。在隐藏msbuild输出时,在msbuild完成其工作时会显示基于某些字符的状态和动画。这里我的脚本使用msbuild构建并显示等待动画(你肯定会喜欢这个......):
Hi Experts,
I'm building a long list of Visual Studio projects using msbuild. And while hiding the msbuild output, displaying a status and an animation based upon some characters is displayed while msbuild doing its job. Here my script to build using msbuild and display wait animation (You will surely like this...):
$anim=@("|","/","-","\","|") # Animation sequence characters<br />
$ReturnCode = @{}<br />
$BuildStatus="Building $(ProjectName)" <br />
<br />
$CursorTop=[Console]::CursorTop #// Cursor position on Y axis<br />
$CursorLeft=$BuildStatus.Length #// Cursor position on X axis <br />
Write-Host $BuildStatus -ForegroundColor Cyan<br />
<br />
#// starting the MsBuild job in background.<br />
<br />
$MsbJob = [PowerShell]::Create().AddScript(<br />
{<br />
param($MsbArgs, $Result)<br />
& msbuild $MsbArgs | Out-Null<br />
$Result.Value = $LASTEXITCODE<br />
}<br />
).AddArgument($MsbArgs).AddArgument($ReturnCode)<br />
<br />
$async = $MsbJob.BeginInvoke() #// start executing the job.<br />
<br />
#// While above script block is doing its job in background, display status and animation in console window.<br />
<br />
while (!$async.IsCompleted)<br />
{<br />
foreach ($item in $anim) #// looping on array containing characters to form animation<br />
{<br />
<br />
[Console]::SetCursorPosition($CursorLeft + 5,$CursorTop) #//setting position for cursor<br />
Write-Host $item -ForegroundColor Yellow <br />
Start-Sleep -m 50<br />
}<br />
}<br />
<br />
$MsbJob.EndInvoke($async)<br />
<br />
最多当时,它按预期工作,即显示如下状态:
构建MyProject(动画字符)..
但突然间,它变成了这样:
]
仅发现解决方案:我能够纠正这是为了增加控制台的屏幕缓冲区大小(控制台属性 - >布局:屏幕缓冲区大小)到1024.此外,我还增加了窗口大小以填充显示器,它没有像那样打破。
我的评估关于Screen Buffer是否正确?还是别的什么都搞砸了?如果是,我是否必须实际增加屏幕缓冲区大小,即从我的.psm1脚本中增加。?
任何帮助都会非常感激。
most of the time, it works as expected i.e. showing the status like:
Building MyProject (Animating characters)..
but suddenly, it becomes like this:
http://img89.imageshack.us/img89/7650/4fh.png[^]
Only Discovered Solution: I was able to correct this is to increase the Screen Buffer Size of Console (Console Properties --> Layout: Screen Buffer Size) to 1024. In addition, I also increased Window Size to fill out the monitor and it didn't break like that.
Is my assessment about Screen Buffer is correct? or anything else is breaking up? If Yes, do I have to increase the screen buffer size pragmatically i.e. from inside my .psm1 script.?
Any help would be really appreciated.
推荐答案
这篇关于PowerShell:Console和SetCursorPosition中的角色动画变得疯狂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!