Using the “alternate screen” in a bash script

后端 未结 3 1341
深忆病人
深忆病人 2020-11-30 21:23

The alternate screen is used by many \"user-interactive\" terminal applications like vim, htop, screen, alsamixer, less, ... It is like a different buffer of the te

3条回答
  •  一整个雨季
    2020-11-30 22:12

    For C console application:

    ncurses

    Wikipedia:

    ncurses (new curses) is a programming library that provides an API which allows the programmer to write text-based user interfaces in a terminal-independent manner.

    less uses this library.

    A hello world program from here, to compile it in gcc, flag -lncurses is needed.

    #include 
    
    int main()
    {   
        initscr();          /* Start curses mode          */
        printw("Hello World !!!");  /* Print Hello World          */
        refresh();          /* Print it on to the real screen */
        getch();            /* Wait for user input */
        endwin();           /* End curses mode        */
    
        return 0;
    }
    

提交回复
热议问题