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
This commit is contained in:
parent
43b00d8a11
commit
34ec7c5b49
@ -18,6 +18,17 @@ console_info(VALUE io)
|
|||||||
INT2FIX(csbi.wAttributes));
|
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 FOREGROUND_MASK (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)
|
||||||
#define BACKGROUND_MASK (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
|
#define BACKGROUND_MASK (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
|
||||||
|
|
||||||
@ -29,6 +40,7 @@ Init_attribute(VALUE m)
|
|||||||
"cur_x", "cur_y",
|
"cur_x", "cur_y",
|
||||||
"attr", NULL);
|
"attr", NULL);
|
||||||
rb_define_method(rb_cIO, "console_info", console_info, 0);
|
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_MASK", INT2FIX(FOREGROUND_MASK));
|
||||||
rb_define_const(m, "FOREGROUND_BLUE", INT2FIX(FOREGROUND_BLUE));
|
rb_define_const(m, "FOREGROUND_BLUE", INT2FIX(FOREGROUND_BLUE));
|
||||||
|
@ -4,13 +4,12 @@ if /mswin|mingw/ =~ RUBY_PLATFORM and STDOUT.tty?
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
|
||||||
class Test_Win32Console < Test::Unit::TestCase
|
class Test_Win32Console < Test::Unit::TestCase
|
||||||
def setup
|
def reset
|
||||||
print "\e[m!"
|
STDOUT.console_attribute(7)
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
alias setup reset
|
||||||
print "\e[m!"
|
alias teardown reset
|
||||||
end
|
|
||||||
|
|
||||||
def test_default
|
def test_default
|
||||||
info = STDOUT.console_info
|
info = STDOUT.console_info
|
||||||
|
Loading…
x
Reference in New Issue
Block a user