首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用backspace的NCurses

使用backspace的NCurses
EN

Stack Overflow用户
提问于 2017-05-12 21:52:14
回答 1查看 1.2K关注 0票数 0

你好,我有这段代码,后置空间不能正常工作

代码语言:javascript
复制
 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();

后置空间的角色没有出现,这正是我想要的,但动作没有完成。

EN

回答 1

Stack Overflow用户

发布于 2017-05-12 22:44:32

如果echogetch调用之前打开,ncurses可能返回ASCII备份空间,例如8(与\b相同)。在源代码中,这是Solaris兼容性的一个特性:

代码语言:javascript
复制
    /*
     * 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取决于您使用的系统)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43946959

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档