irb 1.13.0 → 1.13.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4425b668e9f62b7535ef0db6b790b8e15a0ca62d4b81461d758c645c6043496
4
- data.tar.gz: 36977d4a243c9acbc057729ff7bd6ea2432f8cfdb4013e7e4f2c05bebef26c70
3
+ metadata.gz: 243737997cdd6abe7e129eb7e7945dca379f1af38ed4254dfe094f2a611918cc
4
+ data.tar.gz: 5a1cbbdf5ab88a61278afe32a5497f38efa1342e123734ae3ede6135aae9b91f
5
5
  SHA512:
6
- metadata.gz: 804b6fa04f60f7ecc3bf98a9aa818fd8a0e177528c455ac46e853683463176b3eb651eb81e079b70870d2c4f55ab99d4292f10563f42b4c50d697e8e9684b810
7
- data.tar.gz: 0f554e6950eda72508cf3af5eb4c446fc0584eec20c843cbf7ae653698b233add55251028dcf7a4991df5dfdfb90956589b728d727d4deb9e64cfe524349aab5
6
+ metadata.gz: 0b4e5d658e1eba4a0503ffd3776c3baffabb0782eb43a993aac593b6dc4383e9e209ca3c1f077c78225f612a1ac7607f951bc11a2ff8fd78a93e12029fbf1954
7
+ data.tar.gz: c9e978f318f22d322934b77b8c431830e67a9cb7cf365923041f77123ee5e7d39ffa814a4e7bdd9af759f4671d0b24bd2ae68a9d20beb54b4a0e4248e32ee85f
@@ -18,12 +18,12 @@ module IRB
18
18
  class << self
19
19
  def category(category = nil)
20
20
  @category = category if category
21
- @category
21
+ @category || "No category"
22
22
  end
23
23
 
24
24
  def description(description = nil)
25
25
  @description = description if description
26
- @description
26
+ @description || "No description provided."
27
27
  end
28
28
 
29
29
  def help_message(help_message = nil)
@@ -8,11 +8,6 @@ module IRB
8
8
  category "Debugging"
9
9
  description "Start the debugger of debug.gem."
10
10
 
11
- BINDING_IRB_FRAME_REGEXPS = [
12
- '<internal:prelude>',
13
- binding.method(:irb).source_location.first,
14
- ].map { |file| /\A#{Regexp.escape(file)}:\d+:in (`|'Binding#)irb'\z/ }
15
-
16
11
  def execute(_arg)
17
12
  execute_debug_command
18
13
  end
@@ -36,7 +31,7 @@ module IRB
36
31
  # 3. Insert a debug breakpoint at `Irb#debug_break` with the intended command.
37
32
  # 4. Exit the current Irb#run call via `throw :IRB_EXIT`.
38
33
  # 5. `Irb#debug_break` will be called and trigger the breakpoint, which will run the intended command.
39
- unless binding_irb?
34
+ unless irb_context.from_binding?
40
35
  puts "Debugging commands are only available when IRB is started with binding.irb"
41
36
  return
42
37
  end
@@ -60,16 +55,6 @@ module IRB
60
55
  throw :IRB_EXIT
61
56
  end
62
57
  end
63
-
64
- private
65
-
66
- def binding_irb?
67
- caller.any? do |frame|
68
- BINDING_IRB_FRAME_REGEXPS.any? do |regexp|
69
- frame.match?(regexp)
70
- end
71
- end
72
- end
73
58
  end
74
59
 
75
60
  class DebugCommand < Debug
@@ -28,17 +28,9 @@ module IRB
28
28
  commands_grouped_by_categories = commands_info.group_by { |cmd| cmd[:category] }
29
29
  commands_grouped_by_categories["Helper methods"] = helper_methods_info
30
30
 
31
- user_aliases = irb_context.instance_variable_get(:@user_aliases)
32
-
33
- commands_grouped_by_categories["Aliases"] = user_aliases.map do |alias_name, target|
34
- { display_name: alias_name, description: "Alias for `#{target}`" }
35
- end
36
-
37
31
  if irb_context.with_debugger
38
32
  # Remove the original "Debugging" category
39
33
  commands_grouped_by_categories.delete("Debugging")
40
- # Add an empty "Debugging (from debug.gem)" category at the end
41
- commands_grouped_by_categories["Debugging (from debug.gem)"] = []
42
34
  end
43
35
 
44
36
  longest_cmd_name_length = commands_info.map { |c| c[:display_name].length }.max
@@ -46,15 +38,31 @@ module IRB
46
38
  output = StringIO.new
47
39
 
48
40
  help_cmds = commands_grouped_by_categories.delete("Help")
41
+ no_category_cmds = commands_grouped_by_categories.delete("No category")
42
+ aliases = irb_context.instance_variable_get(:@user_aliases).map do |alias_name, target|
43
+ { display_name: alias_name, description: "Alias for `#{target}`" }
44
+ end
49
45
 
46
+ # Display help commands first
50
47
  add_category_to_output("Help", help_cmds, output, longest_cmd_name_length)
51
48
 
49
+ # Display the rest of the commands grouped by categories
52
50
  commands_grouped_by_categories.each do |category, cmds|
53
51
  add_category_to_output(category, cmds, output, longest_cmd_name_length)
54
52
  end
55
53
 
54
+ # Display commands without a category
55
+ if no_category_cmds
56
+ add_category_to_output("No category", no_category_cmds, output, longest_cmd_name_length)
57
+ end
58
+
59
+ # Display aliases
60
+ add_category_to_output("Aliases", aliases, output, longest_cmd_name_length)
61
+
56
62
  # Append the debugger help at the end
57
63
  if irb_context.with_debugger
64
+ # Add "Debugging (from debug.gem)" category as title
65
+ add_category_to_output("Debugging (from debug.gem)", [], output, longest_cmd_name_length)
58
66
  output.puts DEBUGGER__.help
59
67
  end
60
68
 
data/lib/irb/context.rb CHANGED
@@ -73,11 +73,12 @@ module IRB
73
73
 
74
74
  self.prompt_mode = IRB.conf[:PROMPT_MODE]
75
75
 
76
- if IRB.conf[:SINGLE_IRB] or !defined?(IRB::JobManager)
77
- @irb_name = IRB.conf[:IRB_NAME]
78
- else
79
- @irb_name = IRB.conf[:IRB_NAME]+"#"+IRB.JobManager.n_jobs.to_s
76
+ @irb_name = IRB.conf[:IRB_NAME]
77
+
78
+ unless IRB.conf[:SINGLE_IRB] or !defined?(IRB::JobManager)
79
+ @irb_name = @irb_name + "#" + IRB.JobManager.n_jobs.to_s
80
80
  end
81
+
81
82
  self.irb_path = "(" + @irb_name + ")"
82
83
 
83
84
  case input_method
@@ -85,7 +86,7 @@ module IRB
85
86
  @io = nil
86
87
  case use_multiline?
87
88
  when nil
88
- if STDIN.tty? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !use_singleline?
89
+ if term_interactive? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !use_singleline?
89
90
  # Both of multiline mode and singleline mode aren't specified.
90
91
  @io = RelineInputMethod.new(build_completor)
91
92
  else
@@ -99,7 +100,7 @@ module IRB
99
100
  unless @io
100
101
  case use_singleline?
101
102
  when nil
102
- if (defined?(ReadlineInputMethod) && STDIN.tty? &&
103
+ if (defined?(ReadlineInputMethod) && term_interactive? &&
103
104
  IRB.conf[:PROMPT_MODE] != :INF_RUBY)
104
105
  @io = ReadlineInputMethod.new
105
106
  else
@@ -151,6 +152,11 @@ module IRB
151
152
  @command_aliases = @user_aliases.merge(KEYWORD_ALIASES)
152
153
  end
153
154
 
155
+ private def term_interactive?
156
+ return true if ENV['TEST_IRB_FORCE_INTERACTIVE']
157
+ STDIN.tty? && ENV['TERM'] != 'dumb'
158
+ end
159
+
154
160
  # because all input will eventually be evaluated as Ruby code,
155
161
  # command names that conflict with Ruby keywords need special workaround
156
162
  # we can remove them once we implemented a better command system for IRB
@@ -602,6 +608,10 @@ module IRB
602
608
  nil
603
609
  end
604
610
 
611
+ def from_binding?
612
+ @irb.from_binding
613
+ end
614
+
605
615
  def evaluate_expression(code, line_no) # :nodoc:
606
616
  result = nil
607
617
  if IRB.conf[:MEASURE] && IRB.conf[:MEASURE_CALLBACKS].empty?
@@ -2,32 +2,33 @@
2
2
 
3
3
  require_relative "command"
4
4
  require_relative "command/internal_helpers"
5
- require_relative "command/context"
6
- require_relative "command/exit"
7
- require_relative "command/force_exit"
8
- require_relative "command/chws"
9
- require_relative "command/pushws"
10
- require_relative "command/subirb"
11
- require_relative "command/load"
12
- require_relative "command/debug"
13
- require_relative "command/edit"
5
+ require_relative "command/backtrace"
14
6
  require_relative "command/break"
15
7
  require_relative "command/catch"
16
- require_relative "command/next"
17
- require_relative "command/delete"
18
- require_relative "command/step"
8
+ require_relative "command/chws"
9
+ require_relative "command/context"
19
10
  require_relative "command/continue"
11
+ require_relative "command/debug"
12
+ require_relative "command/delete"
13
+ require_relative "command/disable_irb"
14
+ require_relative "command/edit"
15
+ require_relative "command/exit"
20
16
  require_relative "command/finish"
21
- require_relative "command/backtrace"
22
- require_relative "command/info"
17
+ require_relative "command/force_exit"
23
18
  require_relative "command/help"
24
- require_relative "command/show_doc"
19
+ require_relative "command/history"
20
+ require_relative "command/info"
25
21
  require_relative "command/irb_info"
22
+ require_relative "command/load"
26
23
  require_relative "command/ls"
27
24
  require_relative "command/measure"
25
+ require_relative "command/next"
26
+ require_relative "command/pushws"
27
+ require_relative "command/show_doc"
28
28
  require_relative "command/show_source"
29
+ require_relative "command/step"
30
+ require_relative "command/subirb"
29
31
  require_relative "command/whereami"
30
- require_relative "command/history"
31
32
 
32
33
  module IRB
33
34
  module Command
@@ -235,6 +236,10 @@ module IRB
235
236
  [:history, NO_OVERRIDE],
236
237
  [:hist, NO_OVERRIDE]
237
238
  )
239
+
240
+ _register_with_aliases(:irb_disable_irb, Command::DisableIrb,
241
+ [:disable_irb, NO_OVERRIDE]
242
+ )
238
243
  end
239
244
 
240
245
  ExtendCommand = Command
@@ -1,7 +1,7 @@
1
1
  module IRB
2
2
  module HelperMethod
3
3
  class Conf < Base
4
- description "Returns the current context."
4
+ description "Returns the current IRB context."
5
5
 
6
6
  def execute
7
7
  IRB.CurrentContext
data/lib/irb/init.rb CHANGED
@@ -52,6 +52,7 @@ module IRB # :nodoc:
52
52
  IRB.init_error
53
53
  IRB.parse_opts(argv: argv)
54
54
  IRB.run_config
55
+ IRB.validate_config
55
56
  IRB.load_modules
56
57
 
57
58
  unless @CONF[:PROMPT][@CONF[:PROMPT_MODE]]
@@ -427,6 +428,40 @@ module IRB # :nodoc:
427
428
  @irbrc_files
428
429
  end
429
430
 
431
+ def IRB.validate_config
432
+ conf[:IRB_NAME] = conf[:IRB_NAME].to_s
433
+
434
+ irb_rc = conf[:IRB_RC]
435
+ unless irb_rc.nil? || irb_rc.respond_to?(:call)
436
+ raise_validation_error "IRB.conf[:IRB_RC] should be a callable object. Got #{irb_rc.inspect}."
437
+ end
438
+
439
+ back_trace_limit = conf[:BACK_TRACE_LIMIT]
440
+ unless back_trace_limit.is_a?(Integer)
441
+ raise_validation_error "IRB.conf[:BACK_TRACE_LIMIT] should be an integer. Got #{back_trace_limit.inspect}."
442
+ end
443
+
444
+ prompt = conf[:PROMPT]
445
+ unless prompt.is_a?(Hash)
446
+ msg = "IRB.conf[:PROMPT] should be a Hash. Got #{prompt.inspect}."
447
+
448
+ if prompt.is_a?(Symbol)
449
+ msg += " Did you mean to set `IRB.conf[:PROMPT_MODE]`?"
450
+ end
451
+
452
+ raise_validation_error msg
453
+ end
454
+
455
+ eval_history = conf[:EVAL_HISTORY]
456
+ unless eval_history.nil? || eval_history.is_a?(Integer)
457
+ raise_validation_error "IRB.conf[:EVAL_HISTORY] should be an integer. Got #{eval_history.inspect}."
458
+ end
459
+ end
460
+
461
+ def IRB.raise_validation_error(msg)
462
+ raise TypeError, msg, @irbrc_files
463
+ end
464
+
430
465
  # loading modules
431
466
  def IRB.load_modules
432
467
  for m in @CONF[:LOAD_MODULES]
@@ -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
@@ -327,10 +328,11 @@ module IRB
327
328
  ->() {
328
329
  dialog.trap_key = nil
329
330
  alt_d = [
330
- [Reline::Key.new(nil, 0xE4, true)], # Normal Alt+d.
331
331
  [27, 100], # Normal Alt+d when convert-meta isn't used.
332
- [195, 164], # The "ä" that appears when Alt+d is pressed on xterm.
333
- [226, 136, 130] # The "∂" that appears when Alt+d in pressed on iTerm2.
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.
334
336
  ]
335
337
 
336
338
  if just_cursor_moving and completion_journey_data.nil?
data/lib/irb/ruby-lex.rb CHANGED
@@ -219,28 +219,7 @@ module IRB
219
219
  :unrecoverable_error
220
220
  rescue SyntaxError => e
221
221
  case e.message
222
- when /unterminated (?:string|regexp) meets end of file/
223
- # "unterminated regexp meets end of file"
224
- #
225
- # example:
226
- # /
227
- #
228
- # "unterminated string meets end of file"
229
- #
230
- # example:
231
- # '
232
- return :recoverable_error
233
- when /syntax error, unexpected end-of-input/
234
- # "syntax error, unexpected end-of-input, expecting keyword_end"
235
- #
236
- # example:
237
- # if true
238
- # hoge
239
- # if false
240
- # fuga
241
- # end
242
- return :recoverable_error
243
- when /syntax error, unexpected keyword_end/
222
+ when /unexpected keyword_end/
244
223
  # "syntax error, unexpected keyword_end"
245
224
  #
246
225
  # example:
@@ -250,7 +229,7 @@ module IRB
250
229
  # example:
251
230
  # end
252
231
  return :unrecoverable_error
253
- when /syntax error, unexpected '\.'/
232
+ when /unexpected '\.'/
254
233
  # "syntax error, unexpected '.'"
255
234
  #
256
235
  # example:
@@ -262,6 +241,27 @@ module IRB
262
241
  # example:
263
242
  # method / f /
264
243
  return :unrecoverable_error
244
+ when /unterminated (?:string|regexp) meets end of file/
245
+ # "unterminated regexp meets end of file"
246
+ #
247
+ # example:
248
+ # /
249
+ #
250
+ # "unterminated string meets end of file"
251
+ #
252
+ # example:
253
+ # '
254
+ return :recoverable_error
255
+ when /unexpected end-of-input/
256
+ # "syntax error, unexpected end-of-input, expecting keyword_end"
257
+ #
258
+ # example:
259
+ # if true
260
+ # hoge
261
+ # if false
262
+ # fuga
263
+ # end
264
+ return :recoverable_error
265
265
  else
266
266
  return :other_error
267
267
  end
data/lib/irb/version.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  #
6
6
 
7
7
  module IRB # :nodoc:
8
- VERSION = "1.13.0"
8
+ VERSION = "1.13.2"
9
9
  @RELEASE_VERSION = VERSION
10
- @LAST_UPDATE_DATE = "2024-05-01"
10
+ @LAST_UPDATE_DATE = "2024-06-15"
11
11
  end
data/lib/irb.rb CHANGED
@@ -311,7 +311,9 @@ require_relative "irb/pager"
311
311
  # ### Input Method
312
312
  #
313
313
  # The IRB input method determines how command input is to be read; by default,
314
- # the input method for a session is IRB::RelineInputMethod.
314
+ # the input method for a session is IRB::RelineInputMethod. Unless the
315
+ # value of the TERM environment variable is 'dumb', in which case the
316
+ # most simplistic input method is used.
315
317
  #
316
318
  # You can set the input method by:
317
319
  #
@@ -329,7 +331,8 @@ require_relative "irb/pager"
329
331
  # IRB::ReadlineInputMethod.
330
332
  # * `--nosingleline` or `--multiline` sets the input method to
331
333
  # IRB::RelineInputMethod.
332
- #
334
+ # * `--nosingleline` together with `--nomultiline` sets the
335
+ # input to IRB::StdioInputMethod.
333
336
  #
334
337
  #
335
338
  # Method `conf.use_multiline?` and its synonym `conf.use_reline` return:
@@ -928,8 +931,11 @@ module IRB
928
931
  # The lexer used by this irb session
929
932
  attr_accessor :scanner
930
933
 
934
+ attr_reader :from_binding
935
+
931
936
  # Creates a new irb session
932
- def initialize(workspace = nil, input_method = nil)
937
+ def initialize(workspace = nil, input_method = nil, from_binding: false)
938
+ @from_binding = from_binding
933
939
  @context = Context.new(self, workspace, input_method)
934
940
  @context.workspace.load_helper_methods_to_main
935
941
  @signal_status = :IN_IRB
@@ -1593,7 +1599,7 @@ class Binding
1593
1599
  else
1594
1600
  # If we're not in a debugger session, create a new IRB instance with the current
1595
1601
  # workspace
1596
- binding_irb = IRB::Irb.new(workspace)
1602
+ binding_irb = IRB::Irb.new(workspace, from_binding: true)
1597
1603
  binding_irb.context.irb_path = irb_path
1598
1604
  binding_irb.run(IRB.conf)
1599
1605
  binding_irb.debug_break
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.0
4
+ version: 1.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-05-01 00:00:00.000000000 Z
12
+ date: 2024-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: reline
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  - !ruby/object:Gem::Version
158
158
  version: '0'
159
159
  requirements: []
160
- rubygems_version: 3.5.7
160
+ rubygems_version: 3.5.11
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).