Skip to content

Commit 8b08999

Browse files
authored
Merge pull request #66 from Isty001/master
add missing flushinp, menu mark, fore and back functions
2 parents d3b8aae + a1f9346 commit 8b08999

1 file changed

Lines changed: 136 additions & 0 deletions

File tree

ext/curses/curses.c

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,20 @@ curses_nonl(VALUE obj)
620620
return Qnil;
621621
}
622622

623+
/*
624+
* Document-method: Curses.flushinp
625+
*
626+
* The flushinp routine throws away any typeahead that has been
627+
* typed by the user and has not yet been read by the program.
628+
*/
629+
static VALUE
630+
curses_flushinp(VALUE obj)
631+
{
632+
curses_stdscr();
633+
flushinp();
634+
return Qnil;
635+
}
636+
623637
/*
624638
* Document-method: Curses.beep
625639
*
@@ -3618,6 +3632,121 @@ menu_set_format(VALUE obj, VALUE rows, VALUE cols)
36183632
return obj;
36193633
}
36203634

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+
36213750
/*
36223751
* Document-method: Curses::Menu#format
36233752
*
@@ -4753,6 +4882,7 @@ Init_curses(void)
47534882
rb_define_module_function(mCurses, "nocrmode", curses_nocbreak, 0);
47544883
rb_define_module_function(mCurses, "nl", curses_nl, 0);
47554884
rb_define_module_function(mCurses, "nonl", curses_nonl, 0);
4885+
rb_define_module_function(mCurses, "flushinp", curses_flushinp, 0);
47564886
rb_define_module_function(mCurses, "beep", curses_beep, 0);
47574887
rb_define_module_function(mCurses, "flash", curses_flash, 0);
47584888
rb_define_module_function(mCurses, "ungetch", curses_ungetch, 1);
@@ -4988,6 +5118,12 @@ Init_curses(void)
49885118
rb_define_method(cMenu, "scale", menu_scale, 0);
49895119
rb_define_method(cMenu, "set_format", menu_set_format, 2);
49905120
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);
49915127
rb_define_method(cMenu, "set_opts", menu_set_opts, 1);
49925128
rb_define_method(cMenu, "opts_on", menu_opts_on_m, 1);
49935129
rb_define_method(cMenu, "opts_off", menu_opts_off_m, 1);

0 commit comments

Comments
 (0)