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

ruby-changes:27008

From: nobu <ko1@a...>
Date: Tue, 5 Feb 2013 13:28:07 +0900 (JST)
Subject: [ruby-changes:27008] nobu:r39060 (trunk): console.c: default by stty raw

nobu	2013-02-05 13:27:57 +0900 (Tue, 05 Feb 2013)

  New Revision: 39060

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

  Log:
    console.c: default by stty raw
    
    * ext/io/console/console.c (rawmode_opt): use default values by `stty
      raw`.

  Modified files:
    trunk/ChangeLog
    trunk/ext/io/console/console.c
    trunk/test/io/console/test_io_console.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39059)
+++ ChangeLog	(revision 39060)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Feb  5 13:27:53 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/io/console/console.c (rawmode_opt): use default values by `stty
+	  raw`.
+
 Tue Feb  5 12:50:47 2013  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* range.c: Use div instead of / for bsearch
Index: ext/io/console/console.c
===================================================================
--- ext/io/console/console.c	(revision 39059)
+++ ext/io/console/console.c	(revision 39060)
@@ -105,7 +105,8 @@ rawmode_opt(int argc, VALUE *argv, rawmo https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L105
     if (!NIL_P(vopts)) {
 	VALUE vmin = rb_hash_aref(vopts, ID2SYM(rb_intern("min")));
 	VALUE vtime = rb_hash_aref(vopts, ID2SYM(rb_intern("time")));
-	opts->vmin = 0;
+	/* default values by `stty raw` */
+	opts->vmin = 1;
 	opts->vtime = 0;
 	if (!NIL_P(vmin)) {
 	    opts->vmin = NUM2INT(vmin);
Index: test/io/console/test_io_console.rb
===================================================================
--- test/io/console/test_io_console.rb	(revision 39059)
+++ test/io/console/test_io_console.rb	(revision 39060)
@@ -29,14 +29,21 @@ class TestIO_Console < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/io/console/test_io_console.rb#L29
     len = 0
     th = nil
     helper {|m, s|
+      assert_equal([nil, 0], [s.getch(min: 0), len])
+      main = Thread.current
+      go = false
       th = Thread.start {
-        m.print("a")
         len += 1
-        sleep 2
-        m.print("1234567890")
+        m.print("a")
+        m.flush
+        sleep 0.01 until go and main.stop?
         len += 10
+        m.print("1234567890")
+        m.flush
       }
       assert_equal(["a", 1], [s.getch(min: 1), len])
+      go = true
+      assert_equal(["1", 11], [s.getch, len])
     }
   ensure
     th.kill if th and th.alive?
@@ -46,12 +53,15 @@ class TestIO_Console < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/io/console/test_io_console.rb#L53
     len = 0
     th = nil
     helper {|m, s|
+      assert_equal([nil, 0], [s.getch(min: 0, time: 0.1), len])
+      main = Thread.current
       th = Thread.start {
-        sleep 2
-        m.print("a")
-        len += 1
+        sleep 0.01 until main.stop?
+        len += 2
+        m.print("ab")
       }
-      assert_equal([nil, 0], [s.getch(time: 0.1), len])
+      assert_equal(["a", 2], [s.getch(min: 1, time: 1), len])
+      assert_equal(["b", 2], [s.getch(time: 1), len])
     }
   ensure
     th.kill if th and th.alive?

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

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