ncurses到外部shell并且后面弄乱键

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

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

以前有人看过这种行为并知道解决这个问题的神奇之处是什么? 如果它有帮助,这是Ruby ncurses库。

在稍微挖了一下之后,我发现了一个货物结果解决方案:在stdscr上取出shell后明确调用键盘(1)。 我不知道为什么会这样,但确实如此。 如果他们可以解释原因,我会将其他人的答案标记为是。 当前的工作原理是键盘接触某种内部缓冲区并清除它。

抓一点:

  NCURSES_EXPORT(INT)
键盘(WINDOW * win,bool flag)
 {
     T((T_CALLED(“键盘(%p,%d)”),win,flag));

     if(win){
         win  - > _ use_keypad = flag;
         returnCode(_nc_keypad(SP,flag));
    其他
         RETURNCODE(ERR);
 } 

是啊。 没有键盘,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程序中做的第一件事是调用键盘(stdscr,true)来启用漂亮的键盘映射。

希望有所帮助。