Initiate User Input with Editable Text

How can I load a text with the possibility to edit it in user console?

Consider this scenario...

  1. Prompt a user to type a text in console
  2. Prompt the user to type another text but the first text will load to console and have the ability to edit it

You'd need to put the terminal into raw mode and take over from there.
By take over, I mean you need to manually make sure that hitting backspace erases a character, pressing inserts one, etc.
Termion is a good library in this case.

2 Likes

If you don't want to do the manual terminal management yourself, you might want to look into a crate that implements interactive prompts.

I've had success with the rustyline crate crate in the past. This gives you nice things like prompts (with an optional initial value), history (i.e. hitting the up key to select previous entries), tab completion, and shortcuts (i.e. registering a series of keys which, when pressed, will perform a particular operation).

4 Likes

Thank you @RedDocMD and @Michael-F-Bryan. Both references are good and solved my problem.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.