SBoudrias / Inquirer.js

A collection of common interactive command line user interfaces.
MIT License
20.2k stars 1.3k forks source link

Add support for multiline input #99

Closed brianweil closed 8 years ago

brianweil commented 10 years ago

I would like to add support for multiple lines of text in the input type. I use the prompt for commit messages and sometimes one line is not enough. The UI could be as simple as pressing shift+enter to move to the next line of input. Feedback from the contributors is welcome and appreciated.

SBoudrias commented 10 years ago

I wonder if we could call the system editor like when you git commit and get the content back afterward.

SBoudrias commented 10 years ago

Just to keep track: http://stackoverflow.com/questions/19456184/cli-implement-something-like-git-commit-open-a-text-editor-and-get-value

eddiemonge commented 10 years ago

+1. karma init does this reasonably well

jameswomack commented 9 years ago

This would be great for doing things like blog posts from the command-line. Hexo would do well to integrate this.

RonaldTreur commented 9 years ago

Just to make sure this stays on the radar: +1

AndersDJohnson commented 8 years ago

+1 Any updates on this? I support the Shift+Enter idea, either as a default to insert newline on any option, or swapped for Enter behavior which instead inserts newline on options explicitly configured as multiline.

SBoudrias commented 8 years ago

@adjohnson916 PR welcomed.

SBoudrias commented 8 years ago

This is now shipped with v1.1.0

0phoff commented 7 years ago

I know there is editor support, but is there any chance that you will also support multiline? I prefer would prefer multiline over editor for my application.

Multiline should allow the user to enter multiple lines, and close when it encounters an empty line (or line with only a dot) or when the user presses CTRL+D. At least that is the standard behaviour across various command line applications I use.

I tried to look at your code to implement it myself, but I don't really understand how to implement a custom prompt... Is there any documentation or tutorial?

aleclarson commented 5 years ago

A working (yet untested) implementation: https://github.com/aleclarson/inquirer/commit/16ddf2f497ca7b0929ba252eef875062eebd5e64

It adds a multiline boolean option to input prompts. It probably won't merge cleanly into master, because I've made other changes. But you can take inspiration from it.

The ctrl+d key binding has its own commit: https://github.com/aleclarson/inquirer/commit/e5c844e9ab056e3b17eef94ae05dc211d0656275

KoStard commented 22 hours ago

Has this feature been merged? I don't see how to receive multi-line input from the user from terminal without opening external windows.

import { input } from '@inquirer/prompts';

const answer = await input({
  message: 'Enter a description',
  multiline: true,
});
console.log(answer);

I tried this, but it only accepted one line. Also I don't see anything about multiline support in the homepage: https://github.com/SBoudrias/Inquirer.js

I think this issue can be reopened to track the interest in this request.

SBoudrias commented 22 hours ago

Hi @KoStard, the multi-line comes through the editor prompt. There's been some more recent talk over here too https://github.com/SBoudrias/Inquirer.js/discussions/1583 (I'm open to improving this, but transparently, it's not on my todo list ATM. So it's up for the taking.)