你好,我有这段代码,后置空间不能正常工作
while((ch=getch())!='\n') {
++counter;
noecho();
if (ch == KEY_BACKSPACE || ch == KEY_DC || ch == 127) {
counter--;
delch();
delch();
input[counter] = '\0';
} else
{
addch(ch);
}
refresh();后置空间的角色没有出现,这正是我想要的,但动作没有完成。
发布于 2017-05-12 22:44:32
如果echo在getch调用之前打开,ncurses可能返回ASCII备份空间,例如8(与\b相同)。在源代码中,这是Solaris兼容性的一个特性:
/*
* If echo() is in effect, display the printable version of the
* key on the screen. Carriage return and backspace are treated
* specially by Solaris curses:
*
* If carriage return is defined as a function key in the
* terminfo, e.g., kent, then Solaris may return either ^J (or ^M
* if nonl() is set) or KEY_ENTER depending on the echo() mode.
* We echo before translating carriage return based on nonl(),
* since the visual result simply moves the cursor to column 0.
*
* Backspace is a different matter. Solaris curses does not
* translate it to KEY_BACKSPACE if kbs=^H. This does not depend
* on the stty modes, but appears to be a hardcoded special case.
* This is a difference from ncurses, which uses the terminfo entry.
* However, we provide the same visual result as Solaris, moving the
* cursor to the left.
*/
if (sp->_echo && !(win->_flags & _ISPAD)) {
chtype backup = (chtype) ((ch == KEY_BACKSPACE) ? '\b' : ch);
if (backup < KEY_MIN)
wechochar(win, backup);
}另一种可能性是终端描述(终止)可能与实际的终端设置(stty)不一致。在这种情况下,ncurses将返回所发送的任何密钥(无论是ASCII DEL / 127还是BS /8取决于您使用的系统)。
https://stackoverflow.com/questions/43946959
复制相似问题