summaryrefslogtreecommitdiff
path: root/ext/io
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-03-13 00:55:49 -0800
committerGitHub <noreply@github.com>2021-03-13 17:55:49 +0900
commitb20e2c3f2a3ce227b9cf32d2bf02db0ac67eccb5 (patch)
treed6f3ee19ac9050acbc0b897dd21c48da83f02f84 /ext/io
parent6f9e007729d53fdbc22e37e52129ea5aa2556d0e (diff)
Backport io-console 0.5.7 to Ruby 3.0 (#4252)
* [ruby/io-console] [DOC] Note that IO#getpass returns a chomped string IO#getpass uses String#chomp! on the read input line. https://github.com/ruby/io-console/commit/1e98c93bc8 * [ruby/io-console] Ignore chomp! result and return the modified string https://github.com/ruby/io-console/commit/09e5ccc729 * [ruby/io-console] Pre-define chomp! ID https://github.com/ruby/io-console/commit/028e1c9497 * [ruby/io-console] Shrink struct query_args https://github.com/ruby/io-console/commit/720be0a3e5 * [ruby/io-console] bump up to 0.5.7 https://github.com/ruby/io-console/commit/f55d7ebff6 Co-authored-by: Marcus Stollsteimer <sto.mar@web.de> Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Diffstat (limited to 'ext/io')
-rw-r--r--ext/io/console/console.c13
-rw-r--r--ext/io/console/io-console.gemspec2
2 files changed, 10 insertions, 5 deletions
diff --git a/ext/io/console/console.c b/ext/io/console/console.c
index ff4df73693..2e2467036d 100644
--- a/ext/io/console/console.c
+++ b/ext/io/console/console.c
@@ -77,7 +77,7 @@ getattr(int fd, conmode *t)
static ID id_getc, id_console, id_close, id_min, id_time, id_intr;
#if ENABLE_IO_GETPASS
-static ID id_gets;
+static ID id_gets, id_chomp_bang;
#endif
#ifdef HAVE_RB_SCHEDULER_TIMEOUT
@@ -1223,8 +1223,8 @@ console_key_pressed_p(VALUE io, VALUE k)
}
#else
struct query_args {
- const char *qstr;
- int opt;
+ char qstr[6];
+ unsigned char opt;
};
static int
@@ -1562,7 +1562,7 @@ static VALUE
str_chomp(VALUE str)
{
if (!NIL_P(str)) {
- str = rb_funcallv(str, rb_intern("chomp!"), 0, 0);
+ rb_funcallv(str, id_chomp_bang, 0, 0);
}
return str;
}
@@ -1574,6 +1574,10 @@ str_chomp(VALUE str)
* Reads and returns a line without echo back.
* Prints +prompt+ unless it is +nil+.
*
+ * The newline character that terminates the
+ * read line is removed from the returned string,
+ * see String#chomp!.
+ *
* You must require 'io/console' to use this method.
*/
static VALUE
@@ -1618,6 +1622,7 @@ Init_console(void)
id_getc = rb_intern("getc");
#if ENABLE_IO_GETPASS
id_gets = rb_intern("gets");
+ id_chomp_bang = rb_intern("chomp!");
#endif
id_console = rb_intern("console");
id_close = rb_intern("close");
diff --git a/ext/io/console/io-console.gemspec b/ext/io/console/io-console.gemspec
index 743e5e965d..8a0df83b2c 100644
--- a/ext/io/console/io-console.gemspec
+++ b/ext/io/console/io-console.gemspec
@@ -1,5 +1,5 @@
# -*- ruby -*-
-_VERSION = "0.5.6"
+_VERSION = "0.5.7"
Gem::Specification.new do |s|
s.name = "io-console"