-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add progress bar detail updates #890
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -300,6 +300,23 @@ public protocol Noorable: Sendable { | |
| task: @escaping (@escaping (Double) -> Void) async throws -> V | ||
| ) async throws -> V | ||
|
|
||
| /// Shows a progress bar step with optional detail text. | ||
| /// - Parameters: | ||
| /// - message: The message that represents "what's being done" | ||
| /// - successMessage: The message that the step gets updated to when the action completes. | ||
| /// - errorMessage: The message that the step gets updated to when the action errors. | ||
| /// - renderer: A rendering interface that holds the UI state. | ||
| /// - task: The asynchronous task to run. The caller can use the argument that the function takes to update the progress. | ||
| /// The value should be between 0 and 1. The detail text is appended after the percentage when present. | ||
| /// message. | ||
| func progressBarStep<V>( | ||
| message: String, | ||
| successMessage: String?, | ||
| errorMessage: String?, | ||
| renderer: Rendering, | ||
| task: @escaping (@escaping (ProgressBarUpdate) -> Void) async throws -> V | ||
|
Contributor
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. Does this conflict with the other overloads in practical use? |
||
| ) async throws -> V | ||
|
|
||
| /// Displays a static table | ||
| /// - Parameters: | ||
| /// - headers: Column headers | ||
|
|
@@ -766,6 +783,25 @@ public final class Noora: Noorable { | |
| errorMessage: String?, | ||
| renderer: Rendering, | ||
| task: @escaping (@escaping (Double) -> Void) async throws -> V | ||
| ) async throws -> V { | ||
| try await progressBarStep( | ||
| message: message, | ||
| successMessage: successMessage, | ||
| errorMessage: errorMessage, | ||
| renderer: renderer | ||
| ) { update in | ||
| try await task { progress in | ||
| update(ProgressBarUpdate(progress: progress)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public func progressBarStep<V>( | ||
| message: String, | ||
| successMessage: String?, | ||
| errorMessage: String?, | ||
| renderer: Rendering, | ||
| task: @escaping (@escaping (ProgressBarUpdate) -> Void) async throws -> V | ||
| ) async throws -> V { | ||
| try await ProgressBarStep( | ||
| message: message, | ||
|
|
@@ -1303,7 +1339,6 @@ extension Noorable { | |
| message: message, | ||
| successMessage: nil, | ||
| errorMessage: nil, | ||
| renderer: Renderer(), | ||
| task: task | ||
| ) | ||
| } | ||
|
|
@@ -1323,6 +1358,34 @@ extension Noorable { | |
| ) | ||
| } | ||
|
|
||
| public func progressBarStep<V>( | ||
| message: String, | ||
| task: @escaping (@escaping (ProgressBarUpdate) -> Void) async throws -> V | ||
| ) async throws -> V { | ||
| try await progressBarStep( | ||
| message: message, | ||
| successMessage: nil, | ||
| errorMessage: nil, | ||
| renderer: Renderer(), | ||
| task: task | ||
| ) | ||
| } | ||
|
|
||
| public func progressBarStep<V>( | ||
| message: String, | ||
| successMessage: String?, | ||
| errorMessage: String?, | ||
| task: @escaping (@escaping (ProgressBarUpdate) -> Void) async throws -> V | ||
| ) async throws -> V { | ||
| try await progressBarStep( | ||
| message: message, | ||
| successMessage: successMessage, | ||
| errorMessage: errorMessage, | ||
| renderer: Renderer(), | ||
| task: task | ||
| ) | ||
| } | ||
|
|
||
|
Comment on lines
+1361
to
+1388
Contributor
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. These 2 can be removed if you use default arguments |
||
| public func table( | ||
| headers: [String], | ||
| rows: [[String]], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,15 +27,17 @@ This component represents a long-running step in the execution of a command show | |
| ### Example | ||
|
|
||
| ```swift | ||
| try await Noora().progressStep( | ||
| try await Noora().progressBarStep( | ||
|
Contributor
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. Does this mean |
||
| message: "Processing the graph", | ||
| successMessage: "Project graph processed", | ||
| errorMessage: "Failed to process the project graph" | ||
| ) { updateProgress in | ||
| for step in steps { | ||
| try await runStep() | ||
| // Use updateProgress to update the progress. The value should be between 0 and 1. | ||
| updateProgress(step / steps) | ||
| let progress = Double(step) / Double(steps) | ||
| let detail = "\(step) / \(steps) nodes" | ||
| updateProgress(ProgressBarUpdate(progress: progress, detail: detail)) | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
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.
These three can have default arguments. Which would remove the need for two overloads