[ruby/irb] Powerup show_source by enabling RubyVM.keep_script_lines

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

* Powerup show_source by enabling RubyVM.keep_script_lines

* Add file_content field to avoid reading file twice while show_source

* Change path passed to eval, don't change irb_path.

* Encapsulate source coloring logic and binary file check insode class Source

* Add edit command testcase when irb_path does not exist

* Memoize irb_path existence to reduce file existence check calculating eval_path

239683a937
This commit is contained in:
tomoya ishida 2024-02-13 03:38:27 +09:00 committed by git
parent e878bbd641
commit 7af97dc71f
8 changed files with 149 additions and 51 deletions

View file

@ -45,15 +45,18 @@ module IRB
private
def show_source(source)
file_content = IRB::Color.colorize_code(File.read(source.file))
code = file_content.lines[(source.first_line - 1)...source.last_line].join
content = <<~CONTENT
if source.binary_file?
content = "\n#{bold('Defined in binary file')}: #{source.file}\n\n"
else
code = source.colorized_content || 'Source not available'
content = <<~CONTENT
#{bold("From")}: #{source.file}:#{source.first_line}
#{bold("From")}: #{source.file}:#{source.line}
#{code}
CONTENT
#{code.chomp}
CONTENT
end
Pager.page_content(content)
end