summaryrefslogtreecommitdiff
path: root/ext/-test-/win32
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-21 13:10:34 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-21 13:10:34 +0000
commit34ec7c5b496fb4dad4536b6e71333484f1d99c4f (patch)
tree7ee556792f9b217dc13d1685744545926863efaa /ext/-test-/win32
parent43b00d8a118e946e57fae4b6a192d3b0e832cf1e (diff)
win32/test_console_attr.rb: reset attributes
* ext/-test-/win32/console/attribute.c (console_set_attribute): set console attribute. * test/-ext-/win32/test_console_attr.rb (reset): reset attributes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/-test-/win32')
-rw-r--r--ext/-test-/win32/console/attribute.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/ext/-test-/win32/console/attribute.c b/ext/-test-/win32/console/attribute.c
index 6b8bd96..8941272 100644
--- a/ext/-test-/win32/console/attribute.c
+++ b/ext/-test-/win32/console/attribute.c
@@ -18,6 +18,17 @@ console_info(VALUE io)
INT2FIX(csbi.wAttributes));
}
+static VALUE
+console_set_attribute(VALUE io, VALUE attr)
+{
+ int fd = NUM2INT(rb_funcallv(io, rb_intern("fileno"), 0, 0));
+ HANDLE h = (HANDLE)rb_w32_get_osfhandle(fd);
+
+ if (h == (HANDLE)-1) rb_raise(rb_eIOError, "invalid io");
+ SetConsoleTextAttribute(h, NUM2INT(attr));
+ return Qnil;
+}
+
#define FOREGROUND_MASK (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)
#define BACKGROUND_MASK (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
@@ -29,6 +40,7 @@ Init_attribute(VALUE m)
"cur_x", "cur_y",
"attr", NULL);
rb_define_method(rb_cIO, "console_info", console_info, 0);
+ rb_define_method(rb_cIO, "console_attribute", console_set_attribute, 1);
rb_define_const(m, "FOREGROUND_MASK", INT2FIX(FOREGROUND_MASK));
rb_define_const(m, "FOREGROUND_BLUE", INT2FIX(FOREGROUND_BLUE));