5

我有这个 ncurses 应用程序正在执行标准配方,用于暂时退出 ncurses,运行外部编辑器/shell/任何东西,然后在完成后返回到 ncurses。

这几乎可以工作,除了 ncurses 之后得到的前几次按键显然是假的;如果我按两次向上箭头,ncurses 认为 ^[ 和 A 分别被看到。

任何人以前见过这种行为并且知道解决这个问题的魔法是什么?如果有帮助的话,这就是 Ruby ncurses 库。

4

2 回答 2

1

在扎根之后,我找到了一个货物培养解决方案:在 stdscr 上取出 shell 后显式调用 keypad(1)。我不知道为什么会这样,但确实如此。如果他们能解释原因,我会将其他人的答案标记为是。 当前的工作理论是键盘触摸某种内部缓冲区并将其清除。

从头开始:

NCURSES_EXPORT(int)
键盘(WINDOW *win,布尔标志)
{
    T((T_CALLED("键盘(%p,%d)"), win, flag));

    如果(赢){
        win->_use_keypad = 标志;
        returnCode(_nc_keypad(SP, flag));
    } 别的
        返回码(错误);
}
于 2009-07-27T19:18:56.310 回答
0

是的。如果没有键盘,ncurses 将无法为您处理转义码。从键盘手册页:

   The keypad option enables the keypad of the user's  terminal.   If  en-
   abled (bf is TRUE), the user can press a function key (such as an arrow
   key) and wgetch returns a single value representing the  function  key,
   as in KEY_LEFT.  If disabled (bf is FALSE), curses does not treat func-
   tion keys specially and the program has to  interpret  the  escape  se-
   quences  itself.   If the keypad in the terminal can be turned on (made
   to transmit) and off (made to work locally),  turning  on  this  option
   causes  the terminal keypad to be turned on when wgetch is called.  The
   default value for keypad is false.

通常,我在 ncurses 程序中做的第一件事是调用 keypad(stdscr, true) 来启用漂亮的键盘映射。

希望有帮助。

于 2009-07-28T14:18:17.107 回答