2

在 linux 终端中以非规范模式使用退格的简单方法是什么?

这是代码的一部分,当我设置标志时:

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) {...}
 }

当我按退格键时,我得到一个

^?

. 但我需要删除最后一个符号..

谢谢你。

4

2 回答 2

2

我不认为这是可能的。根据tcsetattr()手册页(强调我的):

在非规范模式下,输入立即可用(用户无需键入行分隔符),并且行编辑被禁用

此外,如果你的程序立即接收到你输入的每一个字符,它怎么会再次被“带走”呢?

于 2014-02-27T17:10:07.257 回答
-1

在您的 linux 终端中执行此操作并像往常一样进行编码,它不会显示 ^?当你使用退格键时。

您也可以将其添加到您的 .profile 中作为永久文件。

 stty erase ^?
于 2014-02-27T14:42:57.377 回答