[前][次][番号順一覧][スレッド一覧]

ruby-changes:35160

From: nobu <ko1@a...>
Date: Thu, 21 Aug 2014 22:10:48 +0900 (JST)
Subject: [ruby-changes:35160] nobu:r47242 (trunk): win32/test_console_attr.rb: reset attributes

nobu	2014-08-21 22:10:34 +0900 (Thu, 21 Aug 2014)

  New Revision: 47242

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47242

  Log:
    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.

  Modified files:
    trunk/ext/-test-/win32/console/attribute.c
    trunk/test/-ext-/win32/test_console_attr.rb
Index: ext/-test-/win32/console/attribute.c
===================================================================
--- ext/-test-/win32/console/attribute.c	(revision 47241)
+++ ext/-test-/win32/console/attribute.c	(revision 47242)
@@ -18,6 +18,17 @@ console_info(VALUE io) https://github.com/ruby/ruby/blob/trunk/ext/-test-/win32/console/attribute.c#L18
 			 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 BACKGROUND_MASK (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
 
@@ -29,6 +40,7 @@ Init_attribute(VALUE m) https://github.com/ruby/ruby/blob/trunk/ext/-test-/win32/console/attribute.c#L40
 							 "cur_x", "cur_y",
 							 "attr", NULL);
     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_BLUE", INT2FIX(FOREGROUND_BLUE));
Index: test/-ext-/win32/test_console_attr.rb
===================================================================
--- test/-ext-/win32/test_console_attr.rb	(revision 47241)
+++ test/-ext-/win32/test_console_attr.rb	(revision 47242)
@@ -4,13 +4,12 @@ if /mswin|mingw/ =~ RUBY_PLATFORM and ST https://github.com/ruby/ruby/blob/trunk/test/-ext-/win32/test_console_attr.rb#L4
   require 'test/unit'
 
   class Test_Win32Console < Test::Unit::TestCase
-    def setup
-      print "\e[m!"
+    def reset
+      STDOUT.console_attribute(7)
     end
 
-    def teardown
-      print "\e[m!"
-    end
+    alias setup reset
+    alias teardown reset
 
     def test_default
       info = STDOUT.console_info

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]