[ruby/io-console] Enable getpass methods always

https://github.com/ruby/io-console/commit/57f9649df4
This commit is contained in:
Nobuyoshi Nakada 2023-08-18 10:33:25 +09:00 committed by git
parent 1bbce42964
commit 540cf43205
3 changed files with 0 additions and 12 deletions

View File

@ -76,9 +76,7 @@ getattr(int fd, conmode *t)
#endif #endif
static ID id_getc, id_console, id_close; static ID id_getc, id_console, id_close;
#if ENABLE_IO_GETPASS
static ID id_gets, id_chomp_bang; static ID id_gets, id_chomp_bang;
#endif
#if defined HAVE_RUBY_FIBER_SCHEDULER_H #if defined HAVE_RUBY_FIBER_SCHEDULER_H
# include "ruby/fiber/scheduler.h" # include "ruby/fiber/scheduler.h"
@ -1534,7 +1532,6 @@ io_getch(int argc, VALUE *argv, VALUE io)
return rb_funcallv(io, id_getc, argc, argv); return rb_funcallv(io, id_getc, argc, argv);
} }
#if ENABLE_IO_GETPASS
static VALUE static VALUE
puts_call(VALUE io) puts_call(VALUE io)
{ {
@ -1615,7 +1612,6 @@ io_getpass(int argc, VALUE *argv, VALUE io)
puts_call(io); puts_call(io);
return str; return str;
} }
#endif
/* /*
* IO console methods * IO console methods
@ -1625,10 +1621,8 @@ Init_console(void)
{ {
#undef rb_intern #undef rb_intern
id_getc = rb_intern("getc"); id_getc = rb_intern("getc");
#if ENABLE_IO_GETPASS
id_gets = rb_intern("gets"); id_gets = rb_intern("gets");
id_chomp_bang = rb_intern("chomp!"); id_chomp_bang = rb_intern("chomp!");
#endif
id_console = rb_intern("console"); id_console = rb_intern("console");
id_close = rb_intern("close"); id_close = rb_intern("close");
#define init_rawmode_opt_id(name) \ #define init_rawmode_opt_id(name) \
@ -1676,16 +1670,12 @@ InitVM_console(void)
rb_define_method(rb_cIO, "clear_screen", console_clear_screen, 0); rb_define_method(rb_cIO, "clear_screen", console_clear_screen, 0);
rb_define_method(rb_cIO, "pressed?", console_key_pressed_p, 1); rb_define_method(rb_cIO, "pressed?", console_key_pressed_p, 1);
rb_define_method(rb_cIO, "check_winsize_changed", console_check_winsize_changed, 0); rb_define_method(rb_cIO, "check_winsize_changed", console_check_winsize_changed, 0);
#if ENABLE_IO_GETPASS
rb_define_method(rb_cIO, "getpass", console_getpass, -1); rb_define_method(rb_cIO, "getpass", console_getpass, -1);
#endif
rb_define_singleton_method(rb_cIO, "console", console_dev, -1); rb_define_singleton_method(rb_cIO, "console", console_dev, -1);
{ {
VALUE mReadable = rb_define_module_under(rb_cIO, "generic_readable"); VALUE mReadable = rb_define_module_under(rb_cIO, "generic_readable");
rb_define_method(mReadable, "getch", io_getch, -1); rb_define_method(mReadable, "getch", io_getch, -1);
#if ENABLE_IO_GETPASS
rb_define_method(mReadable, "getpass", io_getpass, -1); rb_define_method(mReadable, "getpass", io_getpass, -1);
#endif
} }
{ {
/* :stopdoc: */ /* :stopdoc: */

View File

@ -35,7 +35,6 @@ when true
elsif have_func("rb_scheduler_timeout") # 3.0 elsif have_func("rb_scheduler_timeout") # 3.0
have_func("rb_io_wait") have_func("rb_io_wait")
end end
$defs << "-D""ENABLE_IO_GETPASS=1"
create_makefile("io/console") {|conf| create_makefile("io/console") {|conf|
conf << "\n""VK_HEADER = #{vk_header}\n" conf << "\n""VK_HEADER = #{vk_header}\n"
} }

View File

@ -241,7 +241,6 @@ defined?(PTY) and defined?(IO.console) and TestIO_Console.class_eval do
end end
def test_getpass def test_getpass
omit unless IO.method_defined?("getpass")
run_pty("p IO.console.getpass('> ')") do |r, w| run_pty("p IO.console.getpass('> ')") do |r, w|
assert_equal("> ", r.readpartial(10)) assert_equal("> ", r.readpartial(10))
sleep 0.1 sleep 0.1