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

Feature request: Initial input values #590

Closed
renarsvilnis opened this issue Sep 19, 2017 · 11 comments
Closed

Feature request: Initial input values #590

renarsvilnis opened this issue Sep 19, 2017 · 11 comments

Comments

@renarsvilnis
Copy link

I'd like to make a feature request for the ability to have editable default values (maybe call it "initial value"?).

Usage example

In the example gif below instead of copy-pasting the "default" value, that is auto-generated from the given link, I'd like the user to be able to edit the generated value easier.

out

Maybe there is some hackish way of achieving it now? I tried mutably modifying the given Answers hash within the filter method of the first question, but no luck.

@renarsvilnis
Copy link
Author

Any feedback?

If so, I'm interested in contributing the feature.

@czebe
Copy link

czebe commented Oct 18, 2017

This would be useful. At the moment it's hard to get default value in the input prompt and edit/modify it (eg. rename file.xxx to file2.xxx etc). To me it'd feel natural if I press TAB, the default value gets written in the input so I can edit it (I'm not sure if you can detect this in the console).

@SBoudrias
Copy link
Owner

@czebe yeah, any keypress can be detected.

I think using tab to put the default value in is a great idea actually. Would you be interested in preparing a PR?

@renarsvilnis
Copy link
Author

renarsvilnis commented Oct 19, 2017

@SBoudrias I'll give it a shot, to implement tab complete.

@jonathancochran
Copy link

Any luck with this @renarsvilnis?

@renarsvilnis
Copy link
Author

@jonathancochran No, I needed a quick fix, so I just added a prefix +, in my app, that when present prepends inputted tabs with the "initial values"

@hi2u
Copy link

hi2u commented Jun 7, 2018

This would be really useful. My use case is entering dates in a CLI (paper documents) scanning interface.

My default value is today's date, such as 2018-06-07 - but when I need to enter a different date, it's usually around the same time, so would be handy being able to just edit the default answer rather than having to fully type it out (or copy and paste).

I know there's datepicker plugins, but text is a bit easier for me.

The file renaming example above is really good too.

The tab completion idea is nice, but as a basic start without much more work it would be handy just as an option we can specify.

@NoriSte
Copy link

NoriSte commented Oct 15, 2019

I'm very interested in this feature, I'd like to use it in my nprr (a sort of npm run + autocomplete) package 😊

@TianyiShi2001
Copy link

TianyiShi2001 commented Apr 26, 2020

the prompts package already has this feature. This is also true for enquirer. You may consider switching to them if you don't have too much code dependent on inquirer and you really need this feature.

@swordensen
Copy link

I ended up solving this a little bit differently. For situations where I want to be able to edit the default value of an input type question I push the default value to the inquirer read stream.

This is my code:

import inquirer from 'inquirer';

(async ()=>{
   const question = {
       type: 'input',
       name: 'answer',
       default: "idk, give it a try",
       message: "can you edit the default value?"
   }
   const prompt = inquirer.prompt([
       question
   ])

   const readStream = (prompt.ui as any).rl.input;
   readStream.push(question.default);
   const {answer} = await prompt;
   console.log({answer});
})()

note that it this only works if you are asking one question at a time.

@SBoudrias
Copy link
Owner

Hi all, the new @inquirer/input allow editing the default value when pressing tab.

I'll close this ticket as we don't intend to backport features to the maintenance version. See new release announcement

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

8 participants