Skip to content

feat(@clack/prompts): custom spinner indicator support #247

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

Merged
merged 12 commits into from
Apr 22, 2025

Conversation

Cygnusfear
Copy link
Contributor

Custom Spinner Support

Great work on clack! I was eager to have a custom spinner option so I figured I could contribute back to the project. Happy to adjust the implementation if not conform requirements.

Supports a 'custom' indicator on the spinner for settings custom frames and speed:

export const customSpinner = spinner({
	indicator: "custom",
	custom: {
		frames: ["🦨", "🐎", "🌵", "🤠", "💘", "🧨", "🌮", "🥃", "🏜️"],
		speed: 500,
	},
});

Copy link

changeset-bot bot commented Mar 10, 2025

🦋 Changeset detected

Latest commit: f4461cf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clack/prompts Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@43081j
Copy link
Collaborator

43081j commented Apr 16, 2025

could you catch up from main? there will be big conflicts since i split the modules into individual files 😬

i'd also rework this slightly to just have a top level frames option and delay option, rather than custom

@Cygnusfear
Copy link
Contributor Author

@43081j for sure!

Caught up and flattened custom into the regular options!

@43081j
Copy link
Collaborator

43081j commented Apr 18, 2025

looks good to me, but can you add some tests?

we need to test the two individually:

  • custom frames
  • custom delay

you can assert the delay worked by using vitest's fake timers (we already use them in spinner tests)

@Cygnusfear
Copy link
Contributor Author

@43081j implemented comments and added tests for spinner & delay, I think I'm doing something wrong but I can't figure out where the issue is-- vitest is reporting these errors after I implement any arbitrary describe/test block:

(node:39957) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [ReadableWorkerStdio]. Use emitter.setMaxListeners() to increase limit
(node:39957) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unhandledRejection listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(node:39957) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [ReadableWorkerStdio]. Use emitter.setMaxListeners() to increase limit
(node:39957) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 keypress listeners added to [ReadableWorkerStdio]. Use emitter.setMaxListeners() to increase limit

@43081j
Copy link
Collaborator

43081j commented Apr 18, 2025

that will be because you need to stop() your spinner in the test, before asserting the buffer

@43081j
Copy link
Collaborator

43081j commented Apr 18, 2025

if you catch up from main, you'll get conflicts in your snapshots i think. just make sure locally you pnpm i then re-run your tests and update the snapshots

@Cygnusfear
Copy link
Contributor Author

Ah nice, vitest was updated!

Caught up & added frame for loop and result.stop(). No snapshot conflicts afaict.

@43081j
Copy link
Collaborator

43081j commented Apr 18, 2025

seems odd the snapshots didn't update 🤔

ANSI codes get serialised now into human-readable strings, so it definitely should've updated them

Copy link

pkg-pr-new bot commented Apr 18, 2025

@example/basic@example/changesets

npm i https://pkg.pr.new/bombshell-dev/clack/@clack/core@247
npm i https://pkg.pr.new/bombshell-dev/clack/@clack/prompts@247

commit: f4461cf

@43081j
Copy link
Collaborator

43081j commented Apr 18, 2025

ah it looks like you still need to catch up from main (github says 2 commits behind, which makes sense as thats where the snapshot change is)

@Cygnusfear
Copy link
Contributor Author

ah it looks like you still need to catch up from main (github says 2 commits behind, which makes sense as thats where the snapshot change is)

my bad, I think I was behind on main updates, woops- did another catch up and indeed new snapshots with ANSI codes replaced

@Cygnusfear
Copy link
Contributor Author

@43081j
Caught up and moved the stop calls in front of assertions, updated snapshots

Copy link
Collaborator

@43081j 43081j left a comment

Choose a reason for hiding this comment

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

looks good!

we just need a changeset now and seems good to merge after that (you can run npx changeset)

Signed-off-by: Alexander Mangel <[email protected]>
@Cygnusfear
Copy link
Contributor Author

@43081j
Pushed changeset! Let me know if that looks ok to you 🙏

@43081j 43081j merged commit 19558b9 into bombshell-dev:main Apr 22, 2025
5 checks passed
@43081j
Copy link
Collaborator

43081j commented Apr 22, 2025

will release it as part of the next 1.0 pre-release (nate may backport it if needed though)

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

Successfully merging this pull request may close these issues.

2 participants