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

feat: support multiline custom placeholders #1074

Closed
mirsella opened this issue Dec 9, 2023 · 5 comments
Closed

feat: support multiline custom placeholders #1074

mirsella opened this issue Dec 9, 2023 · 5 comments

Comments

@mirsella
Copy link
Contributor

mirsella commented Dec 9, 2023

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 !

@mirsella
Copy link
Contributor Author

mirsella commented Dec 9, 2023

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!");
}

@mirsella
Copy link
Contributor Author

mirsella commented Dec 9, 2023

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 !

@sassman
Copy link
Member

sassman commented Jan 11, 2024

Hey @mirsella

Interesting feature. I myself was not yet in the needs of a multi line input. But I saw that there is one thumbs up on the suggestion.

But we can easily do it manually and end the input with ctrl+d !

I would prefer this approach over a \n\n simply because 2 new lines could easily be part of regular input a user wants to provide.

From a usability POV the editor approach already available in dialoguer seems even more charming.

On the configuration part, somehow I would prefer to lower the complexity by simply adding a new type:

[placeholders.input]
type = "text"      # instead of "string" we use "text" to imply a free form and multi line text
prompt = "main puzzle input"
regex = "[^ ]"

@mirsella
Copy link
Contributor Author

mirsella commented Jan 11, 2024

I'll work on a PR implementing text and editor type !

edit: i'm a little busy now, but it's still on my plans

@sassman
Copy link
Member

sassman commented Feb 15, 2024

Progress so far:

github-merge-queue bot pushed a commit that referenced this issue Feb 16, 2024
* docs: add docs about the new feature #1074

* refactor: rename some small bits

* try out not linking the unreleased section
@sassman sassman closed this as completed Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants