summaryrefslogtreecommitdiff
path: root/ext/-test-/win32/console
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-21 08:10:34 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-21 08:10:34 +0000
commit43b00d8a118e946e57fae4b6a192d3b0e832cf1e (patch)
treeb2bfaa4fb5df353a13067cc5003c83eaf23c7821 /ext/-test-/win32/console
parent4d9de3db0a9c84a8e0cb1564af348df4ed21dff2 (diff)
win32.c: manage reverse video
* win32/win32.c (constat_attr): manage reverse video internally since Windows console window does not manage it. based on the patch by white leaf in [ruby-dev:48483]. [Bug #10158] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/-test-/win32/console')
-rw-r--r--ext/-test-/win32/console/attribute.c44
-rw-r--r--ext/-test-/win32/console/depend1
-rw-r--r--ext/-test-/win32/console/extconf.rb8
-rw-r--r--ext/-test-/win32/console/init.c11
4 files changed, 64 insertions, 0 deletions
diff --git a/ext/-test-/win32/console/attribute.c b/ext/-test-/win32/console/attribute.c
new file mode 100644
index 0000000..6b8bd96
--- /dev/null
+++ b/ext/-test-/win32/console/attribute.c
@@ -0,0 +1,44 @@
+#include <ruby.h>
+
+static VALUE rb_cConsoleScreenBufferInfo;
+
+static VALUE
+console_info(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");
+ 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.wAttributes));
+}
+
+#define FOREGROUND_MASK (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)
+#define BACKGROUND_MASK (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
+
+void
+Init_attribute(VALUE m)
+{
+ rb_cConsoleScreenBufferInfo = rb_struct_define_under(m, "ConsoleScreenBufferInfo",
+ "size_x", "size_y",
+ "cur_x", "cur_y",
+ "attr", NULL);
+ rb_define_method(rb_cIO, "console_info", console_info, 0);
+
+ rb_define_const(m, "FOREGROUND_MASK", INT2FIX(FOREGROUND_MASK));
+ rb_define_const(m, "FOREGROUND_BLUE", INT2FIX(FOREGROUND_BLUE));
+ rb_define_const(m, "FOREGROUND_GREEN", INT2FIX(FOREGROUND_GREEN));
+ rb_define_const(m, "FOREGROUND_RED", INT2FIX(FOREGROUND_RED));
+ rb_define_const(m, "FOREGROUND_INTENSITY", INT2FIX(FOREGROUND_INTENSITY));
+
+ rb_define_const(m, "BACKGROUND_MASK", INT2FIX(BACKGROUND_MASK));
+ rb_define_const(m, "BACKGROUND_BLUE", INT2FIX(BACKGROUND_BLUE));
+ rb_define_const(m, "BACKGROUND_GREEN", INT2FIX(BACKGROUND_GREEN));
+ rb_define_const(m, "BACKGROUND_RED", INT2FIX(BACKGROUND_RED));
+ rb_define_const(m, "BACKGROUND_INTENSITY", INT2FIX(BACKGROUND_INTENSITY));
+}
diff --git a/ext/-test-/win32/console/depend b/ext/-test-/win32/console/depend
new file mode 100644
index 0000000..f4f65ad
--- /dev/null
+++ b/ext/-test-/win32/console/depend
@@ -0,0 +1 @@
+attribute.o: $(ruby_headers) $(hdrdir)/ruby/win32.h
diff --git a/ext/-test-/win32/console/extconf.rb b/ext/-test-/win32/console/extconf.rb
new file mode 100644
index 0000000..4de9fa7
--- /dev/null
+++ b/ext/-test-/win32/console/extconf.rb
@@ -0,0 +1,8 @@
+if $mingw or $mswin
+ $srcs = Dir[File.join($srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
+ inits = $srcs.map {|s| File.basename(s, ".*")}
+ inits.delete("init")
+ inits.map! {|s|"X(#{s})"}
+ $defs << "-DTEST_INIT_FUNCS(X)=\"#{inits.join(' ')}\""
+ create_makefile("-test-/win32/console")
+end
diff --git a/ext/-test-/win32/console/init.c b/ext/-test-/win32/console/init.c
new file mode 100644
index 0000000..f2e0d1c
--- /dev/null
+++ b/ext/-test-/win32/console/init.c
@@ -0,0 +1,11 @@
+#include "ruby.h"
+
+#define init(n) {void Init_##n(VALUE m); Init_##n(m);}
+
+void
+Init_console(void)
+{
+ VALUE mBug = rb_define_module("Bug");
+ VALUE m = rb_define_module_under(mBug, "Win32");
+ TEST_INIT_FUNCS(init);
+}