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): make Spinner.message able to be changed on-the-fly #4079

Merged
merged 8 commits into from
Jan 4, 2024

Conversation

timreichen
Copy link
Contributor

  • makes Spinner.message property public

Reason: Allows to change message during active spinner.

Example:

import { Spinner } from "https://deno.land/std@$STD_VERSION/cli/spinner.ts";
import { delay } from "https://deno.land/std@$STD_VERSION/async/delay.ts";

const spinner = new Spinner( { message: "Loading..." });
spinner.start();
await delay(1000);
spinner.message = "Almost done..."
await delay(1000);
spinner.stop();

@timreichen timreichen requested a review from kt3k as a code owner January 3, 2024 14:53
@github-actions github-actions bot added the cli label Jan 3, 2024
Copy link
Contributor

@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 like the idea of this. Thank you.

It does make me think that this same change could be applied to some of the other properties.

@timreichen
Copy link
Contributor Author

I like the idea of this. Thank you.

It does make me think that this same change could be applied to some of the other properties.

Like color and interval?

@iuioiua
Copy link
Contributor

iuioiua commented Jan 4, 2024

Yep 👍🏾

@timreichen
Copy link
Contributor Author

Yep 👍🏾

Should that be part of this PR or a separate one?

@iuioiua
Copy link
Contributor

iuioiua commented Jan 4, 2024

Let's have it part of this one.

@timreichen
Copy link
Contributor Author

Actually, interval might need special treatment, else a change won't do anything.

@timreichen
Copy link
Contributor Author

timreichen commented Jan 4, 2024

Ok, I updated the code so it works when changing interval and color while the spinner is running.
While at it, I removed the obsolete #active prop and made some adjustments for better readability.

Example:

import { Spinner } from "https://deno.land/std@$STD_VERSION/cli/spinner.ts";
import { delay } from "https://deno.land/std@$STD_VERSION/async/delay.ts";

const spinner = new Spinner({ message: "Loading..." });
spinner.start();
await delay(1000);
spinner.message = "Almost done...";
spinner.color = "blue";
spinner.interval = 25;
await delay(1000);
spinner.stop();

Copy link
Contributor

@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.

Frankly, I don't get some of these changes. I didn't think making color and friends would introduce such logic.

Sorry to change my mind, but can we revert to focusing on making Spinner.message public? Sorry for my previous suggestion. We should always keep PRs focused.

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
#color?: Color;
#intervalId: number | undefined;
#active = false;
#frameIndex = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose of this change?

@timreichen
Copy link
Contributor Author

Frankly, I don't get some of these changes. I didn't think making color and friends would introduce such logic.

Sorry to change my mind, but can we revert to focusing on making Spinner.message public? Sorry for my previous suggestion. We should always keep PRs focused.

Ok, I reverted the changes and will open other PRs for the color and interval. There are some catches to be aware of so it works as intended, so the changes are not just to remove the hash.

Copy link
Contributor

@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.

Nice! LGTM. Thank you.

@iuioiua iuioiua changed the title refactor(cli): public Spinner.message property feat(cli): make Spinner.message able to be changed on-the-fly Jan 4, 2024
@iuioiua iuioiua enabled auto-merge (squash) January 4, 2024 11:39
@iuioiua iuioiua merged commit 9c8b9b5 into denoland:main Jan 4, 2024
12 checks passed
@timreichen timreichen deleted the cli_public_message branch January 7, 2024 21:04
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.

2 participants