Class: Curses::Menu
- Inherits:
-
Data
- Object
- Data
- Curses::Menu
- Defined in:
- ext/curses/curses.c,
lib/curses.rb
Instance Method Summary collapse
- #back_pattern ⇒ Object
- #clear_pattern ⇒ Object
-
#current_item ⇒ Object
call-seq: current_item.
-
#current_item=(item) ⇒ Object
call-seq: current_item=(item).
- #down_item ⇒ Object
-
#driver(command) ⇒ Object
call-seq: driver(command).
- #first_item ⇒ Object
-
#format ⇒ Object
call-seq: format.
-
#initialize(items) ⇒ Object
constructor
call-seq: new(items).
-
#item_count ⇒ Object
call-seq: item_count.
-
#items ⇒ Object
call-seq: items.
-
#items=(items) ⇒ Object
call-seq: items=(items).
- #last_item ⇒ Object
- #left_item ⇒ Object
- #next_item ⇒ Object
- #next_match ⇒ Object
-
#opts(opts) ⇒ Object
call-seq: opts.
-
#opts_off(opts) ⇒ Object
call-seq: opts_off(opts).
-
#opts_on(opts) ⇒ Object
call-seq: opts_on(opts).
-
#post ⇒ Object
call-seq: post.
- #prev_item ⇒ Object
- #prev_match ⇒ Object
- #right_item ⇒ Object
-
#scale ⇒ Object
call-seq: scale.
- #scroll_down_line ⇒ Object
- #scroll_down_page ⇒ Object
- #scroll_up_line ⇒ Object
- #scroll_up_page ⇒ Object
-
#set_format(rows, cols) ⇒ Object
call-seq: set_format(rows, cols).
-
#set_opts(opts) ⇒ Object
call-seq: set_opts(opts).
-
#set_sub(win) ⇒ Object
call-seq: set_sub=(win).
-
#set_win(win) ⇒ Object
call-seq: set_win=(win).
- #toggle_item ⇒ Object
-
#unpost ⇒ Object
call-seq: unpost.
- #up_item ⇒ Object
Constructor Details
#initialize(items) ⇒ Object
call-seq:
new(items)
Construct a new Curses::Menu.
3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 |
# File 'ext/curses/curses.c', line 3303
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();
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;
}
|
Instance Method Details
#back_pattern ⇒ Object
83 84 85 |
# File 'lib/curses.rb', line 83 def back_pattern driver(Curses::REQ_BACK_PATTERN) end |
#clear_pattern ⇒ Object
79 80 81 |
# File 'lib/curses.rb', line 79 def clear_pattern driver(Curses::REQ_CLEAR_PATTERN) end |
#current_item ⇒ Object
call-seq:
current_item
Returns the current item.
3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 |
# File 'ext/curses/curses.c', line 3493
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) ⇒ Object
call-seq:
current_item=(item)
Sets the current item.
3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 |
# File 'ext/curses/curses.c', line 3515
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 ⇒ Object
39 40 41 |
# File 'lib/curses.rb', line 39 def down_item driver(Curses::REQ_DOWN_ITEM) end |
#driver(command) ⇒ Object
call-seq:
driver(command)
Perform the command on the menu.
3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 |
# File 'ext/curses/curses.c', line 3390
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 ⇒ Object
59 60 61 |
# File 'lib/curses.rb', line 59 def first_item driver(Curses::REQ_FIRST_ITEM) end |
#format ⇒ Object
call-seq:
format
Get the maximum size of the menu.
3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 |
# File 'ext/curses/curses.c', line 3615
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 ⇒ Object
call-seq:
item_count
Returns the count of items in the menu.
3411 3412 3413 3414 3415 3416 3417 3418 |
# File 'ext/curses/curses.c', line 3411
static VALUE
menu_item_count(VALUE obj)
{
struct menudata *menup;
GetMENU(obj, menup);
return INT2NUM(item_count(menup->menu));
}
|
#items ⇒ Object
call-seq:
items
Returns the items of the menu.
3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 |
# File 'ext/curses/curses.c', line 3428
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) ⇒ Object
call-seq:
items=(items)
Returns the items of the menu.
3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 |
# File 'ext/curses/curses.c', line 3457
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 ⇒ Object
63 64 65 |
# File 'lib/curses.rb', line 63 def last_item driver(Curses::REQ_LAST_ITEM) end |
#left_item ⇒ Object
27 28 29 |
# File 'lib/curses.rb', line 27 def left_item driver(Curses::REQ_LEFT_ITEM) end |
#next_item ⇒ Object
67 68 69 |
# File 'lib/curses.rb', line 67 def next_item driver(Curses::REQ_NEXT_ITEM) end |
#next_match ⇒ Object
87 88 89 |
# File 'lib/curses.rb', line 87 def next_match driver(Curses::REQ_NEXT_MATCH) end |
#opts(opts) ⇒ Object
call-seq:
opts
Get the current option bits of the menu.
3694 3695 3696 3697 3698 3699 3700 3701 |
# File 'ext/curses/curses.c', line 3694
static VALUE
menu_opts_m(VALUE obj, VALUE opts)
{
struct menudata *menup;
GetMENU(obj, menup);
return INT2NUM(menu_opts(menup->menu));
}
|
#opts_off(opts) ⇒ Object
call-seq:
opts_off(opts)
Turn off the option bits of the menu.
3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 |
# File 'ext/curses/curses.c', line 3674
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) ⇒ Object
call-seq:
opts_on(opts)
Turn on the option bits of the menu.
3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 |
# File 'ext/curses/curses.c', line 3654
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 ⇒ Object
call-seq:
post
Post the menu.
3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 |
# File 'ext/curses/curses.c', line 3348
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 ⇒ Object
71 72 73 |
# File 'lib/curses.rb', line 71 def prev_item driver(Curses::REQ_PREV_ITEM) end |
#prev_match ⇒ Object
91 92 93 |
# File 'lib/curses.rb', line 91 def prev_match driver(Curses::REQ_PREV_MATCH) end |
#right_item ⇒ Object
31 32 33 |
# File 'lib/curses.rb', line 31 def right_item driver(Curses::REQ_RIGHT_ITEM) end |
#scale ⇒ Object
call-seq:
scale
Return the minimum rows and columns required for the subwindow of the menu.
3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 |
# File 'ext/curses/curses.c', line 3575
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 ⇒ Object
47 48 49 |
# File 'lib/curses.rb', line 47 def scroll_down_line driver(Curses::REQ_SCR_DLINE) end |
#scroll_down_page ⇒ Object
55 56 57 |
# File 'lib/curses.rb', line 55 def scroll_down_page driver(Curses::REQ_SCR_DPAGE) end |
#scroll_up_line ⇒ Object
43 44 45 |
# File 'lib/curses.rb', line 43 def scroll_up_line driver(Curses::REQ_SCR_ULINE) end |
#scroll_up_page ⇒ Object
51 52 53 |
# File 'lib/curses.rb', line 51 def scroll_up_page driver(Curses::REQ_SCR_UPAGE) end |
#set_format(rows, cols) ⇒ Object
call-seq:
set_format(rows, cols)
Set the maximum size of the menu.
3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 |
# File 'ext/curses/curses.c', line 3595
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) ⇒ Object
call-seq:
set_opts(opts)
Set the option bits of the menu.
3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 |
# File 'ext/curses/curses.c', line 3634
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) ⇒ Object
call-seq:
set_sub=(win)
Set the subwindow of the menu.
3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 |
# File 'ext/curses/curses.c', line 3555
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) ⇒ Object
call-seq:
set_win=(win)
Set the window of the menu.
3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 |
# File 'ext/curses/curses.c', line 3535
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 ⇒ Object
75 76 77 |
# File 'lib/curses.rb', line 75 def toggle_item driver(Curses::REQ_TOGGLE_ITEM) end |
#unpost ⇒ Object
call-seq:
unpost
Unpost the menu.
3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 |
# File 'ext/curses/curses.c', line 3369
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 ⇒ Object
35 36 37 |
# File 'lib/curses.rb', line 35 def up_item driver(Curses::REQ_UP_ITEM) end |