[comp.lang.c] Curses erase char question

ryan@sjuphil.uucp (Patrick M. Ryan) (10/25/90)

Why does Curses sometimes print out the erase character instead of
erasing the previous character like it supposed to?  I checked it
out with the erasechar() function and it does, in fact, know what
the erase character is.   The backspace on my keyboard is set
to '^?' and it works just fine in the shell.  the application i'm
writing has a command line interface and will be tedious to use if
the user cannot use the backspace.

thanks,
pat

-- 
patrick m. ryan
ryan@sju.edu  / ryan%sjuphil.sju.edu@sh.cs.net
{bpa|burdvax|princeton|rutgers}!sjuphil!ryan
pmr@gemini.gsfc.nasa.gov

draper@inmet.inmet.com (10/27/90)

/* Written  7:37 pm  Oct 24, 1990 by ryan@sjuphil.uucp in inmet:comp.lang.c */
/* ---------- "Curses erase char question" ---------- */

Why does Curses sometimes print out the erase character instead of
erasing the previous character like it supposed to?  I checked it
out with the erasechar() function and it does, in fact, know what
the erase character is.   The backspace on my keyboard is set
to '^?' and it works just fine in the shell.  the application i'm
writing has a command line interface and will be tedious to use if
the user cannot use the backspace.

thanks,
pat

-- 
patrick m. ryan
ryan@sju.edu  / ryan%sjuphil.sju.edu@sh.cs.net
{bpa|burdvax|princeton|rutgers}!sjuphil!ryan
pmr@gemini.gsfc.nasa.gov
/* End of text from inmet:comp.lang.c */


The first and most important question I would ask is:

What version of curses are you using?

I have used BSD, SysV, Aspen, Ultix, VMS and HP-UX curses. Different
versions of curses treat erasechar and killchar differently.

For instance with Aspen curses on the PC both Backspace and Del are
mapped to be erasechar. On BSD curses they usually use whatever has
been defined in the .login or .profile as the erasechar unless you have
updated it by using the stty erase command. With HP-UX erasechar and
killchar are not really characters but functions that return the
erasechar and killchar the current shell had defined when you started
up the windows with initscr.

The following are a few examples of how we deal with erasechar
and killchar in our applications.

VMS - Aspen Curses VMS
----------------------
#define CONTROL(x) (x-'A'+1) /* macro to get ascii value of a control char */
#ifndef erasechar
#define erasechar() CONTROL('H')
#endif
#ifndef killchar
#define killchar() CONTROL('Z');
#endif


PC - Aspen Curses
-----------------

#define CONTROL(x) (x-'A'+1) /* macro to get ascii value of a control char */
#undef killchar
#define killchar() CONTROL('X')

Like I said above on the PC both Backspace and Del are mapped to erasechar.


Sun - BSD Curses
----------------

#define erasechar() (_tty.sg_erase)
#define killchar() (_tty.sg_kill)

The above will map erasechar and kill to what was currently defined 
for the shell when the program was executed.


Other problems may have to do with how youy are collecting your
input. I usually set the mode to be raw with no echo. 
By using noecho you can "look" at the characters that you have
read in and decide if you want them echoed to the screen or not.
For maximum control over input and input echoing I recommend that
you do all input on character by character basis without echo and
then make a desicion if you are going to display the char read in
or not.

I would experiment around defining erasechar and killchar and see what
I could get working. Also play with raw mode and no echo .If you still
have problems email a minimal test case along with information on whatever
you are running for curses and the host, host version of the OS and I
will see what I can do.

- Dave 


Internet: draper@inmet.inmet.com
UUNET: uunet!inmet!draper
-----
Intermetrics Microsystems Software, Incorporated
733 Concord Avenue	   Cambridge,  MA  02138
(617) 661-0072 x4573

TIM@ENH.Prime.COM (10/30/90)

Seems like curses knows that your backspace is a ^?, but to print that at your
terminal does nothing but print "^?" instead of backspacing like you want.
Looking up erasechar() in a curses reference, it says:

erasechar(); /* return user's erase character */

Which is exactly what it is doing ... your OS will use a ^? as a backspace, (no
doubt catches the keypress and translates it into a backspace it can make use
of), but this does not apply to an application program ... try saving the
current backspace character at the beginning of your program, set it to the
default (probably ^h) for the length of the program, then restoring it upon
exiting. Hope this helps ...


/* Tim Cantin                                         1% of Americans retire
    Prime Computer, Inc., MS 10-13                    independently wealthy;
    500 Old Conn Path                             the other 99% are working,
    Framingham, Mass.  01701  (USA)          financially dependent, or dead.
   Phone: (508) 620-2800, ext. 3101                        What will you be?
   InterNet: TIM@ENH.Prime.COM
   Uucp:     {primerd, cvbnet, uunet}!ENH.Prime.COM!TIM
       -or-  {primerd, cvbnet, uunet}!hobbiton!tim                           */

#include "stddisclaimer.h"