當我在Vim內部並鍵入:ls
時,Vim列出緩衝區。最有可能的是使用def_prog_mode()
和endwin()
進入「熟化模式」。我想知道它如何打印這些值。我最喜歡的是使用system("echo ....")
這將是相當費力。 我試過printf
- 沒有效果,和printw
。Vim如何顯示:ls結果(詛咒/熟化模式)
我需要在我的應用程序中做同樣的事情,而不是創建Windows或彈出窗口,我想列出像Vim那樣的內部信息。
這裏是什麼,我已經嘗試了樣品,從http://gist.github.com/587622
#include <ncurses.h>
// it seems system echo is the only way to print some stuff in cooked mode
// i am trying to figure out how VIM displays the result of :ls
int main()
{
initscr(); /* Start curses mode */
printw("Hello World !!! Hit a key\n"); /* Print Hello World */
refresh(); /* Print it on to the real screen */
getch();
def_prog_mode(); /* Save the tty modes */
endwin(); /* End curses mode temporarily */
int i = 0;
for (i = 0; i < 5; i++) {
system("echo inside cooked mode");
}
//printf("helllow there\n");
//system("/bin/ls"); /* Do whatever you like in cooked mode */
//system("read");
//system("/bin/sh"); /* Do whatever you like in cooked mode */
//system("echo hit a key"); /* Do whatever you like in cooked mode */
//printw("Hit a key buddy\n"); /* Print Hello World */
reset_prog_mode(); /* Return to the previous tty mode*/
getch();
/* stored by def_prog_mode() */
refresh(); /* Do refresh() to restore the */
/* Screen contents */
printw("After cooked mode.\nKey to quit"); /* Back to curses use the full */
getch();
refresh(); /* capabilities of curses */
endwin(); /* End curses mode */
return 0;
}
使用編譯:
gcc -o a.out -lncurses a.c && ./a.out
是啊真是棒極了!因爲我實際上使用了ruby並且沒有用C語言寫了18年,所以沒有想到'fflush'。謝謝。 – rahul 2010-09-21 06:40:29
我有這個工作正常。但是,我看到在microemacs中,當鍵入C-x c進入shell時,它不會清除屏幕。由於'endwin()',Vim支持我的編程。如果我刪除'endwin',屏幕不會被清除。但返回後,它仍然滾動。我嘗試了def_shell_mode(???),但是這起來了。那麼如何保持現有的窗戶和麪板顯示並恢復乾淨。謝謝。 – rahul 2010-09-22 08:39:31
好吧,明白了,我們必須停止並重新啓動ncurses。 – rahul 2010-09-22 10:42:37