Skip to content
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

feat(cli): command line spinner #3968

Merged
merged 12 commits into from
Dec 20, 2023
Merged

feat(cli): command line spinner #3968

merged 12 commits into from
Dec 20, 2023

Conversation

darkdarcool
Copy link
Contributor

These are just a a few functions similar to ora's.

Whenever I create a CLI app, I find myself not wanting to add a third-party spinner package and adding this code myself. I think this addition to the CLI module is a helpful one for some people. I'm not exactly sure how to add tests for this, since it depends a lot on timing and stdout, but I'm open to adding tests if someone finds a way.

Like #3777, please tell me if this should not be included in the standard lib, and I'll just make a small third party package for it.

@CLAassistant
Copy link

CLAassistant commented Dec 15, 2023

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the cli label Dec 15, 2023
cli/spinner.ts Outdated Show resolved Hide resolved
cli/spinner.ts Outdated Show resolved Hide resolved
cli/spinner.ts Outdated Show resolved Hide resolved
cli/spinner.ts Outdated Show resolved Hide resolved
cli/spinner.ts Outdated Show resolved Hide resolved
cli/spinner.ts Outdated Show resolved Hide resolved
cli/spinner.ts Outdated Show resolved Hide resolved
cli/spinner.ts Outdated Show resolved Hide resolved
cli/spinner.ts Outdated Show resolved Hide resolved
cli/spinner.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure about adding this also. It seems like something useful that other modules could rely on. However, it could become too opinionated if we're not careful. Either way, I've added a few suggestions. I'm happy to defer to whatever the concensus is for this addition.

I think the only exported symbols here should be Spinner and SpinnerOptions.

@darkdarcool
Copy link
Contributor Author

@iuioiua Thanks for the feedback, I incorporated everything. Also, do you have any suggestions for how I might add tests for this?

@iuioiua
Copy link
Collaborator

iuioiua commented Dec 17, 2023

Sorry, I don't see the changes. Did you push your changes?

I'm not sure how to test this yet. In this case, we may need to do manual testing for the first pass.

@darkdarcool
Copy link
Contributor Author

darkdarcool commented Dec 17, 2023

I think I fixed it now.

Copy link
Collaborator

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking better! Few more suggestions.

cli/spinner.ts Show resolved Hide resolved
cli/spinner.ts Outdated Show resolved Hide resolved
cli/spinner.ts Outdated Show resolved Hide resolved
cli/spinner.ts Outdated Show resolved Hide resolved
cli/spinner.ts Show resolved Hide resolved
cli/spinner.ts Show resolved Hide resolved
@iuioiua iuioiua changed the title feat(cli): spinner.ts feat(cli): command line spinner Dec 18, 2023
Copy link
Collaborator

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some tweaks and fixed the formatting. Now, LGTM.

I'm impartial to adding this functionality, but I'm happy to go along with the consensus.

cli/spinner.ts Outdated
*
* @default {75}
*/
speed?: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

speed sounds strange to me as lower number gives faster speed of spinner. How about internal? ref: https://github.com/sindresorhus/ora?tab=readme-ov-file#interval

cli/spinner.ts Outdated
*/
speed?: number;
/** The color of the spinner. Defaults to the default terminal color. */
color?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this needs to be ANSI color code. On the other hand, ora supports human-readable color names ('black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray'). I wonder which is the better design..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it definitely makes it easier to read and write quickly. I'll make it support both 👍

cli/spinner.ts Outdated
Comment on lines 12 to 13
type Ansi = string & { };
type Color = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray' | Ansi;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iuioiua I used this typescript hack to allow for type suggestions on colors and allowing for a ANSI string, is this ok?

See microsoft/TypeScript#29729 (comment)

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice addition!

@kt3k kt3k merged commit bc03e0d into denoland:main Dec 20, 2023
12 checks passed
spinner?: string[];
/** The message to display next to the spinner. */
message?: string;
/** The time between each frame of the spinner.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful to include the unit of time here (milliseconds) — otherwise, the user must review the implementation to understand. For example:

- The time between each frame of the spinner.
+ The time (milliseconds) between each frame of the spinner.

iuioiua pushed a commit that referenced this pull request Dec 21, 2023
fix(cli/spinner): export type aliases used in public API

Ref: #3968
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants