1

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.

EDIT: The most promising non-ncruses alternative for a helpful library seems to be Terminal.

4
  • 3
    not in c++ natively. You need to use a library or the platform specific console APIs. Ncurses might be a good place to start Commented Feb 26, 2022 at 17:09
  • for this example, I'd say it's easier just to let user enter the whole string. Commented Feb 26, 2022 at 17:11
  • @AlanBirtles Ok, cheers. Is there an alternative to ncurses that is smaller and more focused, since I specifically do not want 99% of what ncurses does? Commented Feb 26, 2022 at 17:21
  • 1
    If you're fine with not supporting cmd.exe (the old windows terminal), just about everything else will support ANSI Escape codes (take a look at those that move the cursor) en.wikipedia.org/wiki/ANSI_escape_code Commented Feb 27, 2022 at 0:51

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Right, thanks. Is there something other than ncurses I could use? I just want to display a couple of characters and move the cursor, not draw windows or colors or get mouse input or any of the other things ncurses offers? EDIT: I now see your edit about implementing it myself, but it seems like if every system has it's own console API, that that would be a very much non-trivial endeavor.
Im sure there might be something more light-weight, but you will have to look around. Dont know many text based gui libraries. :(

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.