2009-07-27 79 views
4

我有这个ncurses应用程序正在执行 的标准配方,暂时从ncurses中删除,运行一个外部的 editor/shell/whatever,然后在完成时退回到ncurses 。ncurses to external shell and back messing with keys

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

之前有人看到过这种行为,并知道这是什么魔术修正 这是什么?如果它有帮助,这是Ruby ncurses库。

回答

1

在绕过一点之后,我发现了一个货运解决方案:在stdscr上出壳后明确调用keypad(1)。我不知道为什么这个工作,但它确实。如果他们能解释为什么,我会将其他人的答案标记为是。 当前的工作原理是键盘触摸某种内部缓冲区并将其清除。

从头开始:

NCURSES_EXPORT(int) 
keypad(WINDOW *win, bool flag) 
{ 
    T((T_CALLED("keypad(%p,%d)"), win, flag)); 

    if (win) { 
     win->_use_keypad = flag; 
     returnCode(_nc_keypad(SP, flag)); 
    } else 
     returnCode(ERR); 
}
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的程序做的第一件事就是调用键盘(stdscr上,真),以实现漂亮的键盘映射。

希望有所帮助。

+0

因此,我在这里不理解的是它为什么在两次按键后“修复”自身。 – 2009-07-28 15:39:55