class Curses::Menu

Public Class Methods

new(items) 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;
    ID id_new;

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

        if (RB_TYPE_P(item, T_ARRAY)) {
            item = rb_apply(cItem, id_new, item);
        }
        GetITEM(item, itemp);
        menu_items[i] = itemp->item;
        rb_ary_push(menup->items, item);
    }
    menu_items[RARRAY_LEN(items)] = NULL;
    menup->menu = new_menu(menu_items);
    if (menup->menu == NULL) {
        check_curses_error(errno);
    }

    return obj;
}

Public Instance Methods

back click to toggle source

Get the background attribute of menu.

static VALUE
menu_get_back(VALUE obj, VALUE attr)
{
    struct menudata *menup;

    GetMENU(obj, menup);

    return CHTYPE2NUM(menu_back(menup->menu));
}
set_back(attr) click to toggle source

Get the background attribute of menu.

static VALUE
menu_set_back(VALUE obj, VALUE attr)
{
    struct menudata *menup;

    GetMENU(obj, menup);
    CHTYPE2NUM(set_menu_back(menup->menu, NUM2CHTYPE(attr)));

    return attr;
}
back_pattern() click to toggle source
# File lib/curses.rb, line 76
def back_pattern
  driver(Curses::REQ_BACK_PATTERN)
end
clear_pattern() click to toggle source
# File lib/curses.rb, line 72
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 32
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 52
def first_item
  driver(Curses::REQ_FIRST_ITEM)
end
fore click to toggle source

Sets the foreground attribute of menu. This is the highlight used for selected menu items.

static VALUE
menu_get_fore(VALUE obj, VALUE attr)
{
    struct menudata *menup;

    GetMENU(obj, menup);

    return CHTYPE2NUM(menu_fore(menup->menu));
}
fore=(attr) click to toggle source

Sets the foreground attribute of menu. This is the highlight used for selected menu items.

static VALUE
menu_set_fore(VALUE obj, VALUE attr)
{
    struct menudata *menup;

    GetMENU(obj, menup);
    set_menu_fore(menup->menu, NUM2CHTYPE(attr));

    return attr;
}
format click to toggle source

Get the maximum size of the menu.

static VALUE
menu_format_m(VALUE obj)
{
    struct menudata *menup;
    int rows, cols;

    GetMENU(obj, menup);
    menu_format(menup->menu, &rows, &cols);
    return rb_assoc_new(INT2NUM(rows), INT2NUM(cols));
}
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 56
def last_item
  driver(Curses::REQ_LAST_ITEM)
end
left_item() click to toggle source
# File lib/curses.rb, line 20
def left_item
  driver(Curses::REQ_LEFT_ITEM)
end
mark click to toggle source

Get the Menu’s mark string

static VALUE
menu_get_mark(VALUE obj)
{
    struct menudata *menup;
    const char *mark;

    GetMENU(obj, menup);
    mark = menu_mark(menup->menu);

    return rb_external_str_new_with_enc(mark, strlen(mark), terminal_encoding);
}
mark=(str) click to toggle source

Set the mark string to distinguish the selected items

static VALUE
menu_set_mark(VALUE obj, VALUE mark)
{
    struct menudata *menup;

    GetMENU(obj, menup);
    set_menu_mark(menup->menu, StringValueCStr(mark));

    return obj;
}
next_item() click to toggle source
# File lib/curses.rb, line 60
def next_item
  driver(Curses::REQ_NEXT_ITEM)
end
next_match() click to toggle source
# File lib/curses.rb, line 80
def next_match
  driver(Curses::REQ_NEXT_MATCH)
end
opts click to toggle source

Get the current option bits of the menu.

static VALUE
menu_opts_m(VALUE obj, VALUE opts)
{
    struct menudata *menup;

    GetMENU(obj, menup);
    return INT2NUM(menu_opts(menup->menu));
}
opts_off(opts) click to toggle source

Turn off the option bits of the menu.

static VALUE
menu_opts_off_m(VALUE obj, VALUE opts)
{
    struct menudata *menup;
    int error;

    GetMENU(obj, menup);
    error = menu_opts_off(menup->menu, NUM2INT(opts));
    check_curses_error(error);
    return obj;
}
opts_on(opts) click to toggle source

Turn on the option bits of the menu.

static VALUE
menu_opts_on_m(VALUE obj, VALUE opts)
{
    struct menudata *menup;
    int error;

    GetMENU(obj, menup);
    error = menu_opts_on(menup->menu, NUM2INT(opts));
    check_curses_error(error);
    return obj;
}
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 64
def prev_item
  driver(Curses::REQ_PREV_ITEM)
end
prev_match() click to toggle source
# File lib/curses.rb, line 84
def prev_match
  driver(Curses::REQ_PREV_MATCH)
end
right_item() click to toggle source
# File lib/curses.rb, line 24
def right_item
  driver(Curses::REQ_RIGHT_ITEM)
end
scale click to toggle source

Return the minimum rows and columns required for the subwindow of the menu.

static VALUE
menu_scale(VALUE obj)
{
    struct menudata *menup;
    int error, rows, columns;

    GetMENU(obj, menup);
    error = scale_menu(menup->menu, &rows, &columns);
    check_curses_error(error);
    return rb_assoc_new(INT2NUM(rows), INT2NUM(columns));
}
scroll_down_line() click to toggle source
# File lib/curses.rb, line 40
def scroll_down_line
  driver(Curses::REQ_SCR_DLINE)
end
scroll_down_page() click to toggle source
# File lib/curses.rb, line 48
def scroll_down_page
  driver(Curses::REQ_SCR_DPAGE)
end
scroll_up_line() click to toggle source
# File lib/curses.rb, line 36
def scroll_up_line
  driver(Curses::REQ_SCR_ULINE)
end
scroll_up_page() click to toggle source
# File lib/curses.rb, line 44
def scroll_up_page
  driver(Curses::REQ_SCR_UPAGE)
end
set_format(rows, cols) click to toggle source

Set the maximum size of the menu.

static VALUE
menu_set_format(VALUE obj, VALUE rows, VALUE cols)
{
    struct menudata *menup;
    int error;

    GetMENU(obj, menup);
    error = set_menu_format(menup->menu, NUM2INT(rows), NUM2INT(cols));
    check_curses_error(error);
    return obj;
}
set_opts(opts) click to toggle source

Set the option bits of the menu.

static VALUE
menu_set_opts(VALUE obj, VALUE opts)
{
    struct menudata *menup;
    int error;

    GetMENU(obj, menup);
    error = set_menu_opts(menup->menu, NUM2INT(opts));
    check_curses_error(error);
    return obj;
}
set_sub=(win) click to toggle source

Set the subwindow of the menu.

static VALUE
menu_set_sub(VALUE obj, VALUE win)
{
    struct menudata *menup;
    struct windata *winp;

    GetMENU(obj, menup);
    GetWINDOW(win, winp);
    set_menu_sub(menup->menu, winp->window);
    return win;
}
set_win=(win) click to toggle source

Set the window of the menu.

static VALUE
menu_set_win(VALUE obj, VALUE win)
{
    struct menudata *menup;
    struct windata *winp;

    GetMENU(obj, menup);
    GetWINDOW(win, winp);
    set_menu_win(menup->menu, winp->window);
    return win;
}
toggle_item() click to toggle source
# File lib/curses.rb, line 68
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 28
def up_item
  driver(Curses::REQ_UP_ITEM)
end