I’m using ncurses for simple UI that involves getting input from the user.
The input is a window of 1 row height, and all there is, is a cursor.
I’m currently using wgetnstr(inputwindow, input, inputlen).
What I would like to, is to be able to edit that input line, much like readline does. That is, being able to use ^W (^U works btw), go back in the buffer and make a change, etc.
If I could keep the history of the input and be able to access it with the ‘up’ arrow, that’d be great too.
However, I haven’t been able to make stdin work with anything but the functions that ncurses provides. It’d be fine on my part, to drop the inputwindow if that would get me the above benefits. But I’m not sure if it’s possible.
So,
- Is it possible to use
readlineor have such functionality usingncursesand the input function it provides ?
and/or - Is it possible and how can I have an empty line below the curses window, that would allow the user to give input using stdin directly (that is all the common read input functions, and thus even
readlinedirectly) ?
If those are doable, some simple code would be great, but guidance and pointers are great too. If not, it’d be great to know, and not waste time trying to make it work.
ncurses expects to control the entire screen. Mixing ncurses input/output with non-ncurses input/output might be possible but I wouldn’t recommend attempting it.
If you need readline style input within an ncurses program you will need to implement it yourself.
The form library (included with ncurses) allows you to define forms with editable fields. You will need to handle the history yourself though. These forms can be place in panels for easier control of placement on the screen.