irb 1.14.0 → 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 -293
- 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 +46 -13
- data/lib/irb/command/copy.rb +83 -0
- data/lib/irb/command/debug.rb +8 -6
- data/lib/irb/command/help.rb +1 -1
- data/lib/irb/command/history.rb +1 -1
- data/lib/irb/command/internal_helpers.rb +7 -4
- data/lib/irb/command/ls.rb +29 -15
- data/lib/irb/completion.rb +81 -57
- data/lib/irb/context.rb +132 -53
- data/lib/irb/debug/ui.rb +2 -4
- data/lib/irb/debug.rb +9 -12
- data/lib/irb/default_commands.rb +19 -8
- data/lib/irb/easter-egg.rb +13 -7
- data/lib/irb/ext/multi-irb.rb +2 -0
- data/lib/irb/history.rb +84 -55
- data/lib/irb/init.rb +7 -2
- data/lib/irb/input-method.rb +167 -130
- data/lib/irb/inspector.rb +42 -36
- data/lib/irb/lc/help-message +2 -2
- data/lib/irb/lc/ja/help-message +4 -4
- data/lib/irb/nesting_parser.rb +364 -213
- data/lib/irb/pager.rb +137 -7
- data/lib/irb/ruby-lex.rb +230 -302
- data/lib/irb/ruby_logo.aa +79 -37
- data/lib/irb/source_finder.rb +15 -22
- 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 +22 -31
- data/lib/irb.rb +148 -986
- data/man/irb.1 +37 -2
- metadata +42 -12
- data/.document +0 -4
- data/Rakefile +0 -54
- data/bin/console +0 -6
- data/bin/setup +0 -6
- data/irb.gemspec +0 -46
data/lib/irb/input-method.rb
CHANGED
|
@@ -26,10 +26,11 @@ module IRB
|
|
|
26
26
|
|
|
27
27
|
def winsize
|
|
28
28
|
if instance_variable_defined?(:@stdout) && @stdout.tty?
|
|
29
|
-
@stdout.winsize
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
winsize = @stdout.winsize
|
|
30
|
+
# If width or height is 0, something is wrong.
|
|
31
|
+
return winsize unless winsize.include? 0
|
|
32
32
|
end
|
|
33
|
+
[24, 80]
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
# Whether this input method is still readable when there is no more data to
|
|
@@ -67,7 +68,9 @@ module IRB
|
|
|
67
68
|
#
|
|
68
69
|
# See IO#gets for more information.
|
|
69
70
|
def gets
|
|
70
|
-
|
|
71
|
+
# Workaround for debug compatibility test https://github.com/ruby/debug/pull/1100
|
|
72
|
+
puts if ENV['RUBY_DEBUG_TEST_UI']
|
|
73
|
+
|
|
71
74
|
print @prompt
|
|
72
75
|
line = @stdin.gets
|
|
73
76
|
@line[@line_no += 1] = line
|
|
@@ -171,11 +174,18 @@ module IRB
|
|
|
171
174
|
end
|
|
172
175
|
|
|
173
176
|
class ReadlineInputMethod < StdioInputMethod
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
class << self
|
|
178
|
+
def initialize_readline
|
|
179
|
+
return if defined?(self::Readline)
|
|
180
|
+
|
|
181
|
+
begin
|
|
182
|
+
require 'readline'
|
|
183
|
+
const_set(:Readline, ::Readline)
|
|
184
|
+
rescue LoadError
|
|
185
|
+
const_set(:Readline, ::Reline)
|
|
186
|
+
end
|
|
187
|
+
const_set(:HISTORY, self::Readline::HISTORY)
|
|
188
|
+
end
|
|
179
189
|
end
|
|
180
190
|
|
|
181
191
|
include HistorySavingAbility
|
|
@@ -212,8 +222,8 @@ module IRB
|
|
|
212
222
|
def gets
|
|
213
223
|
Readline.input = @stdin
|
|
214
224
|
Readline.output = @stdout
|
|
215
|
-
if l = readline(@prompt, false)
|
|
216
|
-
HISTORY.push(l) if !l.empty?
|
|
225
|
+
if l = Readline.readline(@prompt, false)
|
|
226
|
+
Readline::HISTORY.push(l) if !l.empty? && l != Readline::HISTORY.to_a.last
|
|
217
227
|
@line[@line_no += 1] = l + "\n"
|
|
218
228
|
else
|
|
219
229
|
@eof = true
|
|
@@ -235,7 +245,7 @@ module IRB
|
|
|
235
245
|
|
|
236
246
|
# For debug message
|
|
237
247
|
def inspect
|
|
238
|
-
readline_impl =
|
|
248
|
+
readline_impl = Readline == ::Reline ? 'Reline' : 'ext/readline'
|
|
239
249
|
str = "ReadlineInputMethod with #{readline_impl} #{Readline::VERSION}"
|
|
240
250
|
inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
|
|
241
251
|
str += " and #{inputrc_path}" if File.exist?(inputrc_path)
|
|
@@ -245,6 +255,16 @@ module IRB
|
|
|
245
255
|
|
|
246
256
|
class RelineInputMethod < StdioInputMethod
|
|
247
257
|
HISTORY = Reline::HISTORY
|
|
258
|
+
ALT_KEY_NAME = RUBY_PLATFORM.match?(/darwin/) ? "Option" : "Alt"
|
|
259
|
+
PRESS_ALT_D_TO_READ_FULL_DOC = "Press #{ALT_KEY_NAME}+d to read the full document".freeze
|
|
260
|
+
PRESS_ALT_D_TO_SEE_MORE = "Press #{ALT_KEY_NAME}+d to see more".freeze
|
|
261
|
+
ALT_D_SEQUENCES = [
|
|
262
|
+
[27, 100], # Normal Alt+d when convert-meta isn't used.
|
|
263
|
+
# When option/alt is not configured as a meta key in terminal emulator,
|
|
264
|
+
# option/alt + d will send a unicode character depend on OS keyboard setting.
|
|
265
|
+
[195, 164], # "ä" in somewhere (FIXME: environment information is unknown).
|
|
266
|
+
[226, 136, 130] # "∂" Alt+d on Mac keyboard.
|
|
267
|
+
].freeze
|
|
248
268
|
include HistorySavingAbility
|
|
249
269
|
# Creates a new input method object using Reline
|
|
250
270
|
def initialize(completor)
|
|
@@ -263,18 +283,9 @@ module IRB
|
|
|
263
283
|
@completion_params = [preposing, target, postposing, bind]
|
|
264
284
|
@completor.completion_candidates(preposing, target, postposing, bind: bind)
|
|
265
285
|
}
|
|
266
|
-
Reline.output_modifier_proc =
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
next unless IRB::Color.colorable?
|
|
270
|
-
lvars = IRB.CurrentContext&.local_variables || []
|
|
271
|
-
IRB::Color.colorize_code(output, complete: complete, local_variables: lvars)
|
|
272
|
-
end
|
|
273
|
-
else
|
|
274
|
-
proc do |output|
|
|
275
|
-
Reline::Unicode.escape_for_print(output)
|
|
276
|
-
end
|
|
277
|
-
end
|
|
286
|
+
Reline.output_modifier_proc = proc do |input, complete:|
|
|
287
|
+
IRB.CurrentContext.colorize_input(input, complete: complete)
|
|
288
|
+
end
|
|
278
289
|
Reline.dig_perfect_match_proc = ->(matched) { display_document(matched) }
|
|
279
290
|
Reline.autocompletion = IRB.conf[:USE_AUTOCOMPLETE]
|
|
280
291
|
|
|
@@ -304,9 +315,17 @@ module IRB
|
|
|
304
315
|
@auto_indent_proc = block
|
|
305
316
|
end
|
|
306
317
|
|
|
307
|
-
def
|
|
318
|
+
def retrieve_document_target(matched)
|
|
308
319
|
preposing, _target, postposing, bind = @completion_params
|
|
309
|
-
@completor.doc_namespace(preposing, matched, postposing, bind: bind)
|
|
320
|
+
result = @completor.doc_namespace(preposing, matched, postposing, bind: bind)
|
|
321
|
+
case result
|
|
322
|
+
when DocumentTarget, nil
|
|
323
|
+
result
|
|
324
|
+
when Array
|
|
325
|
+
MethodDocument.new(*result)
|
|
326
|
+
when String
|
|
327
|
+
MethodDocument.new(result)
|
|
328
|
+
end
|
|
310
329
|
end
|
|
311
330
|
|
|
312
331
|
def rdoc_ri_driver
|
|
@@ -327,140 +346,158 @@ module IRB
|
|
|
327
346
|
input_method = self # self is changed in the lambda below.
|
|
328
347
|
->() {
|
|
329
348
|
dialog.trap_key = nil
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
# When option/alt is not configured as a meta key in terminal emulator,
|
|
333
|
-
# option/alt + d will send a unicode character depend on OS keyboard setting.
|
|
334
|
-
[195, 164], # "ä" in somewhere (FIXME: environment information is unknown).
|
|
335
|
-
[226, 136, 130] # "∂" Alt+d on Mac keyboard.
|
|
336
|
-
]
|
|
337
|
-
|
|
338
|
-
if just_cursor_moving and completion_journey_data.nil?
|
|
349
|
+
|
|
350
|
+
if just_cursor_moving && completion_journey_data.nil?
|
|
339
351
|
return nil
|
|
340
352
|
end
|
|
341
353
|
cursor_pos_to_render, result, pointer, autocomplete_dialog = context.pop(4)
|
|
342
|
-
return nil if result.nil?
|
|
354
|
+
return nil if result.nil? || pointer.nil? || pointer < 0
|
|
343
355
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
356
|
+
matched_text = result[pointer]
|
|
357
|
+
show_easter_egg = matched_text&.match?(/\ARubyVM/) && !ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
|
|
358
|
+
target = show_easter_egg ? nil : input_method.retrieve_document_target(matched_text)
|
|
347
359
|
|
|
348
|
-
|
|
360
|
+
x, width = input_method.dialog_doc_position(cursor_pos_to_render, autocomplete_dialog, screen_width)
|
|
361
|
+
return nil unless x
|
|
349
362
|
|
|
350
|
-
|
|
363
|
+
dialog.trap_key = ALT_D_SEQUENCES
|
|
351
364
|
|
|
352
365
|
if key.match?(dialog.name)
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
rescue RDoc::RI::Driver::NotFoundError
|
|
359
|
-
end
|
|
366
|
+
begin
|
|
367
|
+
print "\e[?1049h"
|
|
368
|
+
input_method.display_document(matched_text)
|
|
369
|
+
ensure
|
|
370
|
+
print "\e[?1049l"
|
|
360
371
|
end
|
|
361
372
|
end
|
|
362
373
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
used_for_class = false
|
|
372
|
-
if not name =~ /#|\./
|
|
373
|
-
found, klasses, includes, extends = driver.classes_and_includes_and_extends_for(name)
|
|
374
|
-
if not found.empty?
|
|
375
|
-
doc = driver.class_document(name, found, klasses, includes, extends)
|
|
376
|
-
used_for_class = true
|
|
374
|
+
contents = case target
|
|
375
|
+
when CommandDocument
|
|
376
|
+
input_method.command_doc_dialog_contents(target.name, width)
|
|
377
|
+
when MethodDocument
|
|
378
|
+
input_method.rdoc_dialog_contents(target.name, width)
|
|
379
|
+
else
|
|
380
|
+
if show_easter_egg
|
|
381
|
+
input_method.easter_egg_dialog_contents
|
|
377
382
|
end
|
|
378
383
|
end
|
|
379
|
-
unless
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
384
|
+
return nil unless contents
|
|
385
|
+
|
|
386
|
+
contents = contents.take(preferred_dialog_height)
|
|
387
|
+
y = cursor_pos_to_render.y
|
|
388
|
+
Reline::DialogRenderInfo.new(pos: Reline::CursorPos.new(x, y), contents: contents, width: width, bg_color: '49')
|
|
389
|
+
}
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
def command_doc_dialog_contents(command_name, width)
|
|
393
|
+
command_class = IRB::Command.load_command(command_name)
|
|
394
|
+
return unless command_class
|
|
395
|
+
|
|
396
|
+
[PRESS_ALT_D_TO_READ_FULL_DOC, ""] + command_class.doc_dialog_content(command_name, width)
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
def easter_egg_dialog_contents
|
|
400
|
+
type = STDOUT.external_encoding == Encoding::UTF_8 ? :unicode : :ascii
|
|
401
|
+
lines = IRB.send(:easter_egg_logo, type).split("\n")
|
|
402
|
+
lines[0][0, PRESS_ALT_D_TO_SEE_MORE.size] = PRESS_ALT_D_TO_SEE_MORE
|
|
403
|
+
lines
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
def rdoc_dialog_contents(name, width)
|
|
407
|
+
driver = rdoc_ri_driver
|
|
408
|
+
return unless driver
|
|
409
|
+
|
|
410
|
+
name = driver.expand_name(name)
|
|
411
|
+
|
|
412
|
+
doc = if name =~ /#|\./
|
|
413
|
+
d = RDoc::Markup::Document.new
|
|
414
|
+
driver.add_method(d, name)
|
|
415
|
+
d
|
|
416
|
+
else
|
|
417
|
+
found, klasses, includes, extends = driver.classes_and_includes_and_extends_for(name)
|
|
418
|
+
if found.empty?
|
|
419
|
+
d = RDoc::Markup::Document.new
|
|
420
|
+
driver.add_method(d, name)
|
|
421
|
+
d
|
|
422
|
+
else
|
|
423
|
+
driver.class_document(name, found, klasses, includes, extends)
|
|
388
424
|
end
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
formatter = RDoc::Markup::ToAnsi.new
|
|
428
|
+
formatter.width = width
|
|
429
|
+
[PRESS_ALT_D_TO_READ_FULL_DOC] + doc.accept(formatter).split("\n")
|
|
430
|
+
rescue RDoc::RI::Driver::NotFoundError
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
def dialog_doc_position(cursor_pos_to_render, autocomplete_dialog, screen_width)
|
|
434
|
+
width = 40
|
|
435
|
+
right_x = cursor_pos_to_render.x + autocomplete_dialog.width
|
|
436
|
+
if right_x + width > screen_width
|
|
437
|
+
right_width = screen_width - (right_x + 1)
|
|
438
|
+
left_x = autocomplete_dialog.column - width
|
|
439
|
+
left_x = 0 if left_x < 0
|
|
440
|
+
left_width = width > autocomplete_dialog.column ? autocomplete_dialog.column : width
|
|
441
|
+
if right_width.positive? && left_width.positive?
|
|
442
|
+
if right_width >= left_width
|
|
407
443
|
width = right_width
|
|
408
444
|
x = right_x
|
|
409
|
-
|
|
445
|
+
else
|
|
410
446
|
width = left_width
|
|
411
447
|
x = left_x
|
|
412
|
-
else # Both are negative width.
|
|
413
|
-
return nil
|
|
414
448
|
end
|
|
415
|
-
|
|
449
|
+
elsif right_width.positive? && left_width <= 0
|
|
450
|
+
width = right_width
|
|
416
451
|
x = right_x
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
dialog.trap_key = alt_d
|
|
421
|
-
mod_key = RUBY_PLATFORM.match?(/darwin/) ? "Option" : "Alt"
|
|
422
|
-
if show_easter_egg
|
|
423
|
-
type = STDOUT.external_encoding == Encoding::UTF_8 ? :unicode : :ascii
|
|
424
|
-
contents = IRB.send(:easter_egg_logo, type).split("\n")
|
|
425
|
-
message = "Press #{mod_key}+d to see more"
|
|
426
|
-
contents[0][0, message.size] = message
|
|
452
|
+
elsif right_width <= 0 && left_width.positive?
|
|
453
|
+
width = left_width
|
|
454
|
+
x = left_x
|
|
427
455
|
else
|
|
428
|
-
|
|
429
|
-
contents = [message] + doc.accept(formatter).split("\n")
|
|
456
|
+
return nil
|
|
430
457
|
end
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
458
|
+
else
|
|
459
|
+
x = right_x
|
|
460
|
+
end
|
|
461
|
+
[x, width]
|
|
436
462
|
end
|
|
437
463
|
|
|
438
464
|
def display_document(matched)
|
|
439
|
-
|
|
440
|
-
return unless
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
465
|
+
target = retrieve_document_target(matched)
|
|
466
|
+
return unless target
|
|
467
|
+
|
|
468
|
+
case target
|
|
469
|
+
when CommandDocument
|
|
470
|
+
command_class = IRB::Command.load_command(target.name)
|
|
471
|
+
if command_class
|
|
472
|
+
content = command_class.help_message || command_class.description
|
|
473
|
+
Pager.page(retain_content: true) do |io|
|
|
474
|
+
io.puts content
|
|
475
|
+
end
|
|
476
|
+
end
|
|
477
|
+
when MethodDocument
|
|
478
|
+
driver = rdoc_ri_driver
|
|
479
|
+
return unless driver
|
|
446
480
|
|
|
447
|
-
|
|
448
|
-
|
|
481
|
+
if matched =~ /\A(?:::)?RubyVM/ && !ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
|
|
482
|
+
IRB.__send__(:easter_egg)
|
|
483
|
+
return
|
|
484
|
+
end
|
|
449
485
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
486
|
+
if target.names.length > 1
|
|
487
|
+
out = RDoc::Markup::Document.new
|
|
488
|
+
target.names.each do |m|
|
|
489
|
+
begin
|
|
490
|
+
driver.add_method(out, m)
|
|
491
|
+
rescue RDoc::RI::Driver::NotFoundError
|
|
492
|
+
end
|
|
493
|
+
end
|
|
494
|
+
driver.display(out)
|
|
495
|
+
else
|
|
453
496
|
begin
|
|
454
|
-
driver.
|
|
497
|
+
driver.display_names([target.name])
|
|
455
498
|
rescue RDoc::RI::Driver::NotFoundError
|
|
456
499
|
end
|
|
457
500
|
end
|
|
458
|
-
driver.display(out)
|
|
459
|
-
else
|
|
460
|
-
begin
|
|
461
|
-
driver.display_names([namespace])
|
|
462
|
-
rescue RDoc::RI::Driver::NotFoundError
|
|
463
|
-
end
|
|
464
501
|
end
|
|
465
502
|
end
|
|
466
503
|
|
|
@@ -473,7 +510,7 @@ module IRB
|
|
|
473
510
|
Reline.prompt_proc = @prompt_proc
|
|
474
511
|
Reline.auto_indent_proc = @auto_indent_proc if @auto_indent_proc
|
|
475
512
|
if l = Reline.readmultiline(@prompt, false, &@check_termination_proc)
|
|
476
|
-
Reline::HISTORY.push(l) if !l.empty?
|
|
513
|
+
Reline::HISTORY.push(l) if !l.empty? && l != Reline::HISTORY.to_a.last
|
|
477
514
|
@line[@line_no += 1] = l + "\n"
|
|
478
515
|
else
|
|
479
516
|
@eof = true
|
data/lib/irb/inspector.rb
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
module IRB # :nodoc:
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
# Convenience method to create a new Inspector, using the given +inspect+
|
|
11
10
|
# proc, and optional +init+ proc and passes them to Inspector.new
|
|
12
11
|
#
|
|
@@ -43,38 +42,40 @@ module IRB # :nodoc:
|
|
|
43
42
|
# +:marshal+:: Using Marshal.dump
|
|
44
43
|
INSPECTORS = {}
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
# Example
|
|
53
|
-
#
|
|
54
|
-
# Inspector.def_inspector(key, init_p=nil){|v| v.inspect}
|
|
55
|
-
# Inspector.def_inspector([key1,..], init_p=nil){|v| v.inspect}
|
|
56
|
-
# Inspector.def_inspector(key, inspector)
|
|
57
|
-
# Inspector.def_inspector([key1,...], inspector)
|
|
58
|
-
def self.def_inspector(key, arg=nil, &block)
|
|
59
|
-
if block_given?
|
|
60
|
-
inspector = IRB::Inspector(block, arg)
|
|
61
|
-
else
|
|
62
|
-
inspector = arg
|
|
45
|
+
class << self
|
|
46
|
+
# Determines the inspector to use where +inspector+ is one of the keys passed
|
|
47
|
+
# during inspector definition.
|
|
48
|
+
def keys_with_inspector(inspector)
|
|
49
|
+
INSPECTORS.filter_map {|k, v| k if v == inspector}
|
|
63
50
|
end
|
|
64
51
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
52
|
+
# Example
|
|
53
|
+
#
|
|
54
|
+
# Inspector.def_inspector(key, init_p=nil){|v| v.inspect}
|
|
55
|
+
# Inspector.def_inspector([key1,..], init_p=nil){|v| v.inspect}
|
|
56
|
+
# Inspector.def_inspector(key, inspector)
|
|
57
|
+
# Inspector.def_inspector([key1,...], inspector)
|
|
58
|
+
def def_inspector(key, arg=nil, &block)
|
|
59
|
+
if block_given?
|
|
60
|
+
inspector = IRB::Inspector(block, arg)
|
|
61
|
+
else
|
|
62
|
+
inspector = arg
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
case key
|
|
66
|
+
when Array
|
|
67
|
+
for k in key
|
|
68
|
+
def_inspector(k, inspector)
|
|
69
|
+
end
|
|
70
|
+
when Symbol
|
|
71
|
+
INSPECTORS[key] = inspector
|
|
72
|
+
INSPECTORS[key.to_s] = inspector
|
|
73
|
+
when String
|
|
74
|
+
INSPECTORS[key] = inspector
|
|
75
|
+
INSPECTORS[key.intern] = inspector
|
|
76
|
+
else
|
|
77
|
+
INSPECTORS[key] = inspector
|
|
69
78
|
end
|
|
70
|
-
when Symbol
|
|
71
|
-
INSPECTORS[key] = inspector
|
|
72
|
-
INSPECTORS[key.to_s] = inspector
|
|
73
|
-
when String
|
|
74
|
-
INSPECTORS[key] = inspector
|
|
75
|
-
INSPECTORS[key.intern] = inspector
|
|
76
|
-
else
|
|
77
|
-
INSPECTORS[key] = inspector
|
|
78
79
|
end
|
|
79
80
|
end
|
|
80
81
|
|
|
@@ -91,9 +92,14 @@ module IRB # :nodoc:
|
|
|
91
92
|
@init.call if @init
|
|
92
93
|
end
|
|
93
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
|
+
|
|
94
100
|
# Proc to call when the input is evaluated and output in irb.
|
|
95
|
-
def inspect_value(v)
|
|
96
|
-
@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)
|
|
97
103
|
rescue => e
|
|
98
104
|
puts "An error occurred when inspecting the object: #{e.inspect}"
|
|
99
105
|
|
|
@@ -109,11 +115,11 @@ module IRB # :nodoc:
|
|
|
109
115
|
end
|
|
110
116
|
|
|
111
117
|
Inspector.def_inspector([false, :to_s, :raw]){|v| v.to_s}
|
|
112
|
-
Inspector.def_inspector([:p, :inspect]){|v|
|
|
113
|
-
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))
|
|
114
120
|
}
|
|
115
|
-
Inspector.def_inspector([true, :pp, :pretty_inspect], proc{require_relative "color_printer"}){|v|
|
|
116
|
-
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)
|
|
117
123
|
}
|
|
118
124
|
Inspector.def_inspector([:yaml, :YAML], proc{require "yaml"}){|v|
|
|
119
125
|
begin
|
data/lib/irb/lc/help-message
CHANGED
|
@@ -6,10 +6,10 @@ Usage: irb.rb [options] [programfile] [arguments]
|
|
|
6
6
|
-U Set external and internal encodings to UTF-8.
|
|
7
7
|
-E ex[:in] Set default external (ex) and internal (in) encodings
|
|
8
8
|
(same as 'ruby -E').
|
|
9
|
-
-w
|
|
9
|
+
-w Enable warnings (same as 'ruby -w' or 'ruby -W1').
|
|
10
10
|
-W[level=2] Set warning level: 0=silence, 1=medium, 2=verbose
|
|
11
11
|
(same as 'ruby -W').
|
|
12
|
-
--context-mode n Set n[0-
|
|
12
|
+
--context-mode n Set n[0-5] to method to create Binding Object,
|
|
13
13
|
when new workspace was created.
|
|
14
14
|
--extra-doc-dir Add an extra doc dir for the doc dialog.
|
|
15
15
|
--echo Show result (default).
|
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 から 5 のいずれかに設定する.
|
|
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
|
インエディタは使わなくなる.
|