How to delete a character

Hi,

T think this is a question for Perderabo.
If you think you know the answer you must be very good ! :slight_smile:

Most of us know how the make the <backspace> key backspace a character.
Now how do I make the <delete> key delete a character.

!! So when I press the delete key the character after my current cursor position gets deleted. !!

Running "stty erase ^?" makes the delete key performing a backspace.
Now what do I need to run to make the delete key delete.

Some background info might be that I use Midnight Commander for Unix. It has several types of terminals where I can define the erase function, etc.. However per default in a Unix dtterm the delete key does print a ^? or performs a backspace.

Hope it's clear and someone knows the answer.

Regs David

I was looking around a bit and found several sources saying it's not possible, since there is no stty setting for delete-next-character.

oombera's right, the standard tty driver does not support an option to delete the character after the cursor. So the answer to your question is to write your own tty driver. But before you do that, think about why unix has no such option.

When the driver is reading in canonical mode, it is collecting a line of characters. When it has a complete line, the read() system call will complete and the line will be delivered to the program that issued the read. The characters are collected from the keyboard, not the screen. In fact, there may not even be a screen. Remember that the tty driver is prepared to work fine with a printing terminal like the old asr-33.

In canonical mode, the user can edit the line. There is a notion of an erase character that removes the last character typed from the input line. There are options to control what is echoed to the display when the erase character is typed. Unless you are using a printing terminal, you should set echoe. echoe makes the erase character echo as BS-SP-BS. This removes the last character typed from the screen.

To the tty driver, any characters on the screen ahead of the cursor are garbage. They have no bearing on the input line being collected, anymore than a pre-typed character on a sheet of paper in a printing terminal would.

The notion of deleting a character after a cursor would make sense in the context of a full screen editor. emacs does this. But emacs has an in-core copy of the contents of the screen and it is using the tty driver in raw mode. There is no reason to bless this behavior as the official definition of "delete" as you seem to be doing.

I arrange for my backspace key to to be my erase character and my delete key to be my kill character. I set echoe as I mentioned. If I have echoke, I use that, otherwise I use echok. In my mind, my delete key deletes.

Originally, the delete key really deleted. In the 60's I used to type in fortran programs on an asr-33 using paper tape. If I typed a character in error, I would backspace the paper tape and type a delete character. Since the delete character is 177, this drilled all possible holes on the paper tape. Then I could dial the computer and send the program in. All software always ignored delete characters completely so the deleted characters were simply not there.

Hi Perderabo / Oombera,

Thanks for your help and very detailed explanation !!

There was one thing that hit my attention :

quote:
--------------------------------------------------------------------------------
In the 60's I used to type in fortran programs
--------------------------------------------------------------------------------

I don't think I was there yet by that time and You just showed your self a little

Thanks a lot for your explenation !! I can rest now in the knowledge of knowing there is no solution possible for me

Best regs David

(sorry i hit edit on mistake) - optimus_p