diff options
author | Stan Lo <stan001212@gmail.com> | 2023-09-22 14:00:25 +0100 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-09-22 13:00:32 +0000 |
commit | f59b488b5a7f6e46e3e6d80d2b0a269e7d937a30 (patch) | |
tree | 4bea2b1a38560faea01c63792ab93a9308bf4169 /lib/irb | |
parent | c0d27af114740b67c6f278997b7f70f854b99e64 (diff) | |
download | ruby-f59b488b5a7f6e46e3e6d80d2b0a269e7d937a30.tar.gz |
[ruby/irb] Page show_source's output
(https://github.com/ruby/irb/pull/719)
https://github.com/ruby/irb/commit/3cedc5cb62
Diffstat (limited to 'lib/irb')
-rw-r--r-- | lib/irb/cmd/show_source.rb | 17 |
1 files changed, 11 insertions, 6 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) |