Skip to content

Commit a1f9346

Browse files
committed
add menu fore, back, and mark functions
1 parent 8223e1e commit a1f9346

1 file changed

Lines changed: 121 additions & 0 deletions

File tree

ext/curses/curses.c

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,6 +3632,121 @@ menu_set_format(VALUE obj, VALUE rows, VALUE cols)
36323632
return obj;
36333633
}
36343634

3635+
/*
3636+
* Document-method: Curses::Menu#mark=
3637+
*
3638+
* call-seq:
3639+
* mark=(str)
3640+
*
3641+
* Set the mark string to distinguish the selected items
3642+
*/
3643+
static VALUE
3644+
menu_set_mark(VALUE obj, VALUE mark)
3645+
{
3646+
struct menudata *menup;
3647+
3648+
GetMENU(obj, menup);
3649+
set_menu_mark(menup->menu, StringValueCStr(mark));
3650+
3651+
return obj;
3652+
}
3653+
3654+
/*
3655+
* Document-method: Curses::Menu#mark
3656+
*
3657+
* call-seq:
3658+
* mark
3659+
*
3660+
* Get the Menu's mark string
3661+
*/
3662+
static VALUE
3663+
menu_get_mark(VALUE obj)
3664+
{
3665+
struct menudata *menup;
3666+
const char *mark;
3667+
3668+
GetMENU(obj, menup);
3669+
mark = menu_mark(menup->menu);
3670+
3671+
return rb_external_str_new_with_enc(mark, strlen(mark), terminal_encoding);
3672+
}
3673+
3674+
/*
3675+
* Document-method: Curses::Menu#fore=
3676+
*
3677+
* call-seq:
3678+
* fore=(attr)
3679+
*
3680+
* Sets the foreground attribute of menu.
3681+
* This is the highlight used for selected menu items.
3682+
*/
3683+
static VALUE
3684+
menu_set_fore(VALUE obj, VALUE attr)
3685+
{
3686+
struct menudata *menup;
3687+
3688+
GetMENU(obj, menup);
3689+
set_menu_fore(menup->menu, NUM2CHTYPE(attr));
3690+
3691+
return attr;
3692+
}
3693+
3694+
/*
3695+
* Document-method: Curses::Menu#fore
3696+
*
3697+
* call-seq:
3698+
* fore
3699+
*
3700+
* Sets the foreground attribute of menu.
3701+
* This is the highlight used for selected menu items.
3702+
*/
3703+
static VALUE
3704+
menu_get_fore(VALUE obj, VALUE attr)
3705+
{
3706+
struct menudata *menup;
3707+
3708+
GetMENU(obj, menup);
3709+
3710+
return CHTYPE2NUM(menu_fore(menup->menu));
3711+
}
3712+
3713+
/*
3714+
* Document-method: Curses::Menu#set_back
3715+
*
3716+
* call-seq:
3717+
* set_back(attr)
3718+
*
3719+
* Get the background attribute of menu.
3720+
*/
3721+
static VALUE
3722+
menu_set_back(VALUE obj, VALUE attr)
3723+
{
3724+
struct menudata *menup;
3725+
3726+
GetMENU(obj, menup);
3727+
CHTYPE2NUM(set_menu_back(menup->menu, NUM2CHTYPE(attr)));
3728+
3729+
return attr;
3730+
}
3731+
3732+
/*
3733+
* Document-method: Curses::Menu#back
3734+
*
3735+
* call-seq:
3736+
* back
3737+
*
3738+
* Get the background attribute of menu.
3739+
*/
3740+
static VALUE
3741+
menu_get_back(VALUE obj, VALUE attr)
3742+
{
3743+
struct menudata *menup;
3744+
3745+
GetMENU(obj, menup);
3746+
3747+
return CHTYPE2NUM(menu_back(menup->menu));
3748+
}
3749+
36353750
/*
36363751
* Document-method: Curses::Menu#format
36373752
*
@@ -5003,6 +5118,12 @@ Init_curses(void)
50035118
rb_define_method(cMenu, "scale", menu_scale, 0);
50045119
rb_define_method(cMenu, "set_format", menu_set_format, 2);
50055120
rb_define_method(cMenu, "format", menu_format_m, 0);
5121+
rb_define_method(cMenu, "mark=", menu_set_mark, 1);
5122+
rb_define_method(cMenu, "mark", menu_get_mark, 0);
5123+
rb_define_method(cMenu, "fore=", menu_set_fore, 1);
5124+
rb_define_method(cMenu, "fore", menu_get_fore, 0);
5125+
rb_define_method(cMenu, "back=", menu_set_back, 1);
5126+
rb_define_method(cMenu, "back", menu_get_back, 0);
50065127
rb_define_method(cMenu, "set_opts", menu_set_opts, 1);
50075128
rb_define_method(cMenu, "opts_on", menu_opts_on_m, 1);
50085129
rb_define_method(cMenu, "opts_off", menu_opts_off_m, 1);

0 commit comments

Comments
 (0)