vim - Vim 如何显示 :ls results (curses/cooked mode)

标签 vim ncurses

当我在 Vim 中输入 :ls 时,Vim 会列出缓冲区。最有可能的是,它使用 def_prog_mode()endwin() 进入“煮熟模式”。我想知道它如何打印这些值。我得出的最好的结果是使用 system("echo ....") 这将是相当费力的。 我尝试过 printf - 没有效果,并且 printw

我需要在我的应用程序中做同样的事情,而不是创建窗口或弹出窗口,我想像 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

最佳答案

您可能只需要使用fflush刷新stdio缓冲区。也就是说,使用 printf 写入一些文本后,调用 fflush(stdout) 以确保文本发送到终端。 ncurses 可能正在调用 setbufsetvbuf 来启用到终端的 block 缓冲 IO,这不被视为保存和恢复的 tty 模式的一部分。

关于vim - Vim 如何显示 :ls results (curses/cooked mode),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3749916/

相关文章:

更改背景颜色会使程序出错? (诅咒)

c - C 和 ncurses 中的结构体数组

vim - 替换行号列中的 ~

vim - Vim 自动关闭大引号

vim - 在vi中打开所有文件(包括隐藏的)

Vim mksession 将变量作为文字

linux - 用于 Linux 的 CLI pdf 查看器

c++ - Ncurses CTRL + s 挂起 getch()

linux - 如何安装 ncursesw 开发库

search - Vim:搜索并突出显示但不跳转