anseki / readline-sync

Synchronous Readline for interactively running to have a conversation with the user via a console(TTY).
MIT License
797 stars 64 forks source link

Initial value set to the prompt as already typed once the user is asked for an input #55

Closed philocoder closed 7 years ago

philocoder commented 7 years ago

Hello! This is my first "issue" xD so sorry if I get wrong in something.

First, I want to say: great job! This package is very useful.

Secondly, I wonder if something could be added so the developer could specify a value which could be already typed as answer once the question is thrown to the user. Like the "defaultInput" option, but another one, like "initialInputTyped", or something similar. This way, the developer can freely adapt the prompt's initial value, at the same time that the question is being made, to more specific purposes. But at the same time, also letting the final user remove it partially or totally.

Thank you anyway, great tool!!

anseki commented 7 years ago

Hi @philocoder, thank you for the comment 😄

So, do you mean that a limited list of choices? Does the keyInSelect method help you?

Sorry, my English is poor. Please tell me if I mistook your words.

philocoder commented 7 years ago

Hi @anseki! I didn't expect a reply so fast.

Mmmm... No, keyInSelect can't help me here. It would be mainly for prompt/question methods. Some property for the prompt/question methods, to initially set some text as user's input, so the user, when is asked for the input, can see it, and manipulate it before answering. Like a pre-defined and already-typed answer, which is not definitive, but is used to type from it the final answer.

Like what happens when we type tabulation from the command line while searching for some path. The command line shows some valid paths, but the text that was in the command line already typed, as input user, remains there. That effect is what I want to achieve, and I missed some property like "initialValue" or similar, in order to trigger the question, but with a pre-stablished answer (which in the example of the command line, would be the typed text by the user before typing the tabulation).

And sorry for my English, it's poor... Let me know if something is not well said or unclear.

I mean... to put some text as user's default answer, just after the "prompt" symbol.

cd someFolder[tab]

{ Here the CMD output }

This last step is what I don't know how to do it: Because the text should be already typed as answer, but not sent as answer yet:

cd someFolder\

That is, to have already typed the "cd someFolder\".

Heheheheh if you know what I mean

I haven't found an option for that one, and I don't really know where to start looking for, maybe is just about trigger them manually the easiest solution. But I have seen so many options in this project, that I said, hey, this one would be useful too.

...

Okay, I have been looking, and RobotJS seems to me the fastest way to achieve this. I dispose to try it, to see if I can achieve the goal on my own.

anseki commented 7 years ago

I see, you might want something like TUI. It might be a duplicate of https://github.com/anseki/readline-sync/issues/46 and https://github.com/anseki/readline-sync/issues/16. And ncurses may help you.

philocoder commented 7 years ago

Ohhh okay, hehehe I see I'm not the first one. I'll check it out them then.

What amazing things I'm discovering for the console!

Thank you

anseki commented 7 years ago

I hope the ncurses or another library helps you even if readlineSync can't help you. So, please close this issue if it was solved, and please comment to #16 if you want, about the editable default input value.

anseki commented 7 years ago

Unfortunately, no reply came, and I close this issue.