Home > Enterprise >  Prompt user to fill in a template?
Prompt user to fill in a template?

Time:02-27

I've never been able to find anything about this in any language, but what I want to do seems rather simple to me.

I want to prompt the user for input, but have them fill in a sort of template. Let's use a simple DD-MM-YYYY date as an example.

[█ -  -    ]

is where the user writes. As they write, the [ and - stay where they are, with the cursor jumping past them, and hitting enter submits.

I'm not expecting anyone to write all of this for me, but cin and cout seem to be too crude a tools to do this, and so I'm wondering where I should even start, if not there.

Is there something that already does this, or at least something that gives me more control of the cursor to allow me to write it myself? I do not want to be drawing a full-on TUI with windows and boarders and colors, so ncurses would just get in the way. I just want a single-line text field that returns the input.

CodePudding user response:

Generally what you want is a text-based GUI library, such as ncurses. Doing console work is platform-specific, and every system has its own console API to do this. If you want to implement this yourself, you would have to examine what options does your target operating system give you in terms of console API, and build a custom solution based on that.

  • Related