diff --git a/ext/curses/curses.c b/ext/curses/curses.c index def8c6db..c8858299 100644 --- a/ext/curses/curses.c +++ b/ext/curses/curses.c @@ -2810,6 +2810,31 @@ window_getbkgd(VALUE obj) #endif } +/* + * Document-method: Curses::Window.chgat + * call-seq: chgat(n, attrs) + * + * Changes the attributes of a given number of characters starting at + * the current cursor location. + */ +static VALUE +window_chgat(VALUE obj, VALUE n, VALUE attrs) +{ +#ifdef HAVE_WCHGAT + chtype a = NUM2CHTYPE(attrs); + attr_t attr; + short pair; + struct windata *winp; + + GetWINDOW(obj,winp); + attr = a & A_ATTRIBUTES; + pair = PAIR_NUMBER(attr); + return (wchgat(winp->window, NUM2INT(n), attr, pair, NULL) == OK) ? Qtrue : Qfalse; +#else + return Qnil; +#endif +} + /* * Document-method: Curses::Window.resize * call-seq: resize(lines, cols) @@ -5064,6 +5089,7 @@ Init_curses(void) rb_define_method(cWindow, "bkgdset", window_bkgdset, 1); rb_define_method(cWindow, "bkgd", window_bkgd, 1); rb_define_method(cWindow, "getbkgd", window_getbkgd, 0); + rb_define_method(cWindow, "chgat", window_chgat, 2); rb_define_method(cWindow, "nodelay=", window_nodelay, 1); rb_define_method(cWindow, "timeout=", window_timeout, 1); diff --git a/ext/curses/extconf.rb b/ext/curses/extconf.rb index f405f9ce..2a356f5e 100644 --- a/ext/curses/extconf.rb +++ b/ext/curses/extconf.rb @@ -121,7 +121,8 @@ def exec_command(cmd) touchwin untouchwin wtouchln is_linetouched is_wintouched def_prog_mode reset_prog_mode timeout wtimeout nodelay init_color wcolor_set use_default_colors assume_default_colors - newpad unget_wch get_wch wget_wch PDC_get_key_modifiers) + newpad unget_wch get_wch wget_wch PDC_get_key_modifiers + chgat wchgat) have_func(f) || (have_macro(f, curses) && $defs.push(format("-DHAVE_%s", f.upcase))) end convertible_int('chtype', [["#undef MOUSE_MOVED\n"]]+curses) or abort diff --git a/sample/attr_demo.rb b/sample/attr_demo.rb index f28bc123..8c90704e 100644 --- a/sample/attr_demo.rb +++ b/sample/attr_demo.rb @@ -26,7 +26,9 @@ addstr([*('a'..'z'), *('0'..'9')].join + "\n") } getch - + setpos(0, 0) + Curses.stdscr.chgat(6, A_UNDERLINE) + getch ensure close_screen end \ No newline at end of file