Comments (21)
@jonschlinkert Excuse the mess, I just extracted this from my project. Select "client" and then press ctrl + c
.
const { prompt } = require('enquirer');
const contractor = async () => {
const register = async () => {
menu();
}
const menu = async () => {
const { action } = await prompt({
type: 'select',
name: 'action',
message: 'what would you like to do?',
choices: ['register', 'update', 'mine'],
initial: 'register',
});
switch (action) {
case 'register': {
await register();
break;
}
case 'update': {
console.log('update');
break;
}
case 'mine': {
console.log('mine');
break;
}
default: {
console.log('mine');
break;
}
}
}
menu();
}
const client = async () => {
const query = async () => {
menu();
}
const menu = async () => {
const { action } = await prompt({
type: 'select',
name: 'action',
message: 'what would you like to do?',
choices: ['query', 'check'],
initial: 'query',
});
switch (action) {
case 'query': {
await query();
break;
}
case 'check': {
console.log('check');
break;
}
default: {
await query();
break;
}
}
}
menu();
}
const program = async () => {
const { type } = await prompt({
type: 'select',
name: 'type',
message: 'would you like to start a contractor or client?',
choices: ['contractor', 'client'],
initial: 'client',
});
if (!type || type === 'contractor') {
return contractor();
}
return client();
}
program().catch((err) => {
console.log(err);
});
from enquirer.
Haha, I agree! I wouldn't call it customer service though, maybe community service instead.
from enquirer.
This is proof that @jonschlinkert and @doowb have put a lot of thought into making this a great tool for CLI developers. And the customer service is top notch
from enquirer.
Any chance of getting something like enquirer.cleanup() to close any pipes/handles that aren't cleaned up when an .ask is done?
@doowb and I just talked about something related (I believe). @doowb did you mention having a local branch with a fix for this?
from enquirer.
Ahhh, got it. It's, fortunately a much simpler issue than what I was thinking (assuming you agree).
Try adding the following right below the require statement:
const { prompt } = require('enquirer');
prompt.on('cancel', () => process.exit());
Sorry about the confusion on this, I just wasn't thinking. The reason it works this way is that you can control whether or not to exit the process.
Let me know if this is what you're looking for, or if you have suggestions for other before.
from enquirer.
Wow you guys are fast :)
from enquirer.
Also, it appears that enquirer is globbling up my Ctrl + c
and process.on("SIGINT", function () { console.log("Ctrl+C pressed!") })
doesn't fire - not sure if this is a related problem, or a separate issue, though.
from enquirer.
just talked about something related (I believe).
There's a bug in prompt-base
that in some situations the input stream is held open causing the app to stay open, requiring the use of Ctrl + c
. I have a fix for that and I'll get it pushed up soon.
it appears that enquirer is globbling up my
Ctrl + c
andprocess.on("SIGINT", function () { console.log("Ctrl+C pressed!") })
doesn't fire
This has something to do with readline
, but I don't remember off the top of my head how it's handled. I'll look into it to see if this is a problem. It might be that we need to handle Ctrl + c
explicitly in enquirer
.
We're using cli-cursor
to hide the cursor in some prompts, which is supposed to handle restoring the cursor when the process exits. Which node version are you using and are you able to capture a gif showing the bug?
from enquirer.
Wow you guys are fast :)
haha, well let's see how fast we can get that fix shipped. Sorry it's taking so long, we wanted to do more testing locally before we pushed it up. thanks!
from enquirer.
It might be that we need to handle Ctrl + c explicitly in enquirer.
I think we already explicitly handle it somewhere, probably readline-utils, but we probably are not doing anything to hide or show the cursor. A pr for this would be great, or we'll try to get this fixed asap.
from enquirer.
I'm pretty sure this was fixed. We can re-open or create a new issue if anyone still has a problem with this
from enquirer.
I'm still seeing this.
When showing a multiselect, if I press ctrl+c, it doesn't ever exit after that.
from enquirer.
@vjpr I tried running some of the multiselect examples and I can press Ctrl+c
to get it to exit. Can you show the code that you're running that's failing?
from enquirer.
I am running my app as a child process of another Node app using spawn
. In the parent app, I am listening to SIGINT, and then forwarding the process kill command to the child. Maybe its is some interaction with that.
from enquirer.
I am having a similar issue. I can provide an example if no one else is able to reproduce it.
from enquirer.
I am having a similar issue. I can provide an example if no one else is able to reproduce it.
That would be great, any additional info will help. Thanks!
from enquirer.
@nahtnam thanks so much for the detail! I'm sorry I didn't see your reply until now.
I'll spend some time reviewing to see if I can wrap my brain around this. Thanks again.
from enquirer.
Also, to be clear, hitting ctrl+c
will exit when you run a prompt directly, like this:
const { Select } = require('enquirer');
const prompt = new Select({
type: 'select',
name: 'type',
message: 'would you like to start a contractor or client?',
choices: ['contractor', 'client'],
initial: 'client',
});
prompt.run()
.then(console.log)
.catch(console.error);
But when you run pass an array of questions to enquirer it doesn't exit (currently).
I'm not opposed to changing this default behavior if makes more sense to exit. I'd probably prefer that personally, it just didn't get as much thought as it deserved before.
from enquirer.
Hello!
Thanks for taking a look, it makes sense now. I think the opposite would be a better idea. Most people expect the program to quit after you press ctrl + c
, but there are definitely applications where you wouldn't want to be allowed to quit. I think it would be better if by default it quit, and you can add a hook to do something else on ctrl + c
. However, if it is changed, I think you should bump the version up by 1.0
since it would be a breaking change. As for now, I think adding prompt.on('cancel', () => process.exit());
to the docs would be the best idea.
from enquirer.
I think the opposite would be a better idea. Most people expect the program to quit after you press
ctrl + c
,
I think this makes sense. I'll get a patch pushed up soon.
from enquirer.
Sounds good, thank you!
from enquirer.
Related Issues (20)
- select prompt's choices value not working. (only name field does.) HOT 1
- customizing the style of input prompts HOT 2
- Mocking prompt answers without access to the specific enquirer instance used to prompt HOT 3
- typescript: to infer ReturnType after calling prompt(questions) HOT 3
- Input prompt moves on keydown HOT 1
- Is this project still under maintenance?
- when visible list only has disabled choice (by search), press up/down throw RangeError
- AutoComplete prompt - improve highlighting
- press ESC -> error
- Poor terminal and implementation causing issues with rendering HOT 4
- Multiselect clips prompt message and some items when scrolling HOT 4
- Cannot create custom prompt that extends MultiSelect HOT 2
- Validation in Form HOT 2
- Error with webpack HOT 4
- v2.4.0 contains changes that are not compatible with Node 14 HOT 2
- 2.4 changelog HOT 3
- In select or autocomplete mode, can hint support to display only when selected, but not normally?
- list not working when using nodemon HOT 1
- NPM dependency requests ^2.3.6 but seems to resolve 2.4.1? HOT 4
- engines.node in package.json needs to be updated HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from enquirer.