Search code examples
cncursescurses

easy way to get and print input onto window


I'm developing an app in C using ncurses, I want a box where I can get user input, only problem is, I can't find a way to do it that works the way I need it to.

For example, the closest ive come is the mvwgetnstr() routine, however this doesn't print the inputted characters back onto the window like I want it to. Ive searched around for quite a while now but I couldn't find anything.

Thanks for the help!

edit: just to clarify, I would need a routine like mvwgetnstr() just with the input being printed back onto the window.


Solution

  • The getstr manual page tells you:

    Characters input are echoed only if echo is currently on. In that case, backspace is echoed as deletion of the previous character (typically a left motion).

    and the echo manual page gives you more information:

    The echo and noecho routines control whether characters typed by the user are echoed by getch(3x) as they are typed. Echoing by the tty driver is always disabled, but initially getch is in echo mode, so characters typed are echoed. Authors of most interactive programs prefer to do their own echoing in a controlled area of the screen, or not to echo at all, so they disable echoing by calling noecho. [See curs_getch(3x) for a discussion of how these routines interact with cbreak and nocbreak.]

    The ncurses manual page advised initializing it with noecho; your program can turn that off (or on), at any time.