mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-24 04:02:50 +08:00
Set max value for progress task properly
Also clamp the task value if it's greater than the max value. Closes #163
This commit is contained in:
parent
acf01e056f
commit
63abcc92ba
@ -59,7 +59,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task Foo()
|
public Task Should_Reduce_Width_If_Needed()
|
||||||
{
|
{
|
||||||
// Given
|
// Given
|
||||||
var console = new PlainConsole(width: 20);
|
var console = new PlainConsole(width: 20);
|
||||||
@ -87,5 +87,29 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
// Then
|
// Then
|
||||||
return Verifier.Verify(console.Output);
|
return Verifier.Verify(console.Output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Setting_Max_Value_Should_Set_The_MaxValue_And_Cap_Value()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var task = default(ProgressTask);
|
||||||
|
var console = new PlainConsole();
|
||||||
|
var progress = new Progress(console)
|
||||||
|
.Columns(new[] { new ProgressBarColumn() })
|
||||||
|
.AutoRefresh(false)
|
||||||
|
.AutoClear(false);
|
||||||
|
|
||||||
|
// When
|
||||||
|
progress.Start(ctx =>
|
||||||
|
{
|
||||||
|
task = ctx.AddTask("foo");
|
||||||
|
task.Increment(100);
|
||||||
|
task.MaxValue = 20;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Then
|
||||||
|
task.MaxValue.ShouldBe(20);
|
||||||
|
task.Value.ShouldBe(20);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ namespace Spectre.Console
|
|||||||
|
|
||||||
if (maxValue != null)
|
if (maxValue != null)
|
||||||
{
|
{
|
||||||
_maxValue += maxValue.Value;
|
_maxValue = maxValue.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (increment != null)
|
if (increment != null)
|
||||||
@ -175,6 +175,12 @@ namespace Spectre.Console
|
|||||||
Value += increment.Value;
|
Value += increment.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Need to cap the max value?
|
||||||
|
if (Value > _maxValue)
|
||||||
|
{
|
||||||
|
Value = _maxValue;
|
||||||
|
}
|
||||||
|
|
||||||
var timestamp = DateTime.Now;
|
var timestamp = DateTime.Now;
|
||||||
var threshold = timestamp - TimeSpan.FromSeconds(30);
|
var threshold = timestamp - TimeSpan.FromSeconds(30);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user