[ruby/irb] Support disabling pager

(https://github.com/ruby/irb/pull/783)

With either `IRB.conf[:USE_PAGER] = false` or `--no-pager` commnad line flag.

I decided use `--no-pager` instead of `--use-pager` because it matches with
Pry and git's command line flags.

https://github.com/ruby/irb/commit/df1c3b9042
This commit is contained in:
Stan Lo 2023-11-26 11:07:46 +00:00 committed by git
parent 0bced53a8a
commit 9cd086ba4b
6 changed files with 12 additions and 11 deletions

View File

@ -82,6 +82,7 @@ module IRB # :nodoc:
@CONF[:USE_LOADER] = false @CONF[:USE_LOADER] = false
@CONF[:IGNORE_SIGINT] = true @CONF[:IGNORE_SIGINT] = true
@CONF[:IGNORE_EOF] = false @CONF[:IGNORE_EOF] = false
@CONF[:USE_PAGER] = true
@CONF[:EXTRA_DOC_DIRS] = [] @CONF[:EXTRA_DOC_DIRS] = []
@CONF[:ECHO] = nil @CONF[:ECHO] = nil
@CONF[:ECHO_ON_ASSIGNMENT] = nil @CONF[:ECHO_ON_ASSIGNMENT] = nil
@ -285,6 +286,8 @@ module IRB # :nodoc:
end end
when "--noinspect" when "--noinspect"
@CONF[:INSPECT_MODE] = false @CONF[:INSPECT_MODE] = false
when "--no-pager"
@CONF[:USE_PAGER] = false
when "--singleline", "--readline", "--legacy" when "--singleline", "--readline", "--legacy"
@CONF[:USE_SINGLELINE] = true @CONF[:USE_SINGLELINE] = true
when "--nosingleline", "--noreadline" when "--nosingleline", "--noreadline"

View File

@ -22,6 +22,7 @@ Usage: irb.rb [options] [programfile] [arguments]
Show truncated result on assignment (default). Show truncated result on assignment (default).
--inspect Use 'inspect' for output. --inspect Use 'inspect' for output.
--noinspect Don't use 'inspect' for output. --noinspect Don't use 'inspect' for output.
--no-pager Don't use pager.
--multiline Use multiline editor module (default). --multiline Use multiline editor module (default).
--nomultiline Don't use multiline editor module. --nomultiline Don't use multiline editor module.
--singleline Use single line editor module. --singleline Use single line editor module.

View File

@ -18,7 +18,7 @@ module IRB
end end
def page def page
if STDIN.tty? && pager = setup_pager if IRB.conf[:USE_PAGER] && STDIN.tty? && pager = setup_pager
begin begin
pid = pager.pid pid = pager.pid
yield pager yield pager

View File

@ -23,9 +23,6 @@ module TestIRB
save_encodings save_encodings
IRB.instance_variable_get(:@CONF).clear IRB.instance_variable_get(:@CONF).clear
@is_win = (RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/) @is_win = (RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/)
STDIN.singleton_class.define_method :tty? do
false
end
end end
def teardown def teardown
@ -34,13 +31,13 @@ module TestIRB
Dir.chdir(@pwd) Dir.chdir(@pwd)
FileUtils.rm_rf(@tmpdir) FileUtils.rm_rf(@tmpdir)
restore_encodings restore_encodings
STDIN.singleton_class.remove_method :tty?
end end
def execute_lines(*lines, conf: {}, main: self, irb_path: nil) def execute_lines(*lines, conf: {}, main: self, irb_path: nil)
IRB.init_config(nil) IRB.init_config(nil)
IRB.conf[:VERBOSE] = false IRB.conf[:VERBOSE] = false
IRB.conf[:PROMPT_MODE] = :SIMPLE IRB.conf[:PROMPT_MODE] = :SIMPLE
IRB.conf[:USE_PAGER] = false
IRB.conf.merge!(conf) IRB.conf.merge!(conf)
input = TestInputMethod.new(lines) input = TestInputMethod.new(lines)
irb = IRB::Irb.new(IRB::WorkSpace.new(main), input) irb = IRB::Irb.new(IRB::WorkSpace.new(main), input)

View File

@ -346,9 +346,11 @@ module TestIRB
end end
def test_show_cmds_display_different_content_when_debugger_is_enabled def test_show_cmds_display_different_content_when_debugger_is_enabled
write_rc <<~RUBY
IRB.conf[:USE_PAGER] = false
RUBY
write_ruby <<~'ruby' write_ruby <<~'ruby'
# disable pager
STDIN.singleton_class.define_method(:tty?) { false }
binding.irb binding.irb
ruby ruby

View File

@ -7,8 +7,7 @@ module TestIRB
class InputTest < IntegrationTestCase class InputTest < IntegrationTestCase
def test_symbol_aliases_are_handled_correctly def test_symbol_aliases_are_handled_correctly
write_rc <<~RUBY write_rc <<~RUBY
# disable pager IRB.conf[:USE_PAGER] = false
STDIN.singleton_class.define_method(:tty?) { false }
RUBY RUBY
write_ruby <<~'RUBY' write_ruby <<~'RUBY'
@ -27,8 +26,7 @@ module TestIRB
def test_symbol_aliases_are_handled_correctly_with_singleline_mode def test_symbol_aliases_are_handled_correctly_with_singleline_mode
write_rc <<~RUBY write_rc <<~RUBY
# disable pager IRB.conf[:USE_PAGER] = false
STDIN.singleton_class.define_method(:tty?) { false }
IRB.conf[:USE_SINGLELINE] = true IRB.conf[:USE_SINGLELINE] = true
RUBY RUBY