C 如何在另一个窗口中实现滚动窗口?

C 如何在另一个窗口中实现滚动窗口?,c,ncurses,C,Ncurses,我将命令行应用程序嵌入到ncurses TUI中。 如果需要,我的应用程序(客户机/服务器)应该能够打印很多批次行,但它必须保留在我定义的窗口中: /* Removed code */ ITEM **my_items; int c; MENU *my_menu; WINDOW *my_menu_win; int n_choices, i; // Initialize curses initscr();

我将命令行应用程序嵌入到ncurses TUI中。 如果需要,我的应用程序(客户机/服务器)应该能够打印很多批次行,但它必须保留在我定义的窗口中:

    /* Removed code */
    ITEM **my_items;
    int c;
    MENU *my_menu;
    WINDOW *my_menu_win;
    int n_choices, i;

    // Initialize curses
    initscr();                              // initializes the screen
    start_color();
    cbreak();
    noecho();
    keypad(stdscr, TRUE);
    init_pair(1, COLOR_RED, COLOR_BLACK);
    /* Removed code */
    /* Create items */
    n_choices = ARRAY_SIZE(choices);
    my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
    for(i = 0; i < n_choices; ++i)
    {
        my_items[i] = new_item(choices[i], choices[i]);
    }

    /* Removed code */
    /* Create menu */
    my_menu = new_menu((ITEM **)my_items);

    /* Set menu option not to show the description */
    menu_opts_off(my_menu, O_SHOWDESC);

    /* Create the window to be associated with the menu */
    my_menu_win = newwin(WIN_HEIGHT, WIN_WIDTH, WIN_YPOS, WIN_XPOS);
    keypad(my_menu_win, TRUE);

    /* Set main window and sub window */
    set_menu_win(my_menu, my_menu_win);
    set_menu_sub(my_menu, derwin(my_menu_win,  WIN_HEIGHT/2, WIN_WIDTH/2, WIN_HEIGHT/2-3, WIN_WIDTH/2-10));

    /* Set menu mark to the string " * " */
    set_menu_mark(my_menu, ">");

    /* Print a border around the main window and print a title */
    box(my_menu_win, 0, 0);
    /* Removed code */
    /* Post the menu */
    post_menu(my_menu);
    wrefresh(my_menu_win);

    endwin();       //resets the screen
}
/*删除的代码*/
项目**我的项目;
INTC;
菜单*我的菜单;
窗口*我的菜单\u赢;
int n_选择,i;
//初始化诅咒
initscr();//初始化屏幕
启动颜色();
cbreak();
noecho();
键盘(stdscr,真);
初始对(1,红色,黑色);
/*删除的代码*/
/*创建项目*/
n_选项=数组大小(选项);
my_items=(ITEM**)calloc(n_选项,sizeof(ITEM*);
对于(i=0;i”);
/*在主窗口周围打印边框并打印标题*/
框(我的菜单,0,0);
/*删除的代码*/
/*张贴菜单*/
后菜单(我的菜单);
wrefresh(我的菜单);
endwin()//重置屏幕
}

1如何在此窗口中添加一个带有滚动内容的窗口,以便打印通常发送到终端的所有输出


2…或者是否可以将该窗口与终端输出链接?

问题不清楚:显示的唯一有趣的窗口是菜单。快速测试表明,当一次显示的菜单项太多时,菜单库滚动菜单内容以显示菜单项。您可以创建另一个(例如)暂时遮挡菜单窗口的窗口;不过,如果你把窗口布置得不重叠,使用起来会更容易。问题不清楚:显示的唯一有趣的窗口是菜单。快速测试表明,当一次显示的菜单项太多时,菜单库滚动菜单内容以显示菜单项。您可以创建另一个(例如)暂时遮挡菜单窗口的窗口;但是,如果您将窗口布置为不重叠,则使用起来会更方便。