Refactor the API for stopping spinners & progress bars #405
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.
As discussed on Discord, this PR proposes a change to the API for stopping spinners and progress bars.
Currently these use a slightly awkward API using a positional argument to pass a numeric code to set whether the stop is successful or the result of an error or cancellation, e.g.
spinner.stop(undefined, 1)
.This PR proposes removing the error code form in favour of distinct
spinner.cancel()
andspinner.error()
methods.This is a breaking change for anyone using the code API currently.
Notes
This PR does not change any of the existing semantics around how “cancel” and “error” are represented and preserves the current behaviour where a “cancel” code shows a red square and an “error” code shows a yellow triangle.
This is different from the
.error()
method of thelog
utility, which shows a red square.An alternative refactor could be to rename to
.stopAndWarn()
(current “error” behaviour) and.stopAndError()
(current “cancel” behaviour), or something like that, which would align with howlog.warn
andlog.error
look.Or, another alternative would be to switch to an object argument like
.stop({ type: 'warn' })
, which could also resolve the awkwardness of the current positional style and avoid multiple methods.Docs
This will require an update to https://bomb.sh/docs/clack/packages/prompts/#spinner