irb 1.7.1 → 1.13.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.document +1 -1
- data/Gemfile +10 -1
- data/README.md +265 -20
- data/Rakefile +13 -10
- data/doc/irb/irb.rd.ja +1 -3
- data/irb.gemspec +2 -1
- data/lib/irb/cmd/nop.rb +3 -52
- data/lib/irb/color.rb +4 -2
- data/lib/irb/command/backtrace.rb +17 -0
- data/lib/irb/command/base.rb +62 -0
- data/lib/irb/command/break.rb +17 -0
- data/lib/irb/command/catch.rb +17 -0
- data/lib/irb/command/chws.rb +40 -0
- data/lib/irb/command/context.rb +16 -0
- data/lib/irb/{cmd → command}/continue.rb +3 -3
- data/lib/irb/command/debug.rb +71 -0
- data/lib/irb/{cmd → command}/delete.rb +3 -3
- data/lib/irb/command/disable_irb.rb +19 -0
- data/lib/irb/command/edit.rb +63 -0
- data/lib/irb/command/exit.rb +18 -0
- data/lib/irb/{cmd → command}/finish.rb +3 -3
- data/lib/irb/command/force_exit.rb +18 -0
- data/lib/irb/command/help.rb +83 -0
- data/lib/irb/command/history.rb +45 -0
- data/lib/irb/command/info.rb +17 -0
- data/lib/irb/command/internal_helpers.rb +27 -0
- data/lib/irb/{cmd → command}/irb_info.rb +7 -7
- data/lib/irb/{cmd → command}/load.rb +23 -8
- data/lib/irb/{cmd → command}/ls.rb +42 -19
- data/lib/irb/{cmd → command}/measure.rb +18 -17
- data/lib/irb/{cmd → command}/next.rb +3 -3
- data/lib/irb/command/pushws.rb +65 -0
- data/lib/irb/command/show_doc.rb +51 -0
- data/lib/irb/command/show_source.rb +74 -0
- data/lib/irb/{cmd → command}/step.rb +3 -3
- data/lib/irb/command/subirb.rb +123 -0
- data/lib/irb/{cmd → command}/whereami.rb +3 -5
- data/lib/irb/command.rb +23 -0
- data/lib/irb/completion.rb +133 -102
- data/lib/irb/context.rb +182 -66
- data/lib/irb/debug/ui.rb +103 -0
- data/lib/irb/{cmd/debug.rb → debug.rb} +53 -59
- data/lib/irb/default_commands.rb +265 -0
- data/lib/irb/easter-egg.rb +16 -6
- data/lib/irb/ext/change-ws.rb +6 -8
- data/lib/irb/ext/{history.rb → eval_history.rb} +7 -7
- data/lib/irb/ext/loader.rb +4 -4
- data/lib/irb/ext/multi-irb.rb +5 -5
- data/lib/irb/ext/tracer.rb +12 -51
- data/lib/irb/ext/use-loader.rb +6 -8
- data/lib/irb/ext/workspaces.rb +10 -34
- data/lib/irb/frame.rb +1 -1
- data/lib/irb/help.rb +3 -3
- data/lib/irb/helper_method/base.rb +16 -0
- data/lib/irb/helper_method/conf.rb +11 -0
- data/lib/irb/helper_method.rb +29 -0
- data/lib/irb/{ext/save-history.rb → history.rb} +20 -58
- data/lib/irb/init.rb +154 -58
- data/lib/irb/input-method.rb +238 -203
- data/lib/irb/inspector.rb +3 -3
- data/lib/irb/lc/error.rb +1 -11
- data/lib/irb/lc/help-message +4 -0
- data/lib/irb/lc/ja/error.rb +1 -11
- data/lib/irb/lc/ja/help-message +13 -0
- data/lib/irb/locale.rb +2 -2
- data/lib/irb/nesting_parser.rb +13 -3
- data/lib/irb/notifier.rb +1 -1
- data/lib/irb/output-method.rb +2 -8
- data/lib/irb/pager.rb +91 -0
- data/lib/irb/ruby-lex.rb +391 -471
- data/lib/irb/ruby_logo.aa +43 -0
- data/lib/irb/source_finder.rb +139 -0
- data/lib/irb/statement.rb +80 -0
- data/lib/irb/version.rb +3 -3
- data/lib/irb/workspace.rb +24 -4
- data/lib/irb/ws-for-case-2.rb +1 -1
- data/lib/irb/xmp.rb +3 -3
- data/lib/irb.rb +1232 -604
- data/man/irb.1 +7 -0
- metadata +60 -32
- data/lib/irb/cmd/backtrace.rb +0 -21
- data/lib/irb/cmd/break.rb +0 -21
- data/lib/irb/cmd/catch.rb +0 -21
- data/lib/irb/cmd/chws.rb +0 -36
- data/lib/irb/cmd/edit.rb +0 -61
- data/lib/irb/cmd/help.rb +0 -23
- data/lib/irb/cmd/info.rb +0 -21
- data/lib/irb/cmd/pushws.rb +0 -45
- data/lib/irb/cmd/show_cmds.rb +0 -39
- data/lib/irb/cmd/show_doc.rb +0 -48
- data/lib/irb/cmd/show_source.rb +0 -113
- data/lib/irb/cmd/subirb.rb +0 -66
- data/lib/irb/extend-command.rb +0 -356
- data/lib/irb/src_encoding.rb +0 -7
data/lib/irb/input-method.rb
CHANGED
@@ -1,24 +1,17 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# irb/input-method.rb - input methods used irb
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
5
5
|
#
|
6
6
|
|
7
|
-
require_relative 'src_encoding'
|
8
7
|
require_relative 'completion'
|
8
|
+
require_relative "history"
|
9
9
|
require 'io/console'
|
10
10
|
require 'reline'
|
11
11
|
|
12
12
|
module IRB
|
13
|
-
STDIN_FILE_NAME = "(line)" # :nodoc:
|
14
13
|
class InputMethod
|
15
|
-
|
16
|
-
# Creates a new input method object
|
17
|
-
def initialize(file = STDIN_FILE_NAME)
|
18
|
-
@file_name = file
|
19
|
-
end
|
20
|
-
# The file name of this input method, usually given during initialization.
|
21
|
-
attr_reader :file_name
|
14
|
+
BASIC_WORD_BREAK_CHARACTERS = " \t\n`><=;|&{("
|
22
15
|
|
23
16
|
# The irb prompt associated with this input method
|
24
17
|
attr_accessor :prompt
|
@@ -27,7 +20,7 @@ module IRB
|
|
27
20
|
#
|
28
21
|
# See IO#gets for more information.
|
29
22
|
def gets
|
30
|
-
fail NotImplementedError
|
23
|
+
fail NotImplementedError
|
31
24
|
end
|
32
25
|
public :gets
|
33
26
|
|
@@ -47,6 +40,14 @@ module IRB
|
|
47
40
|
false
|
48
41
|
end
|
49
42
|
|
43
|
+
def support_history_saving?
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
47
|
+
def prompting?
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
50
51
|
# For debug message
|
51
52
|
def inspect
|
52
53
|
'Abstract InputMethod'
|
@@ -56,7 +57,6 @@ module IRB
|
|
56
57
|
class StdioInputMethod < InputMethod
|
57
58
|
# Creates a new input method object
|
58
59
|
def initialize
|
59
|
-
super
|
60
60
|
@line_no = 0
|
61
61
|
@line = []
|
62
62
|
@stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
|
@@ -67,6 +67,7 @@ module IRB
|
|
67
67
|
#
|
68
68
|
# See IO#gets for more information.
|
69
69
|
def gets
|
70
|
+
puts if @stdout.tty? # workaround for debug compatibility test
|
70
71
|
print @prompt
|
71
72
|
line = @stdin.gets
|
72
73
|
@line[@line_no += 1] = line
|
@@ -95,6 +96,10 @@ module IRB
|
|
95
96
|
true
|
96
97
|
end
|
97
98
|
|
99
|
+
def prompting?
|
100
|
+
STDIN.tty?
|
101
|
+
end
|
102
|
+
|
98
103
|
# Returns the current line number for #io.
|
99
104
|
#
|
100
105
|
# #line counts the number of times #gets is called.
|
@@ -130,12 +135,9 @@ module IRB
|
|
130
135
|
|
131
136
|
# Creates a new input method object
|
132
137
|
def initialize(file)
|
133
|
-
super
|
134
138
|
@io = file.is_a?(IO) ? file : File.open(file)
|
135
139
|
@external_encoding = @io.external_encoding
|
136
140
|
end
|
137
|
-
# The file name of this input method, usually given during initialization.
|
138
|
-
attr_reader :file_name
|
139
141
|
|
140
142
|
# Whether the end of this input method has been reached, returns +true+ if
|
141
143
|
# there is no more data to read.
|
@@ -168,114 +170,99 @@ module IRB
|
|
168
170
|
end
|
169
171
|
end
|
170
172
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
end
|
173
|
+
class ReadlineInputMethod < StdioInputMethod
|
174
|
+
def self.initialize_readline
|
175
|
+
require "readline"
|
176
|
+
rescue LoadError
|
177
|
+
else
|
178
|
+
include ::Readline
|
179
|
+
end
|
179
180
|
|
180
|
-
|
181
|
-
def initialize
|
182
|
-
self.class.initialize_readline
|
183
|
-
if Readline.respond_to?(:encoding_system_needs)
|
184
|
-
IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false)
|
185
|
-
end
|
186
|
-
super
|
181
|
+
include HistorySavingAbility
|
187
182
|
|
188
|
-
|
189
|
-
|
190
|
-
|
183
|
+
# Creates a new input method object using Readline
|
184
|
+
def initialize
|
185
|
+
self.class.initialize_readline
|
186
|
+
if Readline.respond_to?(:encoding_system_needs)
|
187
|
+
IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false)
|
188
|
+
end
|
191
189
|
|
192
|
-
|
193
|
-
@stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
|
190
|
+
super
|
194
191
|
|
195
|
-
|
196
|
-
|
197
|
-
end
|
198
|
-
Readline.completion_append_character = nil
|
199
|
-
Readline.completion_proc = IRB::InputCompletor::CompletionProc
|
200
|
-
end
|
192
|
+
@eof = false
|
193
|
+
@completor = RegexpCompletor.new
|
201
194
|
|
202
|
-
|
203
|
-
|
204
|
-
# See IO#gets for more information.
|
205
|
-
def gets
|
206
|
-
Readline.input = @stdin
|
207
|
-
Readline.output = @stdout
|
208
|
-
if l = readline(@prompt, false)
|
209
|
-
HISTORY.push(l) if !l.empty?
|
210
|
-
@line[@line_no += 1] = l + "\n"
|
211
|
-
else
|
212
|
-
@eof = true
|
213
|
-
l
|
214
|
-
end
|
195
|
+
if Readline.respond_to?("basic_word_break_characters=")
|
196
|
+
Readline.basic_word_break_characters = BASIC_WORD_BREAK_CHARACTERS
|
215
197
|
end
|
198
|
+
Readline.completion_append_character = nil
|
199
|
+
Readline.completion_proc = ->(target) {
|
200
|
+
bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
|
201
|
+
@completor.completion_candidates('', target, '', bind: bind)
|
202
|
+
}
|
203
|
+
end
|
216
204
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
# See IO#eof? for more information.
|
221
|
-
def eof?
|
222
|
-
@eof
|
223
|
-
end
|
205
|
+
def completion_info
|
206
|
+
'RegexpCompletor'
|
207
|
+
end
|
224
208
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
209
|
+
# Reads the next line from this input method.
|
210
|
+
#
|
211
|
+
# See IO#gets for more information.
|
212
|
+
def gets
|
213
|
+
Readline.input = @stdin
|
214
|
+
Readline.output = @stdout
|
215
|
+
if l = readline(@prompt, false)
|
216
|
+
HISTORY.push(l) if !l.empty?
|
217
|
+
@line[@line_no += 1] = l + "\n"
|
218
|
+
else
|
219
|
+
@eof = true
|
220
|
+
l
|
231
221
|
end
|
222
|
+
end
|
232
223
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
end
|
224
|
+
# Whether the end of this input method has been reached, returns +true+
|
225
|
+
# if there is no more data to read.
|
226
|
+
#
|
227
|
+
# See IO#eof? for more information.
|
228
|
+
def eof?
|
229
|
+
@eof
|
230
|
+
end
|
241
231
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
end
|
232
|
+
def prompting?
|
233
|
+
true
|
234
|
+
end
|
246
235
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
end
|
236
|
+
# For debug message
|
237
|
+
def inspect
|
238
|
+
readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
|
239
|
+
str = "ReadlineInputMethod with #{readline_impl} #{Readline::VERSION}"
|
240
|
+
inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
|
241
|
+
str += " and #{inputrc_path}" if File.exist?(inputrc_path)
|
242
|
+
str
|
255
243
|
end
|
256
244
|
end
|
257
245
|
|
258
|
-
class RelineInputMethod <
|
259
|
-
|
260
|
-
|
246
|
+
class RelineInputMethod < StdioInputMethod
|
247
|
+
HISTORY = Reline::HISTORY
|
248
|
+
include HistorySavingAbility
|
261
249
|
# Creates a new input method object using Reline
|
262
|
-
def initialize
|
250
|
+
def initialize(completor)
|
263
251
|
IRB.__send__(:set_encoding, Reline.encoding_system_needs.name, override: false)
|
264
|
-
super
|
265
252
|
|
266
|
-
|
267
|
-
@line = []
|
268
|
-
@eof = false
|
253
|
+
super()
|
269
254
|
|
270
|
-
@
|
271
|
-
@
|
255
|
+
@eof = false
|
256
|
+
@completor = completor
|
272
257
|
|
273
|
-
|
274
|
-
Reline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
|
275
|
-
end
|
258
|
+
Reline.basic_word_break_characters = BASIC_WORD_BREAK_CHARACTERS
|
276
259
|
Reline.completion_append_character = nil
|
277
260
|
Reline.completer_quote_characters = ''
|
278
|
-
Reline.completion_proc =
|
261
|
+
Reline.completion_proc = ->(target, preposing, postposing) {
|
262
|
+
bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
|
263
|
+
@completion_params = [preposing, target, postposing, bind]
|
264
|
+
@completor.completion_candidates(preposing, target, postposing, bind: bind)
|
265
|
+
}
|
279
266
|
Reline.output_modifier_proc =
|
280
267
|
if IRB.conf[:USE_COLORIZE]
|
281
268
|
proc do |output, complete: |
|
@@ -288,18 +275,23 @@ module IRB
|
|
288
275
|
Reline::Unicode.escape_for_print(output)
|
289
276
|
end
|
290
277
|
end
|
291
|
-
Reline.dig_perfect_match_proc =
|
278
|
+
Reline.dig_perfect_match_proc = ->(matched) { display_document(matched) }
|
292
279
|
Reline.autocompletion = IRB.conf[:USE_AUTOCOMPLETE]
|
293
280
|
|
294
281
|
if IRB.conf[:USE_AUTOCOMPLETE]
|
295
282
|
begin
|
296
283
|
require 'rdoc'
|
297
|
-
Reline.add_dialog_proc(:show_doc,
|
284
|
+
Reline.add_dialog_proc(:show_doc, show_doc_dialog_proc, Reline::DEFAULT_DIALOG_CONTEXT)
|
298
285
|
rescue LoadError
|
299
286
|
end
|
300
287
|
end
|
301
288
|
end
|
302
289
|
|
290
|
+
def completion_info
|
291
|
+
autocomplete_message = Reline.autocompletion ? 'Autocomplete' : 'Tab Complete'
|
292
|
+
"#{autocomplete_message}, #{@completor.inspect}"
|
293
|
+
end
|
294
|
+
|
303
295
|
def check_termination(&block)
|
304
296
|
@check_termination_proc = block
|
305
297
|
end
|
@@ -312,100 +304,165 @@ module IRB
|
|
312
304
|
@auto_indent_proc = block
|
313
305
|
end
|
314
306
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
[27, 100], # Normal Alt+d when convert-meta isn't used.
|
320
|
-
[195, 164], # The "ä" that appears when Alt+d is pressed on xterm.
|
321
|
-
[226, 136, 130] # The "∂" that appears when Alt+d in pressed on iTerm2.
|
322
|
-
]
|
307
|
+
def retrieve_doc_namespace(matched)
|
308
|
+
preposing, _target, postposing, bind = @completion_params
|
309
|
+
@completor.doc_namespace(preposing, matched, postposing, bind: bind)
|
310
|
+
end
|
323
311
|
|
324
|
-
|
325
|
-
|
326
|
-
end
|
327
|
-
cursor_pos_to_render, result, pointer, autocomplete_dialog = context.pop(4)
|
328
|
-
return nil if result.nil? or pointer.nil? or pointer < 0
|
329
|
-
name = result[pointer]
|
330
|
-
name = IRB::InputCompletor.retrieve_completion_data(name, doc_namespace: true)
|
312
|
+
def rdoc_ri_driver
|
313
|
+
return @rdoc_ri_driver if defined?(@rdoc_ri_driver)
|
331
314
|
|
332
|
-
|
333
|
-
|
334
|
-
|
315
|
+
begin
|
316
|
+
require 'rdoc'
|
317
|
+
rescue LoadError
|
318
|
+
@rdoc_ri_driver = nil
|
319
|
+
else
|
320
|
+
options = {}
|
321
|
+
options[:extra_doc_dirs] = IRB.conf[:EXTRA_DOC_DIRS] unless IRB.conf[:EXTRA_DOC_DIRS].empty?
|
322
|
+
@rdoc_ri_driver = RDoc::RI::Driver.new(options)
|
323
|
+
end
|
324
|
+
end
|
335
325
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
326
|
+
def show_doc_dialog_proc
|
327
|
+
input_method = self # self is changed in the lambda below.
|
328
|
+
->() {
|
329
|
+
dialog.trap_key = nil
|
330
|
+
alt_d = [
|
331
|
+
[27, 100], # Normal Alt+d when convert-meta isn't used.
|
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?
|
339
|
+
return nil
|
340
340
|
end
|
341
|
-
|
341
|
+
cursor_pos_to_render, result, pointer, autocomplete_dialog = context.pop(4)
|
342
|
+
return nil if result.nil? or pointer.nil? or pointer < 0
|
342
343
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
344
|
+
name = input_method.retrieve_doc_namespace(result[pointer])
|
345
|
+
# Use first one because document dialog does not support multiple namespaces.
|
346
|
+
name = name.first if name.is_a?(Array)
|
347
|
+
|
348
|
+
show_easter_egg = name&.match?(/\ARubyVM/) && !ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
|
349
|
+
|
350
|
+
driver = input_method.rdoc_ri_driver
|
351
|
+
|
352
|
+
if key.match?(dialog.name)
|
353
|
+
if show_easter_egg
|
354
|
+
IRB.__send__(:easter_egg)
|
355
|
+
else
|
356
|
+
begin
|
357
|
+
driver.display_names([name])
|
358
|
+
rescue RDoc::RI::Driver::NotFoundError
|
359
|
+
end
|
360
|
+
end
|
357
361
|
end
|
358
|
-
|
359
|
-
unless used_for_class
|
360
|
-
doc = RDoc::Markup::Document.new
|
362
|
+
|
361
363
|
begin
|
362
|
-
driver.
|
364
|
+
name = driver.expand_name(name)
|
363
365
|
rescue RDoc::RI::Driver::NotFoundError
|
364
|
-
|
366
|
+
return nil
|
365
367
|
rescue
|
366
368
|
return nil # unknown error
|
367
369
|
end
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
370
|
+
doc = nil
|
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
|
377
|
+
end
|
378
|
+
end
|
379
|
+
unless used_for_class
|
380
|
+
doc = RDoc::Markup::Document.new
|
381
|
+
begin
|
382
|
+
driver.add_method(doc, name)
|
383
|
+
rescue RDoc::RI::Driver::NotFoundError
|
384
|
+
doc = nil
|
385
|
+
rescue
|
386
|
+
return nil # unknown error
|
387
|
+
end
|
388
|
+
end
|
389
|
+
return nil if doc.nil?
|
390
|
+
width = 40
|
391
|
+
|
392
|
+
right_x = cursor_pos_to_render.x + autocomplete_dialog.width
|
393
|
+
if right_x + width > screen_width
|
394
|
+
right_width = screen_width - (right_x + 1)
|
395
|
+
left_x = autocomplete_dialog.column - width
|
396
|
+
left_x = 0 if left_x < 0
|
397
|
+
left_width = width > autocomplete_dialog.column ? autocomplete_dialog.column : width
|
398
|
+
if right_width.positive? and left_width.positive?
|
399
|
+
if right_width >= left_width
|
400
|
+
width = right_width
|
401
|
+
x = right_x
|
402
|
+
else
|
403
|
+
width = left_width
|
404
|
+
x = left_x
|
405
|
+
end
|
406
|
+
elsif right_width.positive? and left_width <= 0
|
380
407
|
width = right_width
|
381
408
|
x = right_x
|
382
|
-
|
409
|
+
elsif right_width <= 0 and left_width.positive?
|
383
410
|
width = left_width
|
384
411
|
x = left_x
|
412
|
+
else # Both are negative width.
|
413
|
+
return nil
|
385
414
|
end
|
386
|
-
|
387
|
-
width = right_width
|
415
|
+
else
|
388
416
|
x = right_x
|
389
|
-
elsif right_width <= 0 and left_width.positive?
|
390
|
-
width = left_width
|
391
|
-
x = left_x
|
392
|
-
else # Both are negative width.
|
393
|
-
return nil
|
394
417
|
end
|
418
|
+
formatter = RDoc::Markup::ToAnsi.new
|
419
|
+
formatter.width = width
|
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
|
427
|
+
else
|
428
|
+
message = "Press #{mod_key}+d to read the full document"
|
429
|
+
contents = [message] + doc.accept(formatter).split("\n")
|
430
|
+
end
|
431
|
+
contents = contents.take(preferred_dialog_height)
|
432
|
+
|
433
|
+
y = cursor_pos_to_render.y
|
434
|
+
Reline::DialogRenderInfo.new(pos: Reline::CursorPos.new(x, y), contents: contents, width: width, bg_color: '49')
|
435
|
+
}
|
436
|
+
end
|
437
|
+
|
438
|
+
def display_document(matched)
|
439
|
+
driver = rdoc_ri_driver
|
440
|
+
return unless driver
|
441
|
+
|
442
|
+
if matched =~ /\A(?:::)?RubyVM/ and not ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
|
443
|
+
IRB.__send__(:easter_egg)
|
444
|
+
return
|
445
|
+
end
|
446
|
+
|
447
|
+
namespace = retrieve_doc_namespace(matched)
|
448
|
+
return unless namespace
|
449
|
+
|
450
|
+
if namespace.is_a?(Array)
|
451
|
+
out = RDoc::Markup::Document.new
|
452
|
+
namespace.each do |m|
|
453
|
+
begin
|
454
|
+
driver.add_method(out, m)
|
455
|
+
rescue RDoc::RI::Driver::NotFoundError
|
456
|
+
end
|
457
|
+
end
|
458
|
+
driver.display(out)
|
395
459
|
else
|
396
|
-
|
460
|
+
begin
|
461
|
+
driver.display_names([namespace])
|
462
|
+
rescue RDoc::RI::Driver::NotFoundError
|
463
|
+
end
|
397
464
|
end
|
398
|
-
|
399
|
-
formatter.width = width
|
400
|
-
dialog.trap_key = alt_d
|
401
|
-
mod_key = RUBY_PLATFORM.match?(/darwin/) ? "Option" : "Alt"
|
402
|
-
message = "Press #{mod_key}+d to read the full document"
|
403
|
-
contents = [message] + doc.accept(formatter).split("\n")
|
404
|
-
contents = contents.take(preferred_dialog_height) if respond_to?(:preferred_dialog_height)
|
405
|
-
|
406
|
-
y = cursor_pos_to_render.y
|
407
|
-
DialogRenderInfo.new(pos: Reline::CursorPos.new(x, y), contents: contents, width: width, bg_color: '49')
|
408
|
-
}
|
465
|
+
end
|
409
466
|
|
410
467
|
# Reads the next line from this input method.
|
411
468
|
#
|
@@ -415,8 +472,8 @@ module IRB
|
|
415
472
|
Reline.output = @stdout
|
416
473
|
Reline.prompt_proc = @prompt_proc
|
417
474
|
Reline.auto_indent_proc = @auto_indent_proc if @auto_indent_proc
|
418
|
-
if l = readmultiline(@prompt, false, &@check_termination_proc)
|
419
|
-
HISTORY.push(l) if !l.empty?
|
475
|
+
if l = Reline.readmultiline(@prompt, false, &@check_termination_proc)
|
476
|
+
Reline::HISTORY.push(l) if !l.empty?
|
420
477
|
@line[@line_no += 1] = l + "\n"
|
421
478
|
else
|
422
479
|
@eof = true
|
@@ -432,37 +489,15 @@ module IRB
|
|
432
489
|
@eof
|
433
490
|
end
|
434
491
|
|
435
|
-
|
436
|
-
# read.
|
437
|
-
#
|
438
|
-
# See IO#eof for more information.
|
439
|
-
def readable_after_eof?
|
492
|
+
def prompting?
|
440
493
|
true
|
441
494
|
end
|
442
495
|
|
443
|
-
# Returns the current line number for #io.
|
444
|
-
#
|
445
|
-
# #line counts the number of times #gets is called.
|
446
|
-
#
|
447
|
-
# See IO#lineno for more information.
|
448
|
-
def line(line_no)
|
449
|
-
@line[line_no]
|
450
|
-
end
|
451
|
-
|
452
|
-
# The external encoding for standard input.
|
453
|
-
def encoding
|
454
|
-
@stdin.external_encoding
|
455
|
-
end
|
456
|
-
|
457
496
|
# For debug message
|
458
497
|
def inspect
|
459
498
|
config = Reline::Config.new
|
460
499
|
str = "RelineInputMethod with Reline #{Reline::VERSION}"
|
461
|
-
|
462
|
-
inputrc_path = File.expand_path(config.inputrc_path)
|
463
|
-
else
|
464
|
-
inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
|
465
|
-
end
|
500
|
+
inputrc_path = File.expand_path(config.inputrc_path)
|
466
501
|
str += " and #{inputrc_path}" if File.exist?(inputrc_path)
|
467
502
|
str
|
468
503
|
end
|
data/lib/irb/inspector.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# irb/inspector.rb - inspect methods
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
@@ -46,7 +46,7 @@ module IRB # :nodoc:
|
|
46
46
|
# Determines the inspector to use where +inspector+ is one of the keys passed
|
47
47
|
# during inspector definition.
|
48
48
|
def self.keys_with_inspector(inspector)
|
49
|
-
INSPECTORS.select{|k,v| v == inspector}.collect{|k, v| k}
|
49
|
+
INSPECTORS.select{|k, v| v == inspector}.collect{|k, v| k}
|
50
50
|
end
|
51
51
|
|
52
52
|
# Example
|
@@ -113,7 +113,7 @@ module IRB # :nodoc:
|
|
113
113
|
Color.colorize_code(v.inspect, colorable: Color.colorable? && Color.inspect_colorable?(v))
|
114
114
|
}
|
115
115
|
Inspector.def_inspector([true, :pp, :pretty_inspect], proc{require_relative "color_printer"}){|v|
|
116
|
-
IRB::ColorPrinter.pp(v, '').chomp
|
116
|
+
IRB::ColorPrinter.pp(v, +'').chomp
|
117
117
|
}
|
118
118
|
Inspector.def_inspector([:yaml, :YAML], proc{require "yaml"}){|v|
|
119
119
|
begin
|
data/lib/irb/lc/error.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# irb/lc/error.rb -
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
@@ -12,11 +12,6 @@ module IRB
|
|
12
12
|
super("Unrecognized switch: #{val}")
|
13
13
|
end
|
14
14
|
end
|
15
|
-
class NotImplementedError < StandardError
|
16
|
-
def initialize(val)
|
17
|
-
super("Need to define `#{val}'")
|
18
|
-
end
|
19
|
-
end
|
20
15
|
class CantReturnToNormalMode < StandardError
|
21
16
|
def initialize
|
22
17
|
super("Can't return to normal mode.")
|
@@ -52,11 +47,6 @@ module IRB
|
|
52
47
|
super("Undefined prompt mode(#{val}).")
|
53
48
|
end
|
54
49
|
end
|
55
|
-
class IllegalRCGenerator < StandardError
|
56
|
-
def initialize
|
57
|
-
super("Define illegal RC_NAME_GENERATOR.")
|
58
|
-
end
|
59
|
-
end
|
60
50
|
|
61
51
|
# :startdoc:
|
62
52
|
end
|
data/lib/irb/lc/help-message
CHANGED
@@ -22,6 +22,7 @@ Usage: irb.rb [options] [programfile] [arguments]
|
|
22
22
|
Show truncated result on assignment (default).
|
23
23
|
--inspect Use 'inspect' for output.
|
24
24
|
--noinspect Don't use 'inspect' for output.
|
25
|
+
--no-pager Don't use pager.
|
25
26
|
--multiline Use multiline editor module (default).
|
26
27
|
--nomultiline Don't use multiline editor module.
|
27
28
|
--singleline Use single line editor module.
|
@@ -30,6 +31,9 @@ Usage: irb.rb [options] [programfile] [arguments]
|
|
30
31
|
--nocolorize Don't use color-highlighting.
|
31
32
|
--autocomplete Use auto-completion (default).
|
32
33
|
--noautocomplete Don't use auto-completion.
|
34
|
+
--regexp-completor
|
35
|
+
Use regexp based completion (default).
|
36
|
+
--type-completor Use type based completion.
|
33
37
|
--prompt prompt-mode, --prompt-mode prompt-mode
|
34
38
|
Set prompt mode. Pre-defined prompt modes are:
|
35
39
|
'default', 'classic', 'simple', 'inf-ruby', 'xmp', 'null'.
|