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

Ctrl+C makes search prompt unresponsive #1675

Open
Atulin opened this issue Feb 24, 2025 · 3 comments
Open

Ctrl+C makes search prompt unresponsive #1675

Atulin opened this issue Feb 24, 2025 · 3 comments

Comments

@Atulin
Copy link

Atulin commented Feb 24, 2025

Code_eJKx3V92sC.mp4

The code is nothing super special:

export const selectSpec = async (args: { spec: string }) => {
	if (Bun.stringWidth(args.spec) > 0) {
		return args.spec;
	}

	const specs = [...new Glob(join(dirname(Bun.main), "specs/[^_]*.json")).scanSync()];
	const fuse = new Fuse(specs, {});

	return await search({
		message: "Select a spec",
		source: (input) => {
			if (!input) {
				return [];
			}

			const results = fuse.search(input).map((result) => basename(result.item));
			return results.map((spec) => ({
				name: spec,
				value: spec,
			}));
		},
	}).catch(() => {
		process.exit(0);
	});
};
@SBoudrias
Copy link
Owner

Did you test with Node.js?

@Atulin
Copy link
Author

Atulin commented Feb 24, 2025

Slightly modifed code to remove Bun dependencies, and when ran with npx tsx test.ts the following file works just fine, but hangs when using Bun:

import { search } from "@inquirer/prompts";
import Fuse from "fuse.js";
import { readdirSync } from "node:fs";
import { basename } from "node:path";

export const selectSpec = async (args: { spec: string }) => {
	if (args.spec.length > 0) {
		return args.spec;
	}

	const specs = readdirSync("specs");
	const fuse = new Fuse(specs, {});

	return await search({
		message: "Select a spec",
		source: (input) => {
			if (!input) {
				return [];
			}

			const results = fuse.search(input).map((result) => basename(result.item));
			return results.map((spec) => ({
				name: spec,
				value: spec,
			}));
		},
	}).catch(() => {
		process.exit(0);
	});
};

await selectSpec({ spec: "" });

@Atulin
Copy link
Author

Atulin commented Feb 24, 2025

I raised an issue on the Bun repo: oven-sh/bun#17636

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

No branches or pull requests

2 participants