Ncurses and Linux pipeline

前端 未结 2 1152
被撕碎了的回忆
被撕碎了的回忆 2021-01-15 15:00

I\'d like to write a simple program using ncurses for displaying some data. I would then like for the program to write to stdout in such a way that I can then use a pipe (|

2条回答
  •  有刺的猬
    2021-01-15 15:23

    By default, curses writes to the standard output, which is where your pipe goes. But there are two different initialization functions for curses: initscr and newterm. The latter lets you do what was asked, like this:

    #include 
    #include 
    
    
    int main(int _argc, char ** _argv)
    {
        newterm(NULL, stderr, stdin);          /* Start curses mode          */    
        printw("Hello World !!!");  /* Print Hello World          */    
        refresh();          /* Print it on to the real screen */    
        getch();            /* Wait for user input */    
        printf("GOT HERE");    
        endwin();           /* End curses mode        */    
        printf("GOT HERE");    
        return 0;
    }
    

    Further reading: manual page for newterm and initscr.

提交回复
热议问题