Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions ext/curses/curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion ext/curses/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion sample/attr_demo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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