[SOLVED] Cannot get ncurses to delete a char with '\b' on screen in linux (c++)
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Cannot get ncurses to delete a char with '\b' on screen in linux (c++)
Hello.
I've modified a program to show * instead of letters when typing a password. I'm trying to make it so that when pressing backspace a * will be removed.
Here's a rough example. The problem is that when trying to do this in the real program, '\b' is not recognized as backspace. Does anyone have an idea why?
Have you tried checking against the ASCII code for the Backspace character by using a different constant or escape sequence? (ctrl-h) or \010 (in octal).
I suggest trying to figure out what is stored in that character variable and then find a way to specify that as a literal. It seems the \b escape code isn't getting it done.
That said, I'd test for KEY_BACKSPACE, not '\b', for anything returned by character grab from ncurses.
Thank you for your answer. Your answer made me think a little and i pulled out gdb and debugged the code. It seems that my backspace button is not the same as '\b' but in my case '\177' (DEL) button.
I'm not sure if this is ncurses, bash, ubuntu or the kernel driver that is to blame.
So if anyone gets the problem that your backspace doesn't work see if it might be using something else on the ascii chart.
You're getting the DEL key from your character grab for your specific terminal mapping. It's possible running your program on another terminal will result in your program breaking because on another terminal you may really get \010 (BACKSPACE). So generally it's best to check against constants defined for keys in ncurses.h or possibly in keymap files.
In otherwords, for portability I'd check for DELETE and BACKSPACE.
These are the kind of "gotchas" you run into when writing code that uses terminal command sets for graphics. :-/
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
Rep:
Quote:
Originally Posted by rnesius
You're getting the DEL key from your character grab for your specific terminal mapping. It's possible running your program on another terminal will result in your program breaking because on another terminal you may really get \010 (BACKSPACE). So generally it's best to check against constants defined for keys in ncurses.h or possibly in keymap files.
In otherwords, for portability I'd check for DELETE and BACKSPACE.
These are the kind of "gotchas" you run into when writing code that uses terminal command sets for graphics. :-/
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.