mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-10-31 09:09:25 +08:00 
			
		
		
		
	Changes progress task IsFinished to account for stopped tasks
Previous behavior was that the only way to get a task to a finished state was to artificially set the Value to MaxValue. With this change StopTask() will also complete the task with the change that a task cannot be restarted.
This commit is contained in:
		 Phil Scott
					Phil Scott
				
			
				
					committed by
					
						 Patrik Svensson
						Patrik Svensson
					
				
			
			
				
	
			
			
			 Patrik Svensson
						Patrik Svensson
					
				
			
						parent
						
							fa731070d8
						
					
				
				
					commit
					855127f32a
				
			| @@ -71,7 +71,7 @@ namespace Spectre.Console | ||||
|         /// <summary> | ||||
|         /// Gets a value indicating whether or not the task has finished. | ||||
|         /// </summary> | ||||
|         public bool IsFinished => Value >= MaxValue; | ||||
|         public bool IsFinished => StopTime != null || Value >= MaxValue; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the percentage done of the task. | ||||
| @@ -107,7 +107,8 @@ namespace Spectre.Console | ||||
|             _maxValue = maxValue; | ||||
|             _value = 0; | ||||
|  | ||||
|             _description = description?.RemoveNewLines()?.Trim() ?? throw new ArgumentNullException(nameof(description)); | ||||
|             _description = description?.RemoveNewLines()?.Trim() ?? | ||||
|                            throw new ArgumentNullException(nameof(description)); | ||||
|             if (string.IsNullOrWhiteSpace(_description)) | ||||
|             { | ||||
|                 throw new ArgumentException("Task name cannot be empty", nameof(description)); | ||||
| @@ -125,13 +126,18 @@ namespace Spectre.Console | ||||
|         { | ||||
|             lock (_lock) | ||||
|             { | ||||
|                 if (StopTime != null) | ||||
|                 { | ||||
|                     throw new InvalidOperationException("Stopped tasks cannot be restarted"); | ||||
|                 } | ||||
|  | ||||
|                 StartTime = DateTime.Now; | ||||
|                 StopTime = null; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Stops the task. | ||||
|         /// Stops and marks the task as finished. | ||||
|         /// </summary> | ||||
|         public void StopTask() | ||||
|         { | ||||
| @@ -292,4 +298,4 @@ namespace Spectre.Console | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user