irb 1.14.3 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rdoc_options +5 -0
- data/CONTRIBUTING.md +52 -0
- data/EXTEND_IRB.md +3 -0
- data/Gemfile +11 -1
- data/README.md +13 -310
- data/doc/COMMAND_LINE_OPTIONS.md +69 -0
- data/doc/COMPARED_WITH_PRY.md +22 -0
- data/doc/Configurations.md +274 -0
- data/doc/EXTEND_IRB.md +122 -0
- data/doc/Index.md +705 -0
- data/doc/irb/irb.rd.ja +1 -1
- data/lib/irb/color.rb +251 -162
- data/lib/irb/color_printer.rb +10 -9
- data/lib/irb/command/base.rb +35 -0
- data/lib/irb/command/copy.rb +83 -0
- data/lib/irb/command/history.rb +1 -1
- data/lib/irb/command/internal_helpers.rb +6 -3
- data/lib/irb/command/ls.rb +6 -4
- data/lib/irb/completion.rb +69 -52
- data/lib/irb/context.rb +100 -64
- data/lib/irb/debug.rb +3 -3
- data/lib/irb/default_commands.rb +4 -1
- data/lib/irb/easter-egg.rb +3 -1
- data/lib/irb/ext/multi-irb.rb +2 -0
- data/lib/irb/history.rb +4 -0
- data/lib/irb/init.rb +6 -1
- data/lib/irb/input-method.rb +158 -122
- data/lib/irb/inspector.rb +12 -7
- data/lib/irb/lc/help-message +2 -2
- data/lib/irb/lc/ja/help-message +1 -1
- data/lib/irb/nesting_parser.rb +362 -213
- data/lib/irb/pager.rb +127 -6
- data/lib/irb/ruby-lex.rb +225 -299
- data/lib/irb/ruby_logo.aa +4 -0
- data/lib/irb/source_finder.rb +12 -18
- data/lib/irb/startup_message.rb +83 -0
- data/lib/irb/statement.rb +21 -0
- data/lib/irb/version.rb +2 -2
- data/lib/irb/workspace.rb +9 -0
- data/lib/irb.rb +112 -927
- data/man/irb.1 +2 -0
- metadata +42 -12
- data/.document +0 -8
- data/Rakefile +0 -52
- data/bin/console +0 -6
- data/bin/setup +0 -6
- data/irb.gemspec +0 -46
data/lib/irb/ruby_logo.aa
CHANGED
data/lib/irb/source_finder.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require 'prism'
|
|
4
4
|
|
|
5
5
|
module IRB
|
|
6
6
|
class SourceFinder
|
|
@@ -29,10 +29,13 @@ module IRB
|
|
|
29
29
|
|
|
30
30
|
def colorized_content
|
|
31
31
|
if !binary_file? && file_exist?
|
|
32
|
-
end_line = find_end
|
|
33
32
|
# To correctly colorize, we need to colorize full content and extract the relevant lines.
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
colored_lines = IRB::Color.colorize_code(file_content).lines
|
|
34
|
+
|
|
35
|
+
# Handle wrong line number case: line_no passed to eval is wrong, file is edited after load, etc
|
|
36
|
+
return if colored_lines.size < @line
|
|
37
|
+
|
|
38
|
+
colored_lines[@line - 1...find_end].join
|
|
36
39
|
elsif @ast_source
|
|
37
40
|
IRB::Color.colorize_code(@ast_source)
|
|
38
41
|
end
|
|
@@ -41,21 +44,12 @@ module IRB
|
|
|
41
44
|
private
|
|
42
45
|
|
|
43
46
|
def find_end
|
|
44
|
-
lex = RubyLex.new
|
|
45
47
|
code = file_content
|
|
46
48
|
lines = code.lines[(@line - 1)..-1]
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
tokens.chunk { |tok| tok.pos[0] }.each do |lnum, chunk|
|
|
52
|
-
code = lines[0..lnum].join
|
|
53
|
-
prev_tokens.concat chunk
|
|
54
|
-
continue = lex.should_continue?(prev_tokens)
|
|
55
|
-
syntax = lex.check_code_syntax(code, local_variables: [])
|
|
56
|
-
if !continue && syntax == :valid
|
|
57
|
-
return @line + lnum
|
|
58
|
-
end
|
|
49
|
+
|
|
50
|
+
lines.each_with_index do |line, index|
|
|
51
|
+
sub_code = lines.take(index + 1).join
|
|
52
|
+
return @line + index if Prism.parse_success?(sub_code)
|
|
59
53
|
end
|
|
60
54
|
@line
|
|
61
55
|
end
|
|
@@ -114,7 +108,7 @@ module IRB
|
|
|
114
108
|
when "owner"
|
|
115
109
|
target_method = owner_receiver.instance_method(method)
|
|
116
110
|
when "receiver"
|
|
117
|
-
target_method =
|
|
111
|
+
target_method = Kernel.instance_method(:method).bind_call(owner_receiver, method)
|
|
118
112
|
end
|
|
119
113
|
super_level.times do |s|
|
|
120
114
|
target_method = target_method.super_method if target_method
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "color"
|
|
4
|
+
require_relative "version"
|
|
5
|
+
|
|
6
|
+
module IRB
|
|
7
|
+
module StartupMessage
|
|
8
|
+
TIPS = [
|
|
9
|
+
'Type "help" for commands, "help <cmd>" for details',
|
|
10
|
+
'"show_doc method" to view documentation',
|
|
11
|
+
'"ls [object]" to see methods and properties',
|
|
12
|
+
'"ls [object] -g pattern" to filter methods and properties',
|
|
13
|
+
'"edit method" to open the method\'s source in editor',
|
|
14
|
+
'"cd object" to navigate into an object',
|
|
15
|
+
'"show_source method" to view source code',
|
|
16
|
+
'"copy expr" to copy the output to clipboard',
|
|
17
|
+
'"debug" to start integration with the "debug" gem',
|
|
18
|
+
'"history -g pattern" to search history',
|
|
19
|
+
].freeze
|
|
20
|
+
|
|
21
|
+
class << self
|
|
22
|
+
def display
|
|
23
|
+
logo_lines = load_logo
|
|
24
|
+
info_lines = build_info_lines
|
|
25
|
+
|
|
26
|
+
output = if logo_lines
|
|
27
|
+
combine_logo_and_info(logo_lines, info_lines)
|
|
28
|
+
else
|
|
29
|
+
info_lines.join("\n")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Add a blank line to not immediately touch warning messages
|
|
33
|
+
puts
|
|
34
|
+
puts output
|
|
35
|
+
puts
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def load_logo
|
|
41
|
+
encoding = STDOUT.external_encoding || Encoding.default_external
|
|
42
|
+
return nil unless encoding == Encoding::UTF_8
|
|
43
|
+
|
|
44
|
+
logo = IRB.send(:easter_egg_logo, :unicode_small)
|
|
45
|
+
return nil unless logo
|
|
46
|
+
|
|
47
|
+
logo.chomp.lines.map(&:chomp)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def build_info_lines
|
|
51
|
+
version_line = "#{Color.colorize('IRB', [:BOLD])} v#{VERSION} - Ruby #{RUBY_VERSION}"
|
|
52
|
+
tip_line = colorize_tip(TIPS.sample)
|
|
53
|
+
dir_line = Color.colorize(short_pwd, [:CYAN])
|
|
54
|
+
|
|
55
|
+
[version_line, tip_line, dir_line]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def colorize_tip(tip)
|
|
59
|
+
tip.gsub(/"[^"]*"/) { |match| Color.colorize(match, [:YELLOW]) }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def combine_logo_and_info(logo_lines, info_lines)
|
|
63
|
+
max_lines = [logo_lines.size, info_lines.size].max
|
|
64
|
+
lines = max_lines.times.map do |i|
|
|
65
|
+
logo_part = logo_lines[i] || ""
|
|
66
|
+
info_part = info_lines[i] || ""
|
|
67
|
+
colored_logo = Color.colorize(logo_part, [:RED, :BOLD])
|
|
68
|
+
"#{colored_logo} #{info_part}"
|
|
69
|
+
end
|
|
70
|
+
lines.join("\n")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def short_pwd
|
|
74
|
+
dir = Dir.pwd
|
|
75
|
+
home = ENV['HOME']
|
|
76
|
+
if home && (dir == home || dir.start_with?("#{home}/"))
|
|
77
|
+
dir = "~#{dir[home.size..]}"
|
|
78
|
+
end
|
|
79
|
+
dir
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
data/lib/irb/statement.rb
CHANGED
|
@@ -54,6 +54,27 @@ module IRB
|
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
+
class IncorrectAlias < Statement
|
|
58
|
+
attr_reader :message
|
|
59
|
+
|
|
60
|
+
def initialize(message)
|
|
61
|
+
@code = ""
|
|
62
|
+
@message = message
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def should_be_handled_by_debugger?
|
|
66
|
+
false
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def is_assignment?
|
|
70
|
+
false
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def suppresses_echo?
|
|
74
|
+
true
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
57
78
|
class Command < Statement
|
|
58
79
|
attr_reader :command_class, :arg
|
|
59
80
|
|
data/lib/irb/version.rb
CHANGED
data/lib/irb/workspace.rb
CHANGED
|
@@ -55,6 +55,15 @@ EOF
|
|
|
55
55
|
# Note that this will typically be IRB::TOPLEVEL_BINDING
|
|
56
56
|
# This is to avoid RubyGems' local variables (see issue #17623)
|
|
57
57
|
@binding = TOPLEVEL_BINDING.dup
|
|
58
|
+
|
|
59
|
+
when 5 # binding in Ruby::Box
|
|
60
|
+
unless defined?(Ruby::Box)
|
|
61
|
+
puts 'Context-mode 5 (binding in Ruby::Box) requires Ruby 4.0 or later.'
|
|
62
|
+
raise NameError, 'Ruby::Box not defined'
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
puts 'Context-mode 5 (binding in Ruby::Box) is experimental. It may be removed or changed without notice.'
|
|
66
|
+
@binding = Ruby::Box.new.eval('Kernel.binding')
|
|
58
67
|
end
|
|
59
68
|
end
|
|
60
69
|
|