mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
win32/console: io_handle
* ext/-test-/win32/console/attribute.c (io_handle): extract conversion from IO instance to HANDLE. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f7d0059e36
commit
ffd0301a35
1 changed files with 16 additions and 8 deletions
|
@ -2,29 +2,37 @@
|
|||
|
||||
static VALUE rb_cConsoleScreenBufferInfo;
|
||||
|
||||
static VALUE
|
||||
console_info(VALUE io)
|
||||
static HANDLE
|
||||
io_handle(VALUE io)
|
||||
{
|
||||
int fd = NUM2INT(rb_funcallv(io, rb_intern("fileno"), 0, 0));
|
||||
HANDLE h = (HANDLE)rb_w32_get_osfhandle(fd);
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
|
||||
if (h == (HANDLE)-1) rb_raise(rb_eIOError, "invalid io");
|
||||
return h;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
console_info(VALUE io)
|
||||
{
|
||||
HANDLE h = io_handle(io);
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
|
||||
if (!GetConsoleScreenBufferInfo(h, &csbi))
|
||||
rb_syserr_fail(rb_w32_map_errno(GetLastError()), "not console");
|
||||
return rb_struct_new(rb_cConsoleScreenBufferInfo,
|
||||
INT2FIX(csbi.dwSize.X), INT2FIX(csbi.dwSize.Y),
|
||||
INT2FIX(csbi.dwCursorPosition.X), INT2FIX(csbi.dwCursorPosition.Y),
|
||||
INT2FIX(csbi.dwSize.X),
|
||||
INT2FIX(csbi.dwSize.Y),
|
||||
INT2FIX(csbi.dwCursorPosition.X),
|
||||
INT2FIX(csbi.dwCursorPosition.Y),
|
||||
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);
|
||||
HANDLE h = io_handle(io);
|
||||
|
||||
if (h == (HANDLE)-1) rb_raise(rb_eIOError, "invalid io");
|
||||
SetConsoleTextAttribute(h, (WORD)NUM2INT(attr));
|
||||
return Qnil;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue