irb 1.14.1 → 1.15.1
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/Gemfile +3 -1
- data/README.md +13 -299
- data/Rakefile +4 -6
- data/irb.gemspec +2 -2
- data/lib/irb/color.rb +1 -0
- data/lib/irb/color_printer.rb +10 -9
- data/lib/irb/command/base.rb +3 -7
- data/lib/irb/command/copy.rb +73 -0
- data/lib/irb/command/history.rb +1 -1
- data/lib/irb/command/internal_helpers.rb +1 -1
- data/lib/irb/command/ls.rb +23 -11
- data/lib/irb/completion.rb +12 -5
- data/lib/irb/context.rb +105 -56
- data/lib/irb/debug/ui.rb +2 -4
- data/lib/irb/debug.rb +1 -0
- data/lib/irb/default_commands.rb +4 -1
- data/lib/irb/easter-egg.rb +2 -1
- data/lib/irb/history.rb +84 -55
- data/lib/irb/init.rb +4 -2
- data/lib/irb/input-method.rb +9 -1
- data/lib/irb/inspector.rb +11 -6
- data/lib/irb/lc/ja/help-message +4 -4
- data/lib/irb/nesting_parser.rb +1 -1
- data/lib/irb/pager.rb +125 -7
- data/lib/irb/source_finder.rb +2 -3
- data/lib/irb/statement.rb +21 -0
- data/lib/irb/version.rb +2 -2
- data/lib/irb/workspace.rb +6 -26
- data/lib/irb.rb +46 -901
- data/man/irb.1 +37 -2
- metadata +19 -8
- data/.document +0 -4
data/lib/irb/completion.rb
CHANGED
@@ -137,26 +137,33 @@ module IRB
|
|
137
137
|
end
|
138
138
|
|
139
139
|
class RegexpCompletor < BaseCompletor # :nodoc:
|
140
|
+
KERNEL_METHODS = ::Kernel.instance_method(:methods)
|
141
|
+
KERNEL_PRIVATE_METHODS = ::Kernel.instance_method(:private_methods)
|
142
|
+
KERNEL_INSTANCE_VARIABLES = ::Kernel.instance_method(:instance_variables)
|
143
|
+
OBJECT_CLASS_INSTANCE_METHOD = ::Object.instance_method(:class)
|
144
|
+
MODULE_CONSTANTS_INSTANCE_METHOD = ::Module.instance_method(:constants)
|
145
|
+
|
140
146
|
using Module.new {
|
141
147
|
refine ::Binding do
|
142
148
|
def eval_methods
|
143
|
-
|
149
|
+
KERNEL_METHODS.bind_call(receiver)
|
144
150
|
end
|
145
151
|
|
146
152
|
def eval_private_methods
|
147
|
-
|
153
|
+
KERNEL_PRIVATE_METHODS.bind_call(receiver)
|
148
154
|
end
|
149
155
|
|
150
156
|
def eval_instance_variables
|
151
|
-
|
157
|
+
KERNEL_INSTANCE_VARIABLES.bind_call(receiver)
|
152
158
|
end
|
153
159
|
|
154
160
|
def eval_global_variables
|
155
|
-
::Kernel.
|
161
|
+
::Kernel.global_variables
|
156
162
|
end
|
157
163
|
|
158
164
|
def eval_class_constants
|
159
|
-
|
165
|
+
klass = OBJECT_CLASS_INSTANCE_METHOD.bind_call(receiver)
|
166
|
+
MODULE_CONSTANTS_INSTANCE_METHOD.bind_call(klass)
|
160
167
|
end
|
161
168
|
end
|
162
169
|
}
|
data/lib/irb/context.rb
CHANGED
@@ -13,6 +13,9 @@ module IRB
|
|
13
13
|
# A class that wraps the current state of the irb session, including the
|
14
14
|
# configuration of IRB.conf.
|
15
15
|
class Context
|
16
|
+
KERNEL_PUBLIC_METHOD = ::Kernel.instance_method(:public_method)
|
17
|
+
KERNEL_METHOD = ::Kernel.instance_method(:method)
|
18
|
+
|
16
19
|
ASSIGN_OPERATORS_REGEXP = Regexp.union(%w[= += -= *= /= %= **= &= |= &&= ||= ^= <<= >>=])
|
17
20
|
# Creates a new IRB context.
|
18
21
|
#
|
@@ -152,11 +155,6 @@ module IRB
|
|
152
155
|
@command_aliases = IRB.conf[:COMMAND_ALIASES].dup
|
153
156
|
end
|
154
157
|
|
155
|
-
private def term_interactive?
|
156
|
-
return true if ENV['TEST_IRB_FORCE_INTERACTIVE']
|
157
|
-
STDIN.tty? && ENV['TERM'] != 'dumb'
|
158
|
-
end
|
159
|
-
|
160
158
|
def use_tracer=(val)
|
161
159
|
require_relative "ext/tracer" if val
|
162
160
|
IRB.conf[:USE_TRACER] = val
|
@@ -174,39 +172,6 @@ module IRB
|
|
174
172
|
__send__(__method__, val)
|
175
173
|
end
|
176
174
|
|
177
|
-
private def build_completor
|
178
|
-
completor_type = IRB.conf[:COMPLETOR]
|
179
|
-
case completor_type
|
180
|
-
when :regexp
|
181
|
-
return RegexpCompletor.new
|
182
|
-
when :type
|
183
|
-
completor = build_type_completor
|
184
|
-
return completor if completor
|
185
|
-
else
|
186
|
-
warn "Invalid value for IRB.conf[:COMPLETOR]: #{completor_type}"
|
187
|
-
end
|
188
|
-
# Fallback to RegexpCompletor
|
189
|
-
RegexpCompletor.new
|
190
|
-
end
|
191
|
-
|
192
|
-
private def build_type_completor
|
193
|
-
if RUBY_ENGINE == 'truffleruby'
|
194
|
-
# Avoid SyntaxError. truffleruby does not support endless method definition yet.
|
195
|
-
warn 'TypeCompletor is not supported on TruffleRuby yet'
|
196
|
-
return
|
197
|
-
end
|
198
|
-
|
199
|
-
begin
|
200
|
-
require 'repl_type_completor'
|
201
|
-
rescue LoadError => e
|
202
|
-
warn "TypeCompletor requires `gem repl_type_completor`: #{e.message}"
|
203
|
-
return
|
204
|
-
end
|
205
|
-
|
206
|
-
ReplTypeCompletor.preload_rbs
|
207
|
-
TypeCompletor.new(self)
|
208
|
-
end
|
209
|
-
|
210
175
|
def save_history=(val)
|
211
176
|
IRB.conf[:SAVE_HISTORY] = val
|
212
177
|
end
|
@@ -299,6 +264,8 @@ module IRB
|
|
299
264
|
attr_reader :use_autocomplete
|
300
265
|
# A copy of the default <code>IRB.conf[:INSPECT_MODE]</code>
|
301
266
|
attr_reader :inspect_mode
|
267
|
+
# Inspector for the current context
|
268
|
+
attr_reader :inspect_method
|
302
269
|
|
303
270
|
# A copy of the default <code>IRB.conf[:PROMPT_MODE]</code>
|
304
271
|
attr_reader :prompt_mode
|
@@ -591,6 +558,8 @@ module IRB
|
|
591
558
|
set_last_value(result)
|
592
559
|
when Statement::Command
|
593
560
|
statement.command_class.execute(self, statement.arg)
|
561
|
+
when Statement::IncorrectAlias
|
562
|
+
warn statement.message
|
594
563
|
end
|
595
564
|
|
596
565
|
nil
|
@@ -624,35 +593,60 @@ module IRB
|
|
624
593
|
result
|
625
594
|
end
|
626
595
|
|
627
|
-
def
|
596
|
+
def parse_input(code, is_assignment_expression)
|
628
597
|
command_name, arg = code.strip.split(/\s+/, 2)
|
629
|
-
return unless code.lines.size == 1 && command_name
|
630
|
-
|
631
598
|
arg ||= ''
|
632
|
-
|
633
|
-
#
|
634
|
-
if
|
635
|
-
|
599
|
+
|
600
|
+
# command can only be 1 line
|
601
|
+
if code.lines.size != 1 ||
|
602
|
+
# command name is required
|
603
|
+
command_name.nil? ||
|
604
|
+
# local variable have precedence over command
|
605
|
+
local_variables.include?(command_name.to_sym) ||
|
606
|
+
# assignment expression is not a command
|
607
|
+
(is_assignment_expression ||
|
608
|
+
(arg.start_with?(ASSIGN_OPERATORS_REGEXP) && !arg.start_with?(/==|=~/)))
|
609
|
+
return Statement::Expression.new(code, is_assignment_expression)
|
636
610
|
end
|
637
611
|
|
638
|
-
|
639
|
-
return if arg.start_with?(ASSIGN_OPERATORS_REGEXP) && !arg.start_with?(/==|=~/)
|
612
|
+
command = command_name.to_sym
|
640
613
|
|
641
|
-
#
|
642
|
-
|
614
|
+
# Check command aliases
|
615
|
+
if aliased_name = command_aliases[command]
|
616
|
+
if command_class = Command.load_command(aliased_name)
|
617
|
+
command = aliased_name
|
618
|
+
elsif HelperMethod.helper_methods[aliased_name]
|
619
|
+
message = <<~MESSAGE
|
620
|
+
Using command alias `#{command}` for helper method `#{aliased_name}` is not supported.
|
621
|
+
Please check the value of `IRB.conf[:COMMAND_ALIASES]`.
|
622
|
+
MESSAGE
|
623
|
+
return Statement::IncorrectAlias.new(message)
|
624
|
+
else
|
625
|
+
message = <<~MESSAGE
|
626
|
+
You're trying to use command alias `#{command}` for command `#{aliased_name}`, but `#{aliased_name}` does not exist.
|
627
|
+
Please check the value of `IRB.conf[:COMMAND_ALIASES]`.
|
628
|
+
MESSAGE
|
629
|
+
return Statement::IncorrectAlias.new(message)
|
630
|
+
end
|
631
|
+
else
|
632
|
+
command_class = Command.load_command(command)
|
633
|
+
end
|
643
634
|
|
644
635
|
# Check visibility
|
645
|
-
public_method = !!
|
646
|
-
private_method = !public_method && !!
|
647
|
-
if Command.execute_as_command?(command, public_method: public_method, private_method: private_method)
|
648
|
-
|
636
|
+
public_method = !!KERNEL_PUBLIC_METHOD.bind_call(main, command) rescue false
|
637
|
+
private_method = !public_method && !!KERNEL_METHOD.bind_call(main, command) rescue false
|
638
|
+
if command_class && Command.execute_as_command?(command, public_method: public_method, private_method: private_method)
|
639
|
+
Statement::Command.new(code, command_class, arg)
|
640
|
+
else
|
641
|
+
Statement::Expression.new(code, is_assignment_expression)
|
649
642
|
end
|
650
643
|
end
|
651
644
|
|
652
645
|
def colorize_input(input, complete:)
|
653
646
|
if IRB.conf[:USE_COLORIZE] && IRB::Color.colorable?
|
654
647
|
lvars = local_variables || []
|
655
|
-
|
648
|
+
parsed_input = parse_input(input, false)
|
649
|
+
if parsed_input.is_a?(Statement::Command)
|
656
650
|
name, sep, arg = input.split(/(\s+)/, 2)
|
657
651
|
arg = IRB::Color.colorize_code(arg, complete: complete, local_variables: lvars)
|
658
652
|
"#{IRB::Color.colorize(name, [:BOLD])}\e[m#{sep}#{arg}"
|
@@ -664,8 +658,12 @@ module IRB
|
|
664
658
|
end
|
665
659
|
end
|
666
660
|
|
667
|
-
def inspect_last_value # :nodoc:
|
668
|
-
@inspect_method.inspect_value(@last_value)
|
661
|
+
def inspect_last_value(output = +'') # :nodoc:
|
662
|
+
@inspect_method.inspect_value(@last_value, output)
|
663
|
+
end
|
664
|
+
|
665
|
+
def inspector_support_stream_output?
|
666
|
+
@inspect_method.support_stream_output?
|
669
667
|
end
|
670
668
|
|
671
669
|
NOPRINTING_IVARS = ["@last_value"] # :nodoc:
|
@@ -698,5 +696,56 @@ module IRB
|
|
698
696
|
def local_variables # :nodoc:
|
699
697
|
workspace.binding.local_variables
|
700
698
|
end
|
699
|
+
|
700
|
+
def safe_method_call_on_main(method_name)
|
701
|
+
main_object = main
|
702
|
+
Object === main_object ? main_object.__send__(method_name) : Object.instance_method(method_name).bind_call(main_object)
|
703
|
+
end
|
704
|
+
|
705
|
+
private
|
706
|
+
|
707
|
+
def term_interactive?
|
708
|
+
return true if ENV['TEST_IRB_FORCE_INTERACTIVE']
|
709
|
+
STDIN.tty? && ENV['TERM'] != 'dumb'
|
710
|
+
end
|
711
|
+
|
712
|
+
def build_completor
|
713
|
+
completor_type = IRB.conf[:COMPLETOR]
|
714
|
+
|
715
|
+
# Gem repl_type_completor is added to bundled gems in Ruby 3.4.
|
716
|
+
# Use :type as default completor only in Ruby 3.4 or later.
|
717
|
+
verbose = !!completor_type
|
718
|
+
completor_type ||= RUBY_VERSION >= '3.4' ? :type : :regexp
|
719
|
+
|
720
|
+
case completor_type
|
721
|
+
when :regexp
|
722
|
+
return RegexpCompletor.new
|
723
|
+
when :type
|
724
|
+
completor = build_type_completor(verbose: verbose)
|
725
|
+
return completor if completor
|
726
|
+
else
|
727
|
+
warn "Invalid value for IRB.conf[:COMPLETOR]: #{completor_type}"
|
728
|
+
end
|
729
|
+
# Fallback to RegexpCompletor
|
730
|
+
RegexpCompletor.new
|
731
|
+
end
|
732
|
+
|
733
|
+
def build_type_completor(verbose:)
|
734
|
+
if RUBY_ENGINE == 'truffleruby'
|
735
|
+
# Avoid SyntaxError. truffleruby does not support endless method definition yet.
|
736
|
+
warn 'TypeCompletor is not supported on TruffleRuby yet' if verbose
|
737
|
+
return
|
738
|
+
end
|
739
|
+
|
740
|
+
begin
|
741
|
+
require 'repl_type_completor'
|
742
|
+
rescue LoadError => e
|
743
|
+
warn "TypeCompletor requires `gem repl_type_completor`: #{e.message}" if verbose
|
744
|
+
return
|
745
|
+
end
|
746
|
+
|
747
|
+
ReplTypeCompletor.preload_rbs
|
748
|
+
TypeCompletor.new(self)
|
749
|
+
end
|
701
750
|
end
|
702
751
|
end
|
data/lib/irb/debug/ui.rb
CHANGED
@@ -45,9 +45,7 @@ module IRB
|
|
45
45
|
$stdout.puts line.chomp
|
46
46
|
}
|
47
47
|
when String
|
48
|
-
str
|
49
|
-
$stdout.puts line.chomp
|
50
|
-
}
|
48
|
+
Pager.page_content(str, retain_content: true)
|
51
49
|
when nil
|
52
50
|
$stdout.puts
|
53
51
|
end
|
@@ -56,7 +54,7 @@ module IRB
|
|
56
54
|
def readline _
|
57
55
|
setup_interrupt do
|
58
56
|
tc = DEBUGGER__::SESSION.instance_variable_get(:@tc)
|
59
|
-
cmd = @irb.debug_readline(tc.current_frame.
|
57
|
+
cmd = @irb.debug_readline(tc.current_frame.eval_binding || TOPLEVEL_BINDING)
|
60
58
|
|
61
59
|
case cmd
|
62
60
|
when nil # when user types C-d
|
data/lib/irb/debug.rb
CHANGED
data/lib/irb/default_commands.rb
CHANGED
@@ -9,6 +9,7 @@ require_relative "command/cd"
|
|
9
9
|
require_relative "command/chws"
|
10
10
|
require_relative "command/context"
|
11
11
|
require_relative "command/continue"
|
12
|
+
require_relative "command/copy"
|
12
13
|
require_relative "command/debug"
|
13
14
|
require_relative "command/delete"
|
14
15
|
require_relative "command/disable_irb"
|
@@ -218,7 +219,8 @@ module IRB
|
|
218
219
|
)
|
219
220
|
|
220
221
|
_register_with_aliases(:irb_show_doc, Command::ShowDoc,
|
221
|
-
[:show_doc, NO_OVERRIDE]
|
222
|
+
[:show_doc, NO_OVERRIDE],
|
223
|
+
[:ri, NO_OVERRIDE]
|
222
224
|
)
|
223
225
|
|
224
226
|
_register_with_aliases(:irb_info, Command::IrbInfo)
|
@@ -249,6 +251,7 @@ module IRB
|
|
249
251
|
)
|
250
252
|
|
251
253
|
register(:cd, Command::CD)
|
254
|
+
register(:copy, Command::Copy)
|
252
255
|
end
|
253
256
|
|
254
257
|
ExtendCommand = Command
|
data/lib/irb/easter-egg.rb
CHANGED
@@ -125,7 +125,7 @@ module IRB
|
|
125
125
|
canvas = Canvas.new(Reline.get_screen_size)
|
126
126
|
end
|
127
127
|
ruby_model = RubyModel.new
|
128
|
-
print "\e[?
|
128
|
+
print "\e[?25l" # hide cursor
|
129
129
|
0.step do |i| # TODO (0..).each needs Ruby 2.6 or later
|
130
130
|
buff = canvas.draw do
|
131
131
|
ruby_model.render_frame(i) do |p1, p2|
|
@@ -139,6 +139,7 @@ module IRB
|
|
139
139
|
end
|
140
140
|
rescue Interrupt
|
141
141
|
ensure
|
142
|
+
print "\e[?25h" # show cursor
|
142
143
|
trap("SIGINT", prev_trap)
|
143
144
|
end
|
144
145
|
end
|
data/lib/irb/history.rb
CHANGED
@@ -1,6 +1,36 @@
|
|
1
1
|
require "pathname"
|
2
2
|
|
3
3
|
module IRB
|
4
|
+
module History
|
5
|
+
DEFAULT_ENTRY_LIMIT = 1000
|
6
|
+
|
7
|
+
class << self
|
8
|
+
# Integer representation of <code>IRB.conf[:HISTORY_FILE]</code>.
|
9
|
+
def save_history
|
10
|
+
return 0 if IRB.conf[:SAVE_HISTORY] == false
|
11
|
+
return DEFAULT_ENTRY_LIMIT if IRB.conf[:SAVE_HISTORY] == true
|
12
|
+
IRB.conf[:SAVE_HISTORY].to_i
|
13
|
+
end
|
14
|
+
|
15
|
+
def save_history?
|
16
|
+
!save_history.zero?
|
17
|
+
end
|
18
|
+
|
19
|
+
def infinite?
|
20
|
+
save_history.negative?
|
21
|
+
end
|
22
|
+
|
23
|
+
# Might be nil when HOME and XDG_CONFIG_HOME are not available.
|
24
|
+
def history_file
|
25
|
+
if (history_file = IRB.conf[:HISTORY_FILE])
|
26
|
+
File.expand_path(history_file)
|
27
|
+
else
|
28
|
+
IRB.rc_file("_history")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
4
34
|
module HistorySavingAbility # :nodoc:
|
5
35
|
def support_history_saving?
|
6
36
|
true
|
@@ -11,76 +41,75 @@ module IRB
|
|
11
41
|
end
|
12
42
|
|
13
43
|
def load_history
|
44
|
+
history_file = History.history_file
|
45
|
+
return unless File.exist?(history_file.to_s)
|
46
|
+
|
14
47
|
history = self.class::HISTORY
|
15
48
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
history.last << "\n" << l
|
27
|
-
else
|
28
|
-
history << l
|
29
|
-
end
|
30
|
-
}
|
31
|
-
end
|
32
|
-
@loaded_history_lines = history.size
|
33
|
-
@loaded_history_mtime = File.mtime(history_file)
|
49
|
+
File.open(history_file, "r:#{IRB.conf[:LC_MESSAGES].encoding}") do |f|
|
50
|
+
f.each { |l|
|
51
|
+
l = l.chomp
|
52
|
+
if self.class == RelineInputMethod and history.last&.end_with?("\\")
|
53
|
+
history.last.delete_suffix!("\\")
|
54
|
+
history.last << "\n" << l
|
55
|
+
else
|
56
|
+
history << l
|
57
|
+
end
|
58
|
+
}
|
34
59
|
end
|
60
|
+
@loaded_history_lines = history.size
|
61
|
+
@loaded_history_mtime = File.mtime(history_file)
|
35
62
|
end
|
36
63
|
|
37
64
|
def save_history
|
65
|
+
return unless History.save_history?
|
66
|
+
return unless (history_file = History.history_file)
|
67
|
+
unless ensure_history_file_writable(history_file)
|
68
|
+
warn <<~WARN
|
69
|
+
Can't write history to #{History.history_file.inspect} due to insufficient permissions.
|
70
|
+
Please verify the value of `IRB.conf[:HISTORY_FILE]`. Ensure the folder exists and that both the folder and file (if it exists) are writable.
|
71
|
+
WARN
|
72
|
+
return
|
73
|
+
end
|
74
|
+
|
38
75
|
history = self.class::HISTORY.to_a
|
39
76
|
|
40
|
-
if
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
77
|
+
if File.exist?(history_file) &&
|
78
|
+
File.mtime(history_file) != @loaded_history_mtime
|
79
|
+
history = history[@loaded_history_lines..-1] if @loaded_history_lines
|
80
|
+
append_history = true
|
81
|
+
end
|
45
82
|
|
46
|
-
|
47
|
-
|
83
|
+
File.open(history_file, (append_history ? "a" : "w"), 0o600, encoding: IRB.conf[:LC_MESSAGES]&.encoding) do |f|
|
84
|
+
hist = history.map { |l| l.scrub.split("\n").join("\\\n") }
|
48
85
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
File.chmod(0600, history_file)
|
53
|
-
end
|
54
|
-
rescue Errno::ENOENT
|
55
|
-
rescue Errno::EPERM
|
56
|
-
return
|
57
|
-
rescue
|
58
|
-
raise
|
86
|
+
unless append_history || History.infinite?
|
87
|
+
# Check size before slicing because array.last(huge_number) raises RangeError.
|
88
|
+
hist = hist.last(History.save_history) if hist.size > History.save_history
|
59
89
|
end
|
60
90
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
append_history = true
|
65
|
-
end
|
91
|
+
f.puts(hist)
|
92
|
+
end
|
93
|
+
end
|
66
94
|
|
67
|
-
|
68
|
-
unless Dir.exist?(pathname.dirname)
|
69
|
-
warn "Warning: The directory to save IRB's history file does not exist. Please double check `IRB.conf[:HISTORY_FILE]`'s value."
|
70
|
-
return
|
71
|
-
end
|
95
|
+
private
|
72
96
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
97
|
+
# Returns boolean whether writing to +history_file+ will be possible.
|
98
|
+
# Permissions of already existing +history_file+ are changed to
|
99
|
+
# owner-only-readable if necessary [BUG #7694].
|
100
|
+
def ensure_history_file_writable(history_file)
|
101
|
+
history_file = Pathname.new(history_file)
|
102
|
+
|
103
|
+
return false unless history_file.dirname.writable?
|
104
|
+
return true unless history_file.exist?
|
105
|
+
|
106
|
+
begin
|
107
|
+
if history_file.stat.mode & 0o66 != 0
|
108
|
+
history_file.chmod 0o600
|
83
109
|
end
|
110
|
+
true
|
111
|
+
rescue Errno::EPERM # no permissions
|
112
|
+
false
|
84
113
|
end
|
85
114
|
end
|
86
115
|
end
|
data/lib/irb/init.rb
CHANGED
@@ -80,7 +80,7 @@ module IRB # :nodoc:
|
|
80
80
|
@CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod)
|
81
81
|
@CONF[:USE_COLORIZE] = (nc = ENV['NO_COLOR']).nil? || nc.empty?
|
82
82
|
@CONF[:USE_AUTOCOMPLETE] = ENV.fetch("IRB_USE_AUTOCOMPLETE", "true") != "false"
|
83
|
-
@CONF[:COMPLETOR] = ENV
|
83
|
+
@CONF[:COMPLETOR] = ENV["IRB_COMPLETOR"]&.to_sym
|
84
84
|
@CONF[:INSPECT_MODE] = true
|
85
85
|
@CONF[:USE_TRACER] = false
|
86
86
|
@CONF[:USE_LOADER] = false
|
@@ -93,7 +93,7 @@ module IRB # :nodoc:
|
|
93
93
|
@CONF[:VERBOSE] = nil
|
94
94
|
|
95
95
|
@CONF[:EVAL_HISTORY] = nil
|
96
|
-
@CONF[:SAVE_HISTORY] =
|
96
|
+
@CONF[:SAVE_HISTORY] = History::DEFAULT_ENTRY_LIMIT
|
97
97
|
|
98
98
|
@CONF[:BACK_TRACE_LIMIT] = 16
|
99
99
|
|
@@ -194,6 +194,8 @@ module IRB # :nodoc:
|
|
194
194
|
:'$' => :show_source,
|
195
195
|
:'@' => :whereami,
|
196
196
|
}
|
197
|
+
|
198
|
+
@CONF[:COPY_COMMAND] = ENV.fetch("IRB_COPY_COMMAND", nil)
|
197
199
|
end
|
198
200
|
|
199
201
|
def IRB.set_measure_callback(type = nil, arg = nil, &block)
|
data/lib/irb/input-method.rb
CHANGED
@@ -67,7 +67,9 @@ module IRB
|
|
67
67
|
#
|
68
68
|
# See IO#gets for more information.
|
69
69
|
def gets
|
70
|
-
|
70
|
+
# Workaround for debug compatibility test https://github.com/ruby/debug/pull/1100
|
71
|
+
puts if ENV['RUBY_DEBUG_TEST_UI']
|
72
|
+
|
71
73
|
print @prompt
|
72
74
|
line = @stdin.gets
|
73
75
|
@line[@line_no += 1] = line
|
@@ -346,9 +348,15 @@ module IRB
|
|
346
348
|
if show_easter_egg
|
347
349
|
IRB.__send__(:easter_egg)
|
348
350
|
else
|
351
|
+
# RDoc::RI::Driver#display_names uses pager command internally.
|
352
|
+
# Some pager command like `more` doesn't use alternate screen
|
353
|
+
# so we need to turn on and off alternate screen manually.
|
349
354
|
begin
|
355
|
+
print "\e[?1049h"
|
350
356
|
driver.display_names([name])
|
351
357
|
rescue RDoc::RI::Driver::NotFoundError
|
358
|
+
ensure
|
359
|
+
print "\e[?1049l"
|
352
360
|
end
|
353
361
|
end
|
354
362
|
end
|
data/lib/irb/inspector.rb
CHANGED
@@ -92,9 +92,14 @@ module IRB # :nodoc:
|
|
92
92
|
@init.call if @init
|
93
93
|
end
|
94
94
|
|
95
|
+
def support_stream_output?
|
96
|
+
second_parameter_type = @inspect.parameters[1]&.first
|
97
|
+
second_parameter_type == :req || second_parameter_type == :opt
|
98
|
+
end
|
99
|
+
|
95
100
|
# Proc to call when the input is evaluated and output in irb.
|
96
|
-
def inspect_value(v)
|
97
|
-
@inspect.call(v)
|
101
|
+
def inspect_value(v, output, colorize: true)
|
102
|
+
support_stream_output? ? @inspect.call(v, output, colorize: colorize) : output << @inspect.call(v, colorize: colorize)
|
98
103
|
rescue => e
|
99
104
|
puts "An error occurred when inspecting the object: #{e.inspect}"
|
100
105
|
|
@@ -110,11 +115,11 @@ module IRB # :nodoc:
|
|
110
115
|
end
|
111
116
|
|
112
117
|
Inspector.def_inspector([false, :to_s, :raw]){|v| v.to_s}
|
113
|
-
Inspector.def_inspector([:p, :inspect]){|v|
|
114
|
-
Color.colorize_code(v.inspect, colorable: Color.colorable? && Color.inspect_colorable?(v))
|
118
|
+
Inspector.def_inspector([:p, :inspect]){|v, colorize: true|
|
119
|
+
Color.colorize_code(v.inspect, colorable: colorize && Color.colorable? && Color.inspect_colorable?(v))
|
115
120
|
}
|
116
|
-
Inspector.def_inspector([true, :pp, :pretty_inspect], proc{require_relative "color_printer"}){|v|
|
117
|
-
IRB::ColorPrinter.pp(v,
|
121
|
+
Inspector.def_inspector([true, :pp, :pretty_inspect], proc{require_relative "color_printer"}){|v, output, colorize: true|
|
122
|
+
IRB::ColorPrinter.pp(v, output, colorize: colorize)
|
118
123
|
}
|
119
124
|
Inspector.def_inspector([:yaml, :YAML], proc{require "yaml"}){|v|
|
120
125
|
begin
|
data/lib/irb/lc/ja/help-message
CHANGED
@@ -8,7 +8,7 @@ Usage: irb.rb [options] [programfile] [arguments]
|
|
8
8
|
-w ruby -w と同じ.
|
9
9
|
-W[level=2] ruby -W と同じ.
|
10
10
|
--context-mode n 新しいワークスペースを作成した時に関連する Binding
|
11
|
-
オブジェクトの作成方法を 0 から
|
11
|
+
オブジェクトの作成方法を 0 から 4 のいずれかに設定する.
|
12
12
|
--extra-doc-dir 指定したディレクトリのドキュメントを追加で読み込む.
|
13
13
|
--echo 実行結果を表示する(デフォルト).
|
14
14
|
--noecho 実行結果を表示しない.
|
@@ -33,9 +33,9 @@ Usage: irb.rb [options] [programfile] [arguments]
|
|
33
33
|
補完に正規表現を利用する.
|
34
34
|
--type-completor 補完に型情報を利用する.
|
35
35
|
--prompt prompt-mode/--prompt-mode prompt-mode
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
プロンプトモードを切り替える.
|
37
|
+
現在定義されているプロンプトモードは,
|
38
|
+
default, classic, simple, inf-ruby, xmp, null.
|
39
39
|
--inf-ruby-mode emacsのinf-ruby-mode用のプロンプト表示を行なう. 特
|
40
40
|
に指定がない限り, シングルラインエディタとマルチラ
|
41
41
|
インエディタは使わなくなる.
|
data/lib/irb/nesting_parser.rb
CHANGED
@@ -159,7 +159,7 @@ module IRB
|
|
159
159
|
when :on_heredoc_end
|
160
160
|
opens.pop
|
161
161
|
when :on_backtick
|
162
|
-
opens << [t, nil]
|
162
|
+
opens << [t, nil] unless t.state == Ripper::EXPR_ARG
|
163
163
|
when :on_tstring_beg, :on_words_beg, :on_qwords_beg, :on_symbols_beg, :on_qsymbols_beg, :on_regexp_beg
|
164
164
|
opens << [t, nil]
|
165
165
|
when :on_tstring_end, :on_regexp_end, :on_label_end
|