summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-08-18 10:36:37 +0900
committergit <svn-admin@ruby-lang.org>2023-08-18 03:55:03 +0000
commit528da4347cb68d2e19373b3d0e517ec7d0d1ea90 (patch)
tree9f556ebb5156da21b7cf30986d95745face28511 /ext
parent540cf43205262d8208516d4046caabfdae62a45a (diff)
[ruby/io-console] Flush after prompt
https://github.com/ruby/io-console/commit/040a1d6259
Diffstat (limited to 'ext')
-rw-r--r--ext/io/console/console.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/ext/io/console/console.c b/ext/io/console/console.c
index 5c31d990bc..da50fc6922 100644
--- a/ext/io/console/console.c
+++ b/ext/io/console/console.c
@@ -76,7 +76,7 @@ getattr(int fd, conmode *t)
#endif
static ID id_getc, id_console, id_close;
-static ID id_gets, id_chomp_bang;
+static ID id_gets, id_flush, id_chomp_bang;
#if defined HAVE_RUBY_FIBER_SCHEDULER_H
# include "ruby/fiber/scheduler.h"
@@ -1591,6 +1591,7 @@ console_getpass(int argc, VALUE *argv, VALUE io)
wio = rb_io_get_write_io(io);
if (wio == io && io == rb_stdin) wio = rb_stderr;
prompt(argc, argv, wio);
+ rb_io_flush(wio);
str = rb_ensure(getpass_call, io, puts_call, wio);
return str_chomp(str);
}
@@ -1608,6 +1609,7 @@ io_getpass(int argc, VALUE *argv, VALUE io)
rb_check_arity(argc, 0, 1);
prompt(argc, argv, io);
+ rb_check_funcall(io, id_flush, 0, 0);
str = str_chomp(rb_funcallv(io, id_gets, 0, 0));
puts_call(io);
return str;
@@ -1622,6 +1624,7 @@ Init_console(void)
#undef rb_intern
id_getc = rb_intern("getc");
id_gets = rb_intern("gets");
+ id_flush = rb_intern("flush");
id_chomp_bang = rb_intern("chomp!");
id_console = rb_intern("console");
id_close = rb_intern("close");