summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2023-09-22 14:00:25 +0100
committergit <svn-admin@ruby-lang.org>2023-09-22 13:00:32 +0000
commitf59b488b5a7f6e46e3e6d80d2b0a269e7d937a30 (patch)
tree4bea2b1a38560faea01c63792ab93a9308bf4169
parentc0d27af114740b67c6f278997b7f70f854b99e64 (diff)
[ruby/irb] Page show_source's output
(https://github.com/ruby/irb/pull/719) https://github.com/ruby/irb/commit/3cedc5cb62
-rw-r--r--lib/irb/cmd/show_source.rb17
-rw-r--r--test/irb/test_irb.rb14
2 files changed, 19 insertions, 12 deletions
diff --git a/lib/irb/cmd/show_source.rb b/lib/irb/cmd/show_source.rb
index 10463ebf08..49cab43fab 100644
--- a/lib/irb/cmd/show_source.rb
+++ b/lib/irb/cmd/show_source.rb
@@ -2,6 +2,7 @@
require_relative "nop"
require_relative "../source_finder"
+require_relative "../pager"
require_relative "../color"
module IRB
@@ -40,12 +41,16 @@ module IRB
private
def show_source(source)
- puts
- puts "#{bold("From")}: #{source.file}:#{source.first_line}"
- puts
- code = IRB::Color.colorize_code(File.read(source.file))
- puts code.lines[(source.first_line - 1)...source.last_line].join
- puts
+ file_content = IRB::Color.colorize_code(File.read(source.file))
+ code = file_content.lines[(source.first_line - 1)...source.last_line].join
+ content = <<~CONTENT
+
+ #{bold("From")}: #{source.file}:#{source.first_line}
+
+ #{code}
+ CONTENT
+
+ Pager.page_content(content)
end
def bold(str)
diff --git a/test/irb/test_irb.rb b/test/irb/test_irb.rb
index 08fe41f5e7..0c77bb0f76 100644
--- a/test/irb/test_irb.rb
+++ b/test/irb/test_irb.rb
@@ -6,6 +6,11 @@ require_relative "helper"
module TestIRB
class InputTest < IntegrationTestCase
def test_symbol_aliases_are_handled_correctly
+ write_rc <<~RUBY
+ # disable pager
+ STDIN.singleton_class.define_method(:tty?) { false }
+ RUBY
+
write_ruby <<~'RUBY'
class Foo
end
@@ -21,12 +26,11 @@ module TestIRB
end
def test_symbol_aliases_are_handled_correctly_with_singleline_mode
- @irbrc = Tempfile.new('irbrc')
- @irbrc.write <<~RUBY
+ write_rc <<~RUBY
+ # disable pager
+ STDIN.singleton_class.define_method(:tty?) { false }
IRB.conf[:USE_SINGLELINE] = true
RUBY
- @irbrc.close
- @envs['IRBRC'] = @irbrc.path
write_ruby <<~'RUBY'
class Foo
@@ -43,8 +47,6 @@ module TestIRB
# Make sure it's tested in singleline mode
assert_include output, "InputMethod: ReadlineInputMethod"
assert_include output, "From: #{@ruby_file.path}:1"
- ensure
- @irbrc.unlink if @irbrc
end
def test_symbol_aliases_dont_affect_ruby_syntax