-
-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature - Add failed task #1195
Open
BatanGaming
wants to merge
9
commits into
spectreconsole:main
Choose a base branch
from
BatanGaming:feature/failed-task
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a8d8b42
Add 'Failed' state to the ProgressTask
BatanGaming 6d1b3de
Add failed rendering for ProgressBar
BatanGaming c0a7489
Add failed rendering for PercentageColumn
BatanGaming b88b3fe
Add failed rendering for SpinnerColumn
BatanGaming e724537
Add failed rendering for DownloadedColumn
BatanGaming c5eeeb9
Add missing XML documentation
BatanGaming 120dc70
Set _maxWidth to null as in CompletedText
BatanGaming 506c0a3
Fix style field name
BatanGaming b3dba12
Merge branch 'main' into feature/failed-task
BatanGaming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 44 additions & 30 deletions
74
src/Spectre.Console/Live/Progress/Columns/PercentageColumn.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,45 @@ | ||
namespace Spectre.Console; | ||
|
||
/// <summary> | ||
/// A column showing task progress in percentage. | ||
/// </summary> | ||
public sealed class PercentageColumn : ProgressColumn | ||
{ | ||
/// <summary> | ||
/// Gets or sets the style for a non-complete task. | ||
/// </summary> | ||
public Style Style { get; set; } = Style.Plain; | ||
|
||
/// <summary> | ||
/// Gets or sets the style for a completed task. | ||
/// </summary> | ||
public Style CompletedStyle { get; set; } = Color.Green; | ||
|
||
/// <inheritdoc/> | ||
public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime) | ||
{ | ||
var percentage = (int)task.Percentage; | ||
var style = percentage == 100 ? CompletedStyle : Style ?? Style.Plain; | ||
return new Text($"{percentage}%", style).RightJustified(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override int? GetColumnWidth(RenderOptions options) | ||
{ | ||
return 4; | ||
} | ||
namespace Spectre.Console; | ||
|
||
/// <summary> | ||
/// A column showing task progress in percentage. | ||
/// </summary> | ||
public sealed class PercentageColumn : ProgressColumn | ||
{ | ||
/// <summary> | ||
/// Gets or sets the style for a non-complete task. | ||
/// </summary> | ||
public Style Style { get; set; } = Style.Plain; | ||
|
||
/// <summary> | ||
/// Gets or sets the style for a completed task. | ||
/// </summary> | ||
public Style CompletedStyle { get; set; } = Color.Green; | ||
|
||
/// <summary> | ||
/// Gets or sets style for a failed task. | ||
/// </summary> | ||
public Style FailedStyle { get; set; } = new Style(foreground: Color.Red); | ||
|
||
/// <inheritdoc/> | ||
public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime) | ||
{ | ||
var percentage = (int)task.Percentage; | ||
var style = Style; | ||
if (task.IsFailed) | ||
{ | ||
style = FailedStyle; | ||
} | ||
else if (percentage == 100) | ||
{ | ||
style = CompletedStyle; | ||
} | ||
|
||
return new Text($"{percentage}%", style).RightJustified(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override int? GetColumnWidth(RenderOptions options) | ||
{ | ||
return 4; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ internal sealed class ProgressBar : Renderable, IHasCulture | |
private const int PULSESIZE = 20; | ||
private const int PULSESPEED = 15; | ||
|
||
public bool IsFailed { get; set; } | ||
|
||
public double Value { get; set; } | ||
public double MaxValue { get; set; } = 100; | ||
|
||
|
@@ -20,6 +22,7 @@ internal sealed class ProgressBar : Renderable, IHasCulture | |
public Style FinishedStyle { get; set; } = Color.Green; | ||
public Style RemainingStyle { get; set; } = Color.Grey; | ||
public Style IndeterminateStyle { get; set; } = DefaultPulseStyle; | ||
public Style FailedStyle { get; set; } = new Style(foreground: Color.Red); | ||
|
||
internal static Style DefaultPulseStyle { get; } = new Style(foreground: Color.DodgerBlue1, background: Color.Grey23); | ||
|
||
|
@@ -35,7 +38,7 @@ protected override IEnumerable<Segment> Render(RenderOptions options, int maxWid | |
var completedBarCount = Math.Min(MaxValue, Math.Max(0, Value)); | ||
var isCompleted = completedBarCount >= MaxValue; | ||
|
||
if (IsIndeterminate && !isCompleted) | ||
if (IsIndeterminate && !isCompleted && !IsFailed) | ||
{ | ||
foreach (var segment in RenderIndeterminate(options, width)) | ||
{ | ||
|
@@ -46,7 +49,16 @@ protected override IEnumerable<Segment> Render(RenderOptions options, int maxWid | |
} | ||
|
||
var bar = !options.Unicode ? AsciiBar : UnicodeBar; | ||
var style = isCompleted ? FinishedStyle : CompletedStyle; | ||
var style = CompletedStyle; | ||
if (isCompleted) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to see support for "Completed with errors", something can have run to completion while still encountering errors. |
||
{ | ||
style = FinishedStyle; | ||
} | ||
else if (IsFailed) | ||
{ | ||
style = FailedStyle; | ||
} | ||
|
||
var barCount = Math.Max(0, (int)(width * (completedBarCount / MaxValue))); | ||
|
||
// Show value? | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather see a public setter on this, the current setup with
StopTaskWithFailure
implies the task always stops as soon as it's failed which I don't think is a reasonable assumption to make.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. You named it right
Completed with errors
in the comment below and I think it's not related toFailed
status. I think what you need is methods likeAddError
,GetErrors
so then you can get occurred errors.I wouldn't mix
Failed
andCompleted
statuses in any way because from my point of viewFailed
task cannot continue working. If some error occurred and task can continue working then I wouldn't call itFailed
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that feels like adding business-logic into a visual component whose goal it is to represents a process. I just want to visualize "The process encountered an error" and whether that stopped the process, or the process is still going is not related to the visual "error state".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me it's just unintuitive to see failed job still going.
@patriksvensson Any chance to review this feature and join the discussion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imagine a CI/CD pipeline, you might have configured it so that even if a test fails, it still publishes the build artifacts. So then the process is in an error state, while still continuing.
In my case the progress bar represents a deployment where a system is deploying 10 different resources, one might fail, but that doesn't stop the deployment from deploying the other nine. (You could argue this is odd behavior, but the behavior is outside of my control, I simply schedule the deployment and monitor its progress).
I would also argue it's more in line with the current design, there are no restrictions on changing the
Value
,MaxValue
orIsIndeterminate
properties, what benefit is gained from restricting the Failed/Error state?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your general example really looks odd for me. But for your particular case, I have something similar actually.

So What I did - I created multiple
ProgressTask
that show the state of each individual task. Since we don't have any option to indicate that error occurred, I made custom widget that shows text state.After the whole process is over it displays all errors that happened during it.
Back to the topic, my main idea is that
Failed
status !=Something bad happened during the process but process still goes on
.I agree, it'd be good to have something that indicates that something happened but I think it should be different status, not
Failed
. For your specific case, I'd suggest to separate deployments into independent tasks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a UI widget why enforce this limitation? If you want to, you can set Failed = true, and then stop the task, and you have what you want, a failed task that is no longer running.
In my case, I'd like to just say Failed = true and let it run until the underlying task is actually completed indicating that while this is still in progress, it encountered an issue. What's so wrong with having the option to do that?