cargo-generate / cargo-generate

cargo, make me a project

Home Page:https://cargo-generate.github.io/cargo-generate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feat: support multiline custom placeholders

mirsella opened this issue · comments

Hello !

It would be very useful to have the option to enter multi line input with custom placeholder, like copying and pasting a block which have multiple line.
Maybe something like this:

[placeholders.input]
type = "string"
multiline = true # optional, false by default
prompt = "main puzzle input"
regex = "[^ ]"

And then pasting this text, for example

1 2
3 4

Would work and set the two line in input instead of setting only 1 2 and 3 4 going to the next placeholder.

Thanks !

or another idea, editor = true open $EDITOR to edit the placeholder, already implemented in dialoguer which is already a dependency of this crate:

use dialoguer::Editor;

if let Some(rv) = Editor::new().edit("Enter a commit message").unwrap() {
    println!("Your message:");
    println!("{}", rv);
} else {
    println!("Abort!");
}

Ok I looked at the details, above idea with Editor should work no problem, but for multiline input, dialoguer::Input doesn't support it !
But we can easily do it manually and end the input with ctrl+d !

fn main() {
    let mut buffer = String::new();
    while std::io::stdin().read_line(&mut buffer).unwrap() != 0 {}
    println!("{buffer}");
}

Or also check for \n\n at the end of the string and finish it if it's the case !
Maybe it should be name raw_input or something like that instead of multiline, as the input comportment will be different from dialoguer.

i would be happy to open a PR with theses features after hearing some feedback !