1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/io/console/console.c (set_rawmode): clear ECHOE and ECHOK

bits too.
* ext/io/console/console.c (echo_p): ignore ECHOE and ECHOK bits.
  [ruby-dev:45309] [Bug #6116]
* ext/io/console/console.c (console_raw): fix rdoc.
* ext/io/console/console.c (console_set_echo): mentioned about
  platform dependency.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34917 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-03-06 01:11:47 +00:00
parent 2706b60ccb
commit dd9569ded8
3 changed files with 38 additions and 12 deletions

View file

@ -1,3 +1,16 @@
Tue Mar 6 10:11:43 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/io/console/console.c (set_rawmode): clear ECHOE and ECHOK
bits too.
* ext/io/console/console.c (echo_p): ignore ECHOE and ECHOK bits.
[ruby-dev:45309] [Bug #6116]
* ext/io/console/console.c (console_raw): fix rdoc.
* ext/io/console/console.c (console_set_echo): mentioned about
platform dependency.
Tue Mar 6 07:18:10 2012 Aaron Patterson <aaron@tenderlovemaking.com> Tue Mar 6 07:18:10 2012 Aaron Patterson <aaron@tenderlovemaking.com>
* lib/xmlrpc/client.rb: switch net/http post2 calls to modern * lib/xmlrpc/client.rb: switch net/http post2 calls to modern

View file

@ -125,10 +125,11 @@ set_rawmode(conmode *t, void *arg)
{ {
#ifdef HAVE_CFMAKERAW #ifdef HAVE_CFMAKERAW
cfmakeraw(t); cfmakeraw(t);
t->c_lflag &= ~(ECHOE|ECHOK);
#elif defined HAVE_TERMIOS_H || defined HAVE_TERMIO_H #elif defined HAVE_TERMIOS_H || defined HAVE_TERMIO_H
t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
t->c_oflag &= ~OPOST; t->c_oflag &= ~OPOST;
t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); t->c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|ICANON|ISIG|IEXTEN);
t->c_cflag &= ~(CSIZE|PARENB); t->c_cflag &= ~(CSIZE|PARENB);
t->c_cflag |= CS8; t->c_cflag |= CS8;
#elif defined HAVE_SGTTY_H #elif defined HAVE_SGTTY_H
@ -189,7 +190,7 @@ static int
echo_p(conmode *t) echo_p(conmode *t)
{ {
#if defined HAVE_TERMIOS_H || defined HAVE_TERMIO_H #if defined HAVE_TERMIOS_H || defined HAVE_TERMIO_H
return (t->c_lflag & (ECHO | ECHOE | ECHOK | ECHONL)) != 0; return (t->c_lflag & (ECHO | ECHONL)) != 0;
#elif defined HAVE_SGTTY_H #elif defined HAVE_SGTTY_H
return (t->sg_flags & ECHO) != 0; return (t->sg_flags & ECHO) != 0;
#elif defined _WIN32 #elif defined _WIN32
@ -295,7 +296,7 @@ ttymode(VALUE io, VALUE (*func)(VALUE), void (*setter)(conmode *, void *), void
* *
* STDIN.raw(&:gets) * STDIN.raw(&:gets)
* *
* will read and return a line with echo back and line editing. * will read and return a line without echo back and line editing.
* *
* You must require 'io/console' to use this method. * You must require 'io/console' to use this method.
*/ */
@ -419,6 +420,8 @@ console_noecho(VALUE io)
* io.echo = flag * io.echo = flag
* *
* Enables/disables echo back. * Enables/disables echo back.
* On some platforms, all combinations of this flags and raw/cooked
* mode may not be valid.
* *
* You must require 'io/console' to use this method. * You must require 'io/console' to use this method.
*/ */

View file

@ -7,14 +7,19 @@ end
require_relative '../../ruby/envutil' require_relative '../../ruby/envutil'
class TestIO_Console < Test::Unit::TestCase class TestIO_Console < Test::Unit::TestCase
Bug6116 = '[ruby-dev:45309]'
def test_raw def test_raw
helper {|m, s| helper {|m, s|
s.print "abc\n" s.print "abc\n"
assert_equal("abc\r\n", m.gets) assert_equal("abc\r\n", m.gets)
assert_send([s, :echo?])
s.raw { s.raw {
assert_not_send([s, :echo?], Bug6116)
s.print "def\n" s.print "def\n"
assert_equal("def\n", m.gets) assert_equal("def\n", m.gets)
} }
assert_send([s, :echo?])
s.print "ghi\n" s.print "ghi\n"
assert_equal("ghi\r\n", m.gets) assert_equal("ghi\r\n", m.gets)
} }
@ -22,14 +27,19 @@ class TestIO_Console < Test::Unit::TestCase
def test_cooked def test_cooked
helper {|m, s| helper {|m, s|
assert_send([s, :echo?])
s.raw { s.raw {
s.print "abc\n" s.print "abc\n"
assert_equal("abc\n", m.gets) assert_equal("abc\n", m.gets)
assert_not_send([s, :echo?], Bug6116)
s.cooked { s.cooked {
assert_send([s, :echo?])
s.print "def\n" s.print "def\n"
assert_equal("def\r\n", m.gets) assert_equal("def\r\n", m.gets)
} }
assert_not_send([s, :echo?], Bug6116)
} }
assert_send([s, :echo?])
s.print "ghi\n" s.print "ghi\n"
assert_equal("ghi\r\n", m.gets) assert_equal("ghi\r\n", m.gets)
} }
@ -37,7 +47,7 @@ class TestIO_Console < Test::Unit::TestCase
def test_echo def test_echo
helper {|m, s| helper {|m, s|
assert(s.echo?) assert_send([s, :echo?])
m.print "a" m.print "a"
assert_equal("a", m.readpartial(10)) assert_equal("a", m.readpartial(10))
} }
@ -46,7 +56,7 @@ class TestIO_Console < Test::Unit::TestCase
def test_noecho def test_noecho
helper {|m, s| helper {|m, s|
s.noecho { s.noecho {
assert(!s.echo?) assert_not_send([s, :echo?])
m.print "a" m.print "a"
sleep 0.1 sleep 0.1
} }
@ -57,7 +67,7 @@ class TestIO_Console < Test::Unit::TestCase
def test_noecho2 def test_noecho2
helper {|m, s| helper {|m, s|
assert(s.echo?) assert_send([s, :echo?])
m.print "a\n" m.print "a\n"
sleep 0.1 sleep 0.1
s.print "b\n" s.print "b\n"
@ -65,13 +75,13 @@ class TestIO_Console < Test::Unit::TestCase
assert_equal("a\r\nb\r\n", m.readpartial(10)) assert_equal("a\r\nb\r\n", m.readpartial(10))
assert_equal("a\n", s.readpartial(10)) assert_equal("a\n", s.readpartial(10))
s.noecho { s.noecho {
assert(!s.echo?) assert_not_send([s, :echo?])
m.print "a\n" m.print "a\n"
s.print "b\n" s.print "b\n"
assert_equal("b\r\n", m.readpartial(10)) assert_equal("b\r\n", m.readpartial(10))
assert_equal("a\n", s.readpartial(10)) assert_equal("a\n", s.readpartial(10))
} }
assert(s.echo?) assert_send([s, :echo?])
m.print "a\n" m.print "a\n"
sleep 0.1 sleep 0.1
s.print "b\n" s.print "b\n"
@ -83,7 +93,7 @@ class TestIO_Console < Test::Unit::TestCase
def test_setecho def test_setecho
helper {|m, s| helper {|m, s|
assert(s.echo?) assert_send([s, :echo?])
s.echo = false s.echo = false
m.print "a" m.print "a"
sleep 0.1 sleep 0.1
@ -95,7 +105,7 @@ class TestIO_Console < Test::Unit::TestCase
def test_setecho2 def test_setecho2
helper {|m, s| helper {|m, s|
assert(s.echo?) assert_send([s, :echo?])
m.print "a\n" m.print "a\n"
sleep 0.1 sleep 0.1
s.print "b\n" s.print "b\n"
@ -103,13 +113,13 @@ class TestIO_Console < Test::Unit::TestCase
assert_equal("a\r\nb\r\n", m.readpartial(10)) assert_equal("a\r\nb\r\n", m.readpartial(10))
assert_equal("a\n", s.readpartial(10)) assert_equal("a\n", s.readpartial(10))
s.echo = false s.echo = false
assert(!s.echo?) assert_not_send([s, :echo?])
m.print "a\n" m.print "a\n"
s.print "b\n" s.print "b\n"
assert_equal("b\r\n", m.readpartial(10)) assert_equal("b\r\n", m.readpartial(10))
assert_equal("a\n", s.readpartial(10)) assert_equal("a\n", s.readpartial(10))
s.echo = true s.echo = true
assert(s.echo?) assert_send([s, :echo?])
m.print "a\n" m.print "a\n"
sleep 0.1 sleep 0.1
s.print "b\n" s.print "b\n"