Class: Curses::Menu
- Inherits:
-
Object
- Object
- Curses::Menu
- Defined in:
- ext/curses/curses.c,
lib/curses.rb
Instance Method Summary collapse
-
#back ⇒ Object
call-seq: back.
-
#back=(attr) ⇒ Object
call-seq: set_back(attr).
- #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
-
#fore ⇒ Object
call-seq: fore.
-
#fore=(attr) ⇒ Object
call-seq: fore=(attr).
-
#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
-
#mark ⇒ Object
call-seq: mark.
-
#mark=(mark) ⇒ Object
call-seq: mark=(str).
- #next_item ⇒ Object
- #next_match ⇒ Object
-
#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.
3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 |
# File 'ext/curses/curses.c', line 3611
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;
}
|
Instance Method Details
#back ⇒ Object
call-seq:
back
Get the background attribute of menu.
4020 4021 4022 4023 4024 4025 4026 4027 4028 |
# File 'ext/curses/curses.c', line 4020
static VALUE
menu_get_back(VALUE obj)
{
struct menudata *menup;
GetMENU(obj, menup);
return CHTYPE2NUM(menu_back(menup->menu));
}
|
#back=(attr) ⇒ Object
call-seq:
set_back(attr)
Get the background attribute of menu.
4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 |
# File 'ext/curses/curses.c', line 4001
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 ⇒ Object
76 77 78 |
# File 'lib/curses.rb', line 76 def back_pattern driver(Curses::REQ_BACK_PATTERN) end |
#clear_pattern ⇒ Object
72 73 74 |
# File 'lib/curses.rb', line 72 def clear_pattern driver(Curses::REQ_CLEAR_PATTERN) end |
#current_item ⇒ Object
call-seq:
current_item
Returns the current item.
3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 |
# File 'ext/curses/curses.c', line 3801
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.
3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 |
# File 'ext/curses/curses.c', line 3823
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
32 33 34 |
# File 'lib/curses.rb', line 32 def down_item driver(Curses::REQ_DOWN_ITEM) end |
#driver(command) ⇒ Object
call-seq:
driver(command)
Perform the command on the menu.
3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 |
# File 'ext/curses/curses.c', line 3698
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
52 53 54 |
# File 'lib/curses.rb', line 52 def first_item driver(Curses::REQ_FIRST_ITEM) end |
#fore ⇒ Object
call-seq:
fore
Sets the foreground attribute of menu. This is the highlight used for selected menu items.
3983 3984 3985 3986 3987 3988 3989 3990 3991 |
# File 'ext/curses/curses.c', line 3983
static VALUE
menu_get_fore(VALUE obj)
{
struct menudata *menup;
GetMENU(obj, menup);
return CHTYPE2NUM(menu_fore(menup->menu));
}
|
#fore=(attr) ⇒ Object
call-seq:
fore=(attr)
Sets the foreground attribute of menu. This is the highlight used for selected menu items.
3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 |
# File 'ext/curses/curses.c', line 3963
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 ⇒ Object
call-seq:
format
Get the maximum size of the menu.
4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 |
# File 'ext/curses/curses.c', line 4038
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.
3719 3720 3721 3722 3723 3724 3725 3726 |
# File 'ext/curses/curses.c', line 3719
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.
3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 |
# File 'ext/curses/curses.c', line 3736
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.
3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 |
# File 'ext/curses/curses.c', line 3765
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
56 57 58 |
# File 'lib/curses.rb', line 56 def last_item driver(Curses::REQ_LAST_ITEM) end |
#left_item ⇒ Object
20 21 22 |
# File 'lib/curses.rb', line 20 def left_item driver(Curses::REQ_LEFT_ITEM) end |
#mark ⇒ Object
call-seq:
mark
Get the Menu’s mark string
3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 |
# File 'ext/curses/curses.c', line 3942
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=(mark) ⇒ Object
call-seq:
mark=(str)
Set the mark string to distinguish the selected items
3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 |
# File 'ext/curses/curses.c', line 3923
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 ⇒ Object
60 61 62 |
# File 'lib/curses.rb', line 60 def next_item driver(Curses::REQ_NEXT_ITEM) end |
#next_match ⇒ Object
80 81 82 |
# File 'lib/curses.rb', line 80 def next_match driver(Curses::REQ_NEXT_MATCH) end |
#opts ⇒ Object
call-seq:
opts
Get the current option bits of the menu.
4117 4118 4119 4120 4121 4122 4123 4124 |
# File 'ext/curses/curses.c', line 4117
static VALUE
menu_opts_m(VALUE obj)
{
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.
4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 |
# File 'ext/curses/curses.c', line 4097
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.
4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 |
# File 'ext/curses/curses.c', line 4077
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.
3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 |
# File 'ext/curses/curses.c', line 3656
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
64 65 66 |
# File 'lib/curses.rb', line 64 def prev_item driver(Curses::REQ_PREV_ITEM) end |
#prev_match ⇒ Object
84 85 86 |
# File 'lib/curses.rb', line 84 def prev_match driver(Curses::REQ_PREV_MATCH) end |
#right_item ⇒ Object
24 25 26 |
# File 'lib/curses.rb', line 24 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.
3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 |
# File 'ext/curses/curses.c', line 3883
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
40 41 42 |
# File 'lib/curses.rb', line 40 def scroll_down_line driver(Curses::REQ_SCR_DLINE) end |
#scroll_down_page ⇒ Object
48 49 50 |
# File 'lib/curses.rb', line 48 def scroll_down_page driver(Curses::REQ_SCR_DPAGE) end |
#scroll_up_line ⇒ Object
36 37 38 |
# File 'lib/curses.rb', line 36 def scroll_up_line driver(Curses::REQ_SCR_ULINE) end |
#scroll_up_page ⇒ Object
44 45 46 |
# File 'lib/curses.rb', line 44 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.
3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 |
# File 'ext/curses/curses.c', line 3903
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.
4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 |
# File 'ext/curses/curses.c', line 4057
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.
3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 |
# File 'ext/curses/curses.c', line 3863
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.
3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 |
# File 'ext/curses/curses.c', line 3843
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
68 69 70 |
# File 'lib/curses.rb', line 68 def toggle_item driver(Curses::REQ_TOGGLE_ITEM) end |
#unpost ⇒ Object
call-seq:
unpost
Unpost the menu.
3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 |
# File 'ext/curses/curses.c', line 3677
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
28 29 30 |
# File 'lib/curses.rb', line 28 def up_item driver(Curses::REQ_UP_ITEM) end |