diff --git a/lib/irb/init.rb b/lib/irb/init.rb index 4df285ce64b298..9704e36cb10745 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -82,6 +82,7 @@ def IRB.init_config(ap_path) @CONF[:USE_LOADER] = false @CONF[:IGNORE_SIGINT] = true @CONF[:IGNORE_EOF] = false + @CONF[:USE_PAGER] = true @CONF[:EXTRA_DOC_DIRS] = [] @CONF[:ECHO] = nil @CONF[:ECHO_ON_ASSIGNMENT] = nil @@ -285,6 +286,8 @@ def IRB.parse_opts(argv: ::ARGV) end when "--noinspect" @CONF[:INSPECT_MODE] = false + when "--no-pager" + @CONF[:USE_PAGER] = false when "--singleline", "--readline", "--legacy" @CONF[:USE_SINGLELINE] = true when "--nosingleline", "--noreadline" diff --git a/lib/irb/lc/help-message b/lib/irb/lc/help-message index c7846b755df96d..37347306e8497a 100644 --- a/lib/irb/lc/help-message +++ b/lib/irb/lc/help-message @@ -22,6 +22,7 @@ Usage: irb.rb [options] [programfile] [arguments] Show truncated result on assignment (default). --inspect Use 'inspect' for output. --noinspect Don't use 'inspect' for output. + --no-pager Don't use pager. --multiline Use multiline editor module (default). --nomultiline Don't use multiline editor module. --singleline Use single line editor module. diff --git a/lib/irb/pager.rb b/lib/irb/pager.rb index 119515078ba25d..e38d97e3c7d347 100644 --- a/lib/irb/pager.rb +++ b/lib/irb/pager.rb @@ -18,7 +18,7 @@ def page_content(content) end def page - if STDIN.tty? && pager = setup_pager + if IRB.conf[:USE_PAGER] && STDIN.tty? && pager = setup_pager begin pid = pager.pid yield pager diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb index 219710c9210f34..62ef7a5b70e2a7 100644 --- a/test/irb/test_cmd.rb +++ b/test/irb/test_cmd.rb @@ -23,9 +23,6 @@ def setup save_encodings IRB.instance_variable_get(:@CONF).clear @is_win = (RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/) - STDIN.singleton_class.define_method :tty? do - false - end end def teardown @@ -34,13 +31,13 @@ def teardown Dir.chdir(@pwd) FileUtils.rm_rf(@tmpdir) restore_encodings - STDIN.singleton_class.remove_method :tty? end def execute_lines(*lines, conf: {}, main: self, irb_path: nil) IRB.init_config(nil) IRB.conf[:VERBOSE] = false IRB.conf[:PROMPT_MODE] = :SIMPLE + IRB.conf[:USE_PAGER] = false IRB.conf.merge!(conf) input = TestInputMethod.new(lines) irb = IRB::Irb.new(IRB::WorkSpace.new(main), input) diff --git a/test/irb/test_debug_cmd.rb b/test/irb/test_debug_cmd.rb index d669c174e6ef6a..53d40f7297ff27 100644 --- a/test/irb/test_debug_cmd.rb +++ b/test/irb/test_debug_cmd.rb @@ -346,9 +346,11 @@ def test_help_command_is_delegated_to_the_debugger end def test_show_cmds_display_different_content_when_debugger_is_enabled + write_rc <<~RUBY + IRB.conf[:USE_PAGER] = false + RUBY + write_ruby <<~'ruby' - # disable pager - STDIN.singleton_class.define_method(:tty?) { false } binding.irb ruby diff --git a/test/irb/test_irb.rb b/test/irb/test_irb.rb index b32e857c1e81a2..e6eb3d5da1f620 100644 --- a/test/irb/test_irb.rb +++ b/test/irb/test_irb.rb @@ -7,8 +7,7 @@ module TestIRB class InputTest < IntegrationTestCase def test_symbol_aliases_are_handled_correctly write_rc <<~RUBY - # disable pager - STDIN.singleton_class.define_method(:tty?) { false } + IRB.conf[:USE_PAGER] = false RUBY write_ruby <<~'RUBY' @@ -27,8 +26,7 @@ class Foo def test_symbol_aliases_are_handled_correctly_with_singleline_mode write_rc <<~RUBY - # disable pager - STDIN.singleton_class.define_method(:tty?) { false } + IRB.conf[:USE_PAGER] = false IRB.conf[:USE_SINGLELINE] = true RUBY