Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用退格的NCurses_C_Ncurses_Curses_Getch - Fatal编程技术网

使用退格的NCurses

使用退格的NCurses,c,ncurses,curses,getch,C,Ncurses,Curses,Getch,你好,我有这个代码,退格是不正常工作 while((ch=getch())!='\n') { ++counter; noecho(); if (ch == KEY_BACKSPACE || ch == KEY_DC || ch == 127) { counter--; delch(); delch(); input[counter] = '\0'; } else { add

你好,我有这个代码,退格是不正常工作

 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();
退格字符未出现,这正是我想要的,但操作未完成

如果在getch调用之前启用echo,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);
}

另一种可能性是,终端描述terminfo可能与实际终端设置stty不一致。在这种情况下,ncurses将返回发送的任何密钥,它是ASCII DEL/127还是BS/8取决于您使用的系统。

您是否调用了keypadstdscr,对吗?是的,我调用了它,声明为int?是的,声明为int