How to use the pattern buffer of an ncurses menu?

18 views Asked by At

The https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/menus.html website says that each menu has an associated pattern buffer which can be used to find the nearest match to characters entered.

But I don't really understand how to use the functions they've given. I've tried the below code

#include <menu.h>
#include <curses.h>
void menu_display(int argc, char *argv[]) {
    ITEM **my_items;
    MENU *my_menu;
    WINDOW *my_menu_win, *title_win;
    
    initscr();
    cbreak();
    noecho();
    curs_set(0);
    keypad(stdscr,TRUE);
    // Initialize curses //

    // Initialize Variables //
    getmaxyx(stdscr, nlines, ncols);
    starty = 0;
    startx = 0;
    cur_win_index = 0;
    // Initialize Variables //


    // Create Menu Items and Menu //
    my_items = (ITEM **)calloc(argc, sizeof(ITEM *));
   
    for(i=0;i<argc;i++)  {
        sprintf(store[i],"%d",i+1);
        my_items[i] = new_item(store[i], argv[i]);
        set_item_userptr(my_items[i], name);
    }
    my_items[argc] = NULL;
    
    my_menu = new_menu((ITEM**)my_items);
    // Create Menu Items and Menu //

    
    // Create windows //

    title_win = newwin(3, ncols, starty, startx);
    my_menu_win = newwin(nlines-3, ncols, starty+3, startx);

    // Create windows //


    
    set_menu_win(my_menu, my_menu_win);
    set_menu_sub(my_menu, derwin(my_menu_win,nlines-4,ncols-10,1,1));     
  

   
    box(my_menu_win, 0, 0);
   
    
 
    wrefresh(title_win);

    post_menu(my_menu);
    wrefresh(my_menu_win);


    /* Main Loop */
    while((c=getch()) != 'q') {
        menu_driver(my_menu, REQ_NEXT_MATCH);
        wrefresh(my_menu_win);
    }
    /* Main Loop */
  
    
    // Free memory //
    unpost_menu(my_menu);
    free_menu(my_menu);
    for(i=0;i<argc;i++)
        free_item(my_items[i]);

    // Free memory //

    endwin();
}

Whenever I click on any key it just keeps jumping to the next item in the menu. How do I make it so that it works similar to search in vim?

0

There are 0 answers