2

What's a simple way to using backspace in non canonical mode in linux terminal ?

It's part of code, when i set flags:

struct termios old_tio, new_tio;
/* get the terminal settings for stdin */
tcgetattr(STDIN_FILENO, &old_tio);
/* we want to keep the old setting to restore them a the end */
new_tio = old_tio;
/* disable canonical mode (buffered i/o) and local echo */
new_tio.c_lflag &=(~ICANON );/*& ~ECHOE  );*/
/* set the new settings immediately */
tcsetattr(STDIN_FILENO,TCSANOW,&new_tio);
for(;1;) {    

    c = getchar(); 
    switch(c) {...}
 }

And when i press backspace i get an

^?

. But i need to erase last symbol..

Thank you.

pandreym
  • 137
  • 1
  • 3
  • 11

2 Answers2

2

I don't think it's possible. According to the tcsetattr() man page (emphasis mine):

In noncanonical mode input is available immediately (without the user having to type a line-delimiter character), and line editing is disabled.

Besides, if your program immediately receives every character you type, how can it be 'taken away' again?

Ingo Leonhardt
  • 9,435
  • 2
  • 24
  • 33
-1

Do this in your linux terminal and do your coding as usual it will not show ^? when u use backspace.

You can also add this in your .profile as permanent.

 stty erase ^?
arunb2w
  • 1,196
  • 9
  • 28
  • when u login to the terminal itself you must do this – arunb2w Feb 27 '14 at 14:47
  • Why i type a command in my terminal, like cd, pwd, ls and other, and when i press an backspace - it's all good, symbol erase. When i run my program and disable canonical mode - i get an ^? . – pandreym Feb 27 '14 at 14:48
  • now, i relaunch terminal, enter you command, after run my programm, but nothing happens. When i press backspace i have an ^?. (#>blablabla) I get (#>blablabla^?) – pandreym Feb 27 '14 at 14:52