What's a way to implement backspace working in field in ncurses

940 views Asked by At

I am try to create tui via ncurses. And I have same problem. There are two fields:

Name
_______

Password
_______

How to implement backspace-support in each field ? And how to use '*' to show each character in password-field ? (Now I use field_opts_off(field[1], O_PUBLIC);and it doesn't show characters in password-field, only move cursor).

Thank you.

2

There are 2 answers

0
Thomas Dickey On BEST ANSWER

There is no tutorial for the forms package that I recall. However, the ncurses test-programs (which are available separately as ncurses-examples) contains a program demo_forms which does implement deletion by maintaining the edited field contents as a hidden field buffer, and decrementing its length in the case for REQ_DEL_CHAR.

Here is a screenshot of the program:

enter image description here

Regarding the "non-ncurses" suggestion: dialog is a curses/ncurses application, and has no particular dependency upon bash.

0
skrtbhtngr On

"Non-ncurses" solution (just for an alternative):

You can use dialog program to perform this task in a very easy way. Just run some linux system commands from C to achieve a nice TUI.

If you want to install it, the package name is dialog too.

For a textfield, you can do: dialog --inputbox <text> <height> <width> [<init>] For a password field: dialog --passwordbox <text> <height> <width> [<init>]

For more info: http://bash.cyberciti.biz/guide/Bash_display_dialog_boxes