Skip to content

Commit 2539b97

Browse files
authored
Merge pull request #100 from ruby/chgat
Add Window#chgat
2 parents 6d23270 + 96d3b25 commit 2539b97

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

ext/curses/curses.c

+26
Original file line numberDiff line numberDiff line change
@@ -2810,6 +2810,31 @@ window_getbkgd(VALUE obj)
28102810
#endif
28112811
}
28122812

2813+
/*
2814+
* Document-method: Curses::Window.chgat
2815+
* call-seq: chgat(n, attrs)
2816+
*
2817+
* Changes the attributes of a given number of characters starting at
2818+
* the current cursor location.
2819+
*/
2820+
static VALUE
2821+
window_chgat(VALUE obj, VALUE n, VALUE attrs)
2822+
{
2823+
#ifdef HAVE_WCHGAT
2824+
chtype a = NUM2CHTYPE(attrs);
2825+
attr_t attr;
2826+
short pair;
2827+
struct windata *winp;
2828+
2829+
GetWINDOW(obj,winp);
2830+
attr = a & A_ATTRIBUTES;
2831+
pair = PAIR_NUMBER(attr);
2832+
return (wchgat(winp->window, NUM2INT(n), attr, pair, NULL) == OK) ? Qtrue : Qfalse;
2833+
#else
2834+
return Qnil;
2835+
#endif
2836+
}
2837+
28132838
/*
28142839
* Document-method: Curses::Window.resize
28152840
* call-seq: resize(lines, cols)
@@ -5064,6 +5089,7 @@ Init_curses(void)
50645089
rb_define_method(cWindow, "bkgdset", window_bkgdset, 1);
50655090
rb_define_method(cWindow, "bkgd", window_bkgd, 1);
50665091
rb_define_method(cWindow, "getbkgd", window_getbkgd, 0);
5092+
rb_define_method(cWindow, "chgat", window_chgat, 2);
50675093

50685094
rb_define_method(cWindow, "nodelay=", window_nodelay, 1);
50695095
rb_define_method(cWindow, "timeout=", window_timeout, 1);

ext/curses/extconf.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def exec_command(cmd)
121121
touchwin untouchwin wtouchln is_linetouched is_wintouched
122122
def_prog_mode reset_prog_mode timeout wtimeout nodelay
123123
init_color wcolor_set use_default_colors assume_default_colors
124-
newpad unget_wch get_wch wget_wch PDC_get_key_modifiers)
124+
newpad unget_wch get_wch wget_wch PDC_get_key_modifiers
125+
chgat wchgat)
125126
have_func(f) || (have_macro(f, curses) && $defs.push(format("-DHAVE_%s", f.upcase)))
126127
end
127128
convertible_int('chtype', [["#undef MOUSE_MOVED\n"]]+curses) or abort

sample/attr_demo.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
addstr([*('a'..'z'), *('0'..'9')].join + "\n")
2727
}
2828
getch
29-
29+
setpos(0, 0)
30+
Curses.stdscr.chgat(6, A_UNDERLINE)
31+
getch
3032
ensure
3133
close_screen
3234
end

0 commit comments

Comments
 (0)