# class Curses::Menu

### Public Class Methods

new(name, description) click to toggle source

Construct a new Curses::Menu.

    static VALUE
    menu_initialize(VALUE obj, VALUE items)
    {
        struct menudata *menup;
        ITEM **menu_items;
        int i;

        Check_Type(items, T_ARRAY);
        curses_init_screen();
        TypedData_Get_Struct(obj, struct menudata, &menudata_type, menup);
        if (menup->menu) {
            rb_raise(rb_eRuntimeError, "already initialized menu");
        }
        menu_items = ALLOC_N(ITEM *, RARRAY_LEN(items) + 1);
        for (i = 0; i < RARRAY_LEN(items); i++) {
            struct itemdata *itemp;

            GetITEM(RARRAY_AREF(items, i), itemp);
            menu_items[i] = itemp->item;
        }
        menu_items[RARRAY_LEN(items)] = NULL;
        menup->menu = new_menu(menu_items);
        if (menup->menu == NULL) {
            check_curses_error(errno);
        }
        menup->items = rb_ary_dup(items);

        return obj;
    }

### Public Instance Methods

back_pattern() click to toggle source

    # File lib/curses.rb, line 83
    def back_pattern
      driver(Curses::REQ_BACK_PATTERN)
    end

clear_pattern() click to toggle source

    # File lib/curses.rb, line 79
    def clear_pattern
      driver(Curses::REQ_CLEAR_PATTERN)
    end

current_item click to toggle source

Returns the current item.

    static VALUE
    menu_get_current_item(VALUE obj)
    {
        struct menudata *menup;
        ITEM *item;

        GetMENU(obj, menup);
        item = current_item(menup->menu);
        if (item == NULL) {
            return Qnil;
        }
        return item_new(item);
    }

current_item=(item) click to toggle source

Sets the current item.

    static VALUE
    menu_set_current_item(VALUE obj, VALUE item)
    {
        struct menudata *menup;
        struct itemdata *itemp;

        GetMENU(obj, menup);
        GetITEM(item, itemp);
        set_current_item(menup->menu, itemp->item);
        return item;
    }

down_item() click to toggle source

    # File lib/curses.rb, line 39
    def down_item
      driver(Curses::REQ_DOWN_ITEM)
    end

driver(command) click to toggle source

Perform the command on the menu.

    static VALUE
    menu_driver_m(VALUE obj, VALUE command)
    {
        struct menudata *menup;
        int error;

        GetMENU(obj, menup);
        error = menu_driver(menup->menu, NUM2INT(command));
        check_curses_error(error);

        return obj;
    }

first_item() click to toggle source

    # File lib/curses.rb, line 59
    def first_item
      driver(Curses::REQ_FIRST_ITEM)
    end

item_count click to toggle source

Returns the count of items in the menu.

    static VALUE
    menu_item_count(VALUE obj)
    {
        struct menudata *menup;

        GetMENU(obj, menup);
        return INT2NUM(item_count(menup->menu));
    }

items click to toggle source

Returns the items of the menu.

    static VALUE
    menu_get_items(VALUE obj)
    {
        struct menudata *menup;
        ITEM **items;
        int count, i;
        VALUE ary;

        GetMENU(obj, menup);
        items = menu_items(menup->menu);
        if (items == NULL) {
            return Qnil;
        }
        count = item_count(menup->menu);
        ary = rb_ary_new();
        for (i = 0; i < count; i++) {
            rb_ary_push(ary, item_new(items[i]));
        }
        return ary;
    }

items=(items) click to toggle source

Returns the items of the menu.

    static VALUE
    menu_set_items(VALUE obj, VALUE items)
    {
        struct menudata *menup;
        ITEM **old_items, **new_items;
        int i, error;

        Check_Type(items, T_ARRAY);
        GetMENU(obj, menup);
        old_items = menu_items(menup->menu);
        new_items = ALLOC_N(ITEM*, RARRAY_LEN(items) + 1);
        for (i = 0; i < RARRAY_LEN(items); i++) {
            struct itemdata *itemp;
            GetITEM(RARRAY_AREF(items, i), itemp);
            new_items[i] = itemp->item;
        }
        new_items[RARRAY_LEN(items)] = NULL;
        error = set_menu_items(menup->menu, new_items);
        if (error != E_OK) {
            xfree(new_items);
            check_curses_error(error);
            return items;
        }
        xfree(old_items);
        menup->items = rb_ary_dup(items);
        return items;
    }

last_item() click to toggle source

    # File lib/curses.rb, line 63
    def last_item
      driver(Curses::REQ_LAST_ITEM)
    end

left_item() click to toggle source

    # File lib/curses.rb, line 27
    def left_item
      driver(Curses::REQ_LEFT_ITEM)
    end

next_item() click to toggle source

    # File lib/curses.rb, line 67
    def next_item
      driver(Curses::REQ_NEXT_ITEM)
    end

next_match() click to toggle source

    # File lib/curses.rb, line 87
    def next_match
      driver(Curses::REQ_NEXT_MATCH)
    end

post click to toggle source

Post the menu.

    static VALUE
    menu_post(VALUE obj)
    {
        struct menudata *menup;
        int error;

        GetMENU(obj, menup);
        error = post_menu(menup->menu);
        check_curses_error(error);

        return obj;
    }

prev_item() click to toggle source

    # File lib/curses.rb, line 71
    def prev_item
      driver(Curses::REQ_PREV_ITEM)
    end

prev_match() click to toggle source

    # File lib/curses.rb, line 91
    def prev_match
      driver(Curses::REQ_PREV_MATCH)
    end

right_item() click to toggle source

    # File lib/curses.rb, line 31
    def right_item
      driver(Curses::REQ_RIGHT_ITEM)
    end

scroll_down_line() click to toggle source

    # File lib/curses.rb, line 47
    def scroll_down_line
      driver(Curses::REQ_SCR_DLINE)
    end

scroll_down_page() click to toggle source

    # File lib/curses.rb, line 55
    def scroll_down_page
      driver(Curses::REQ_SCR_DPAGE)
    end

scroll_up_line() click to toggle source

    # File lib/curses.rb, line 43
    def scroll_up_line
      driver(Curses::REQ_SCR_ULINE)
    end

scroll_up_page() click to toggle source

    # File lib/curses.rb, line 51
    def scroll_up_page
      driver(Curses::REQ_SCR_UPAGE)
    end

toggle_item() click to toggle source

    # File lib/curses.rb, line 75
    def toggle_item
      driver(Curses::REQ_TOGGLE_ITEM)
    end

unpost click to toggle source

Unpost the menu.

    static VALUE
    menu_unpost(VALUE obj)
    {
        struct menudata *menup;
        int error;

        GetMENU(obj, menup);
        error = unpost_menu(menup->menu);
        check_curses_error(error);

        return obj;
    }

up_item() click to toggle source

    # File lib/curses.rb, line 35
    def up_item
      driver(Curses::REQ_UP_ITEM)
    end