2009-07-27 122 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