summaryrefslogtreecommitdiff
path: root/ext/-test-/win32
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-15 12:13:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-15 12:13:35 +0000
commitffd0301a35d0829e21f2510265355896497e1a9c (patch)
tree0487b622c6c882d2fff83d752ce4a8d4a8d81b1b /ext/-test-/win32
parentf7d0059e3643ad1713b8abe4969147e2bc185d75 (diff)
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
Diffstat (limited to 'ext/-test-/win32')
-rw-r--r--ext/-test-/win32/console/attribute.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/ext/-test-/win32/console/attribute.c b/ext/-test-/win32/console/attribute.c
index a2c07fc..6d706fb 100644
--- a/ext/-test-/win32/console/attribute.c
+++ b/ext/-test-/win32/console/attribute.c
@@ -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;
}