Skip to content

Commit e8c5fc8

Browse files
committed
Fix progress related bugs (divide by zero crash for certain window width/message length combinations, failure to show/hide cursor when stdout redirected)
1 parent 56898cb commit e8c5fc8

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

src/CLU/Microsoft.CLU/System.Management.Automation/Host/ConsoleDataStream.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public void WriteProgress(long sourceId, ProgressRecord record)
6363
{
6464
if (record == null)
6565
{
66-
Console.CursorVisible = true;
6766
throw new ArgumentNullException("record");
6867
}
6968

@@ -80,14 +79,12 @@ public void WriteProgress(long sourceId, ProgressRecord record)
8079
_console.Write(" ");
8180
}
8281
_console.WriteLine();
83-
Console.CursorVisible = true;
8482
}
8583
else
8684
{
87-
Console.CursorVisible = false;
8885
var statusLine = string.Format(Strings.ConsoleDataStream_WriteProgress_StatusLineInProgress, record.Activity, record.StatusDescription, record.CurrentOperation, record.SecondsRemaining);
8986
// Subtract what's already known to be needed:
90-
width -= statusLine.Length + 3;
87+
width = Math.Max(1, width - (statusLine.Length + 3));
9188

9289
var chunkSize = (100 / width) + 1;
9390

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
using System.Management.Automation;
7+
8+
namespace Microsoft.CLU.Test
9+
{
10+
11+
[Cmdlet(VerbsCommon.Show, "Progress")]
12+
public class ShowProgress: PSCmdlet
13+
{
14+
[Parameter()]
15+
public int Steps{ get; set; }
16+
17+
18+
protected override void ProcessRecord()
19+
{
20+
base.ProcessRecord();
21+
22+
var progRecord = new ProgressRecord(4711, "Testing progress", "Running");
23+
WriteProgress(progRecord);
24+
for (int step = 1; step <= Steps; ++step)
25+
{
26+
System.Threading.Thread.Sleep(100);
27+
progRecord.PercentComplete = step * 100 / Steps;
28+
WriteProgress(progRecord);
29+
}
30+
progRecord.RecordType = ProgressRecordType.Completed;
31+
WriteProgress(progRecord);
32+
}
33+
}
34+
}

src/CLU/Microsoft.ScenarioTests.CLU/project.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"dependencies": {
1111
"Microsoft.NETCore": "5.0.1-beta-23516",
1212
"Microsoft.NETCore.Platforms": "1.0.1-beta-23516",
13-
"Microsoft.CSharp": "4.0.1-beta-23516"
13+
"Microsoft.CSharp": "4.0.1-beta-23516",
14+
15+
"System.Threading.Thread": "4.0.0-beta-23516"
1416
}
1517
}
1618
},

0 commit comments

Comments
 (0)