summaryrefslogtreecommitdiff
path: root/ext/-test-
diff options
context:
space:
mode:
Diffstat (limited to 'ext/-test-')
-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 a2c07fc4fe..6d706fbfe7 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;
}