当我在 Vim 中输入 时:ls
,Vim 会列出缓冲区。很可能它正在使用def_prog_mode()
and进入“熟模式” endwin()
。我想知道它是如何打印这些值的。我得出的最好的结果是使用system("echo ....")
它会非常费力。我试过了printf
- 没有效果,而且printw
.
我需要在我的应用程序中做同样的事情,而不是创建 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