irb 1.11.2 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -8
  3. data/lib/irb/cmd/nop.rb +3 -52
  4. data/lib/irb/{cmd → command}/backtrace.rb +1 -1
  5. data/lib/irb/command/base.rb +64 -0
  6. data/lib/irb/{cmd → command}/break.rb +1 -1
  7. data/lib/irb/{cmd → command}/catch.rb +1 -1
  8. data/lib/irb/{cmd → command}/chws.rb +4 -6
  9. data/lib/irb/{cmd → command}/continue.rb +1 -1
  10. data/lib/irb/{cmd → command}/debug.rb +3 -4
  11. data/lib/irb/{cmd → command}/delete.rb +1 -1
  12. data/lib/irb/command/edit.rb +70 -0
  13. data/lib/irb/{cmd → command}/exit.rb +2 -4
  14. data/lib/irb/{cmd → command}/finish.rb +1 -1
  15. data/lib/irb/command/force_exit.rb +20 -0
  16. data/lib/irb/command/help.rb +84 -0
  17. data/lib/irb/{cmd → command}/history.rb +3 -3
  18. data/lib/irb/{cmd → command}/info.rb +1 -1
  19. data/lib/irb/{cmd → command}/irb_info.rb +5 -6
  20. data/lib/irb/{cmd → command}/load.rb +3 -5
  21. data/lib/irb/{cmd → command}/ls.rb +10 -4
  22. data/lib/irb/{cmd → command}/measure.rb +2 -4
  23. data/lib/irb/{cmd → command}/next.rb +1 -1
  24. data/lib/irb/{cmd → command}/pushws.rb +20 -5
  25. data/lib/irb/{cmd → command}/show_doc.rb +17 -5
  26. data/lib/irb/{cmd → command}/show_source.rb +26 -10
  27. data/lib/irb/{cmd → command}/step.rb +1 -1
  28. data/lib/irb/{cmd → command}/subirb.rb +3 -5
  29. data/lib/irb/{cmd → command}/whereami.rb +2 -4
  30. data/lib/irb/{extend-command.rb → command.rb} +50 -85
  31. data/lib/irb/completion.rb +1 -1
  32. data/lib/irb/context.rb +56 -18
  33. data/lib/irb/ext/change-ws.rb +4 -4
  34. data/lib/irb/ext/eval_history.rb +3 -3
  35. data/lib/irb/ext/loader.rb +4 -4
  36. data/lib/irb/ext/multi-irb.rb +1 -1
  37. data/lib/irb/ext/tracer.rb +1 -1
  38. data/lib/irb/ext/use-loader.rb +6 -8
  39. data/lib/irb/ext/workspaces.rb +11 -34
  40. data/lib/irb/frame.rb +1 -1
  41. data/lib/irb/help.rb +1 -1
  42. data/lib/irb/history.rb +2 -2
  43. data/lib/irb/init.rb +22 -14
  44. data/lib/irb/input-method.rb +18 -2
  45. data/lib/irb/inspector.rb +2 -2
  46. data/lib/irb/lc/error.rb +1 -6
  47. data/lib/irb/lc/ja/error.rb +1 -6
  48. data/lib/irb/locale.rb +1 -1
  49. data/lib/irb/notifier.rb +1 -1
  50. data/lib/irb/output-method.rb +2 -8
  51. data/lib/irb/ruby-lex.rb +1 -1
  52. data/lib/irb/source_finder.rb +98 -38
  53. data/lib/irb/statement.rb +25 -3
  54. data/lib/irb/version.rb +3 -3
  55. data/lib/irb/workspace.rb +4 -4
  56. data/lib/irb/ws-for-case-2.rb +1 -1
  57. data/lib/irb/xmp.rb +1 -1
  58. data/lib/irb.rb +29 -22
  59. metadata +30 -29
  60. data/lib/irb/cmd/edit.rb +0 -60
  61. data/lib/irb/cmd/help.rb +0 -23
  62. data/lib/irb/cmd/show_cmds.rb +0 -59
data/lib/irb.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb.rb - irb main module
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -9,7 +9,7 @@ require "reline"
9
9
 
10
10
  require_relative "irb/init"
11
11
  require_relative "irb/context"
12
- require_relative "irb/extend-command"
12
+ require_relative "irb/command"
13
13
 
14
14
  require_relative "irb/ruby-lex"
15
15
  require_relative "irb/statement"
@@ -811,7 +811,7 @@ require_relative "irb/pager"
811
811
  #
812
812
  # === Commands
813
813
  #
814
- # Please use the `show_cmds` command to see the list of available commands.
814
+ # Please use the `help` command to see the list of available commands.
815
815
  #
816
816
  # === IRB Sessions
817
817
  #
@@ -886,7 +886,7 @@ module IRB
886
886
 
887
887
  # Quits irb
888
888
  def IRB.irb_exit(*)
889
- throw :IRB_EXIT
889
+ throw :IRB_EXIT, false
890
890
  end
891
891
 
892
892
  # Aborts then interrupts irb.
@@ -903,8 +903,8 @@ module IRB
903
903
  # parsed as a :method_add_arg and the output won't be suppressed
904
904
 
905
905
  PROMPT_MAIN_TRUNCATE_LENGTH = 32
906
- PROMPT_MAIN_TRUNCATE_OMISSION = '...'.freeze
907
- CONTROL_CHARACTERS_PATTERN = "\x00-\x1F".freeze
906
+ PROMPT_MAIN_TRUNCATE_OMISSION = '...'
907
+ CONTROL_CHARACTERS_PATTERN = "\x00-\x1F"
908
908
 
909
909
  # Returns the current context of this irb session
910
910
  attr_reader :context
@@ -933,7 +933,7 @@ module IRB
933
933
 
934
934
  def debug_readline(binding)
935
935
  workspace = IRB::WorkSpace.new(binding)
936
- context.workspace = workspace
936
+ context.replace_workspace(workspace)
937
937
  context.workspace.load_commands_to_main
938
938
  @line_no += 1
939
939
 
@@ -979,13 +979,21 @@ module IRB
979
979
  end
980
980
 
981
981
  begin
982
- catch(:IRB_EXIT) do
982
+ if defined?(RubyVM.keep_script_lines)
983
+ keep_script_lines_backup = RubyVM.keep_script_lines
984
+ RubyVM.keep_script_lines = true
985
+ end
986
+
987
+ forced_exit = catch(:IRB_EXIT) do
983
988
  eval_input
984
989
  end
985
990
  ensure
991
+ RubyVM.keep_script_lines = keep_script_lines_backup if defined?(RubyVM.keep_script_lines)
986
992
  trap("SIGINT", prev_trap)
987
993
  conf[:AT_EXIT].each{|hook| hook.call}
994
+
988
995
  context.io.save_history if save_history
996
+ Kernel.exit if forced_exit
989
997
  end
990
998
  end
991
999
 
@@ -1048,7 +1056,7 @@ module IRB
1048
1056
  return read_input(prompt) if @context.io.respond_to?(:check_termination)
1049
1057
 
1050
1058
  # nomultiline
1051
- code = ''
1059
+ code = +''
1052
1060
  line_offset = 0
1053
1061
  loop do
1054
1062
  line = read_input(prompt)
@@ -1074,16 +1082,17 @@ module IRB
1074
1082
  loop do
1075
1083
  code = readmultiline
1076
1084
  break unless code
1077
-
1078
- if code != "\n"
1079
- yield build_statement(code), @line_no
1080
- end
1085
+ yield build_statement(code), @line_no
1081
1086
  @line_no += code.count("\n")
1082
1087
  rescue RubyLex::TerminateLineInput
1083
1088
  end
1084
1089
  end
1085
1090
 
1086
1091
  def build_statement(code)
1092
+ if code.match?(/\A\n*\z/)
1093
+ return Statement::EmptyInput.new
1094
+ end
1095
+
1087
1096
  code.force_encoding(@context.io.encoding)
1088
1097
  command_or_alias, arg = code.split(/\s/, 2)
1089
1098
  # Transform a non-identifier alias (@, $) or keywords (next, break)
@@ -1129,7 +1138,6 @@ module IRB
1129
1138
  end
1130
1139
  if @context.io.respond_to?(:dynamic_prompt)
1131
1140
  @context.io.dynamic_prompt do |lines|
1132
- lines << '' if lines.empty?
1133
1141
  tokens = RubyLex.ripper_lex_without_warning(lines.map{ |l| l + "\n" }.join, local_variables: @context.local_variables)
1134
1142
  line_results = IRB::NestingParser.parse_by_line(tokens)
1135
1143
  tokens_until_line = []
@@ -1227,7 +1235,7 @@ module IRB
1227
1235
  lines.map{ |l| l + "\n" }.join
1228
1236
  }
1229
1237
  # The "<top (required)>" in "(irb)" may be the top level of IRB so imitate the main object.
1230
- message = message.gsub(/\(irb\):(?<num>\d+):in `<(?<frame>top \(required\))>'/) { "(irb):#{$~[:num]}:in `<main>'" }
1238
+ message = message.gsub(/\(irb\):(?<num>\d+):in (?<open_quote>[`'])<(?<frame>top \(required\))>'/) { "(irb):#{$~[:num]}:in #{$~[:open_quote]}<main>'" }
1231
1239
  puts message
1232
1240
  puts 'Maybe IRB bug!' if irb_bug
1233
1241
  rescue Exception => handler_exc
@@ -1261,12 +1269,11 @@ module IRB
1261
1269
  # Used by the irb command +irb_load+, see IRB@IRB+Sessions for more
1262
1270
  # information.
1263
1271
  def suspend_workspace(workspace)
1264
- @context.workspace, back_workspace = workspace, @context.workspace
1265
- begin
1266
- yield back_workspace
1267
- ensure
1268
- @context.workspace = back_workspace
1269
- end
1272
+ current_workspace = @context.workspace
1273
+ @context.replace_workspace(workspace)
1274
+ yield
1275
+ ensure
1276
+ @context.replace_workspace current_workspace
1270
1277
  end
1271
1278
 
1272
1279
  # Evaluates the given block using the given +input_method+ as the
@@ -1526,7 +1533,7 @@ class Binding
1526
1533
 
1527
1534
  if debugger_irb
1528
1535
  # If we're already in a debugger session, set the workspace and irb_path for the original IRB instance
1529
- debugger_irb.context.workspace = workspace
1536
+ debugger_irb.context.replace_workspace(workspace)
1530
1537
  debugger_irb.context.irb_path = irb_path
1531
1538
  # If we've started a debugger session and hit another binding.irb, we don't want to start an IRB session
1532
1539
  # instead, we want to resume the irb:rdbg session.
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.11.2
4
+ version: 1.12.0
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-02-07 00:00:00.000000000 Z
12
+ date: 2024-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: reline
@@ -60,34 +60,36 @@ files:
60
60
  - exe/irb
61
61
  - irb.gemspec
62
62
  - lib/irb.rb
63
- - lib/irb/cmd/backtrace.rb
64
- - lib/irb/cmd/break.rb
65
- - lib/irb/cmd/catch.rb
66
- - lib/irb/cmd/chws.rb
67
- - lib/irb/cmd/continue.rb
68
- - lib/irb/cmd/debug.rb
69
- - lib/irb/cmd/delete.rb
70
- - lib/irb/cmd/edit.rb
71
- - lib/irb/cmd/exit.rb
72
- - lib/irb/cmd/finish.rb
73
- - lib/irb/cmd/help.rb
74
- - lib/irb/cmd/history.rb
75
- - lib/irb/cmd/info.rb
76
- - lib/irb/cmd/irb_info.rb
77
- - lib/irb/cmd/load.rb
78
- - lib/irb/cmd/ls.rb
79
- - lib/irb/cmd/measure.rb
80
- - lib/irb/cmd/next.rb
81
63
  - lib/irb/cmd/nop.rb
82
- - lib/irb/cmd/pushws.rb
83
- - lib/irb/cmd/show_cmds.rb
84
- - lib/irb/cmd/show_doc.rb
85
- - lib/irb/cmd/show_source.rb
86
- - lib/irb/cmd/step.rb
87
- - lib/irb/cmd/subirb.rb
88
- - lib/irb/cmd/whereami.rb
89
64
  - lib/irb/color.rb
90
65
  - lib/irb/color_printer.rb
66
+ - lib/irb/command.rb
67
+ - lib/irb/command/backtrace.rb
68
+ - lib/irb/command/base.rb
69
+ - lib/irb/command/break.rb
70
+ - lib/irb/command/catch.rb
71
+ - lib/irb/command/chws.rb
72
+ - lib/irb/command/continue.rb
73
+ - lib/irb/command/debug.rb
74
+ - lib/irb/command/delete.rb
75
+ - lib/irb/command/edit.rb
76
+ - lib/irb/command/exit.rb
77
+ - lib/irb/command/finish.rb
78
+ - lib/irb/command/force_exit.rb
79
+ - lib/irb/command/help.rb
80
+ - lib/irb/command/history.rb
81
+ - lib/irb/command/info.rb
82
+ - lib/irb/command/irb_info.rb
83
+ - lib/irb/command/load.rb
84
+ - lib/irb/command/ls.rb
85
+ - lib/irb/command/measure.rb
86
+ - lib/irb/command/next.rb
87
+ - lib/irb/command/pushws.rb
88
+ - lib/irb/command/show_doc.rb
89
+ - lib/irb/command/show_source.rb
90
+ - lib/irb/command/step.rb
91
+ - lib/irb/command/subirb.rb
92
+ - lib/irb/command/whereami.rb
91
93
  - lib/irb/completion.rb
92
94
  - lib/irb/context.rb
93
95
  - lib/irb/debug.rb
@@ -100,7 +102,6 @@ files:
100
102
  - lib/irb/ext/tracer.rb
101
103
  - lib/irb/ext/use-loader.rb
102
104
  - lib/irb/ext/workspaces.rb
103
- - lib/irb/extend-command.rb
104
105
  - lib/irb/frame.rb
105
106
  - lib/irb/help.rb
106
107
  - lib/irb/history.rb
@@ -149,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
150
  - !ruby/object:Gem::Version
150
151
  version: '0'
151
152
  requirements: []
152
- rubygems_version: 3.5.4
153
+ rubygems_version: 3.5.1
153
154
  signing_key:
154
155
  specification_version: 4
155
156
  summary: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
data/lib/irb/cmd/edit.rb DELETED
@@ -1,60 +0,0 @@
1
- require 'shellwords'
2
- require_relative "nop"
3
- require_relative "../source_finder"
4
-
5
- module IRB
6
- # :stopdoc:
7
-
8
- module ExtendCommand
9
- class Edit < Nop
10
- category "Misc"
11
- description 'Open a file with the editor command defined with `ENV["VISUAL"]` or `ENV["EDITOR"]`.'
12
-
13
- class << self
14
- def transform_args(args)
15
- # Return a string literal as is for backward compatibility
16
- if args.nil? || args.empty? || string_literal?(args)
17
- args
18
- else # Otherwise, consider the input as a String for convenience
19
- args.strip.dump
20
- end
21
- end
22
- end
23
-
24
- def execute(*args)
25
- path = args.first
26
-
27
- if path.nil? && (irb_path = @irb_context.irb_path)
28
- path = irb_path
29
- end
30
-
31
- if !File.exist?(path)
32
- source =
33
- begin
34
- SourceFinder.new(@irb_context).find_source(path)
35
- rescue NameError
36
- # if user enters a path that doesn't exist, it'll cause NameError when passed here because find_source would try to evaluate it as well
37
- # in this case, we should just ignore the error
38
- end
39
-
40
- if source
41
- path = source.file
42
- else
43
- puts "Can not find file: #{path}"
44
- return
45
- end
46
- end
47
-
48
- if editor = (ENV['VISUAL'] || ENV['EDITOR'])
49
- puts "command: '#{editor}'"
50
- puts " path: #{path}"
51
- system(*Shellwords.split(editor), path)
52
- else
53
- puts "Can not find editor setting: ENV['VISUAL'] or ENV['EDITOR']"
54
- end
55
- end
56
- end
57
- end
58
-
59
- # :startdoc:
60
- end
data/lib/irb/cmd/help.rb DELETED
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "show_doc"
4
-
5
- module IRB
6
- module ExtendCommand
7
- class Help < ShowDoc
8
- category "Context"
9
- description "[DEPRECATED] Enter the mode to look up RI documents."
10
-
11
- DEPRECATION_MESSAGE = <<~MSG
12
- [Deprecation] The `help` command will be repurposed to display command help in the future.
13
- For RI document lookup, please use the `show_doc` command instead.
14
- For command help, please use `show_cmds` for now.
15
- MSG
16
-
17
- def execute(*names)
18
- warn DEPRECATION_MESSAGE
19
- super
20
- end
21
- end
22
- end
23
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "stringio"
4
- require_relative "nop"
5
- require_relative "../pager"
6
-
7
- module IRB
8
- # :stopdoc:
9
-
10
- module ExtendCommand
11
- class ShowCmds < Nop
12
- category "IRB"
13
- description "List all available commands and their description."
14
-
15
- def execute(*args)
16
- commands_info = IRB::ExtendCommandBundle.all_commands_info
17
- commands_grouped_by_categories = commands_info.group_by { |cmd| cmd[:category] }
18
-
19
- user_aliases = irb_context.instance_variable_get(:@user_aliases)
20
-
21
- commands_grouped_by_categories["Aliases"] = user_aliases.map do |alias_name, target|
22
- { display_name: alias_name, description: "Alias for `#{target}`" }
23
- end
24
-
25
- if irb_context.with_debugger
26
- # Remove the original "Debugging" category
27
- commands_grouped_by_categories.delete("Debugging")
28
- # Remove the `help` command as it's delegated to the debugger
29
- commands_grouped_by_categories["Context"].delete_if { |cmd| cmd[:display_name] == :help }
30
- # Add an empty "Debugging (from debug.gem)" category at the end
31
- commands_grouped_by_categories["Debugging (from debug.gem)"] = []
32
- end
33
-
34
- longest_cmd_name_length = commands_info.map { |c| c[:display_name].length }.max
35
-
36
- output = StringIO.new
37
-
38
- commands_grouped_by_categories.each do |category, cmds|
39
- output.puts Color.colorize(category, [:BOLD])
40
-
41
- cmds.each do |cmd|
42
- output.puts " #{cmd[:display_name].to_s.ljust(longest_cmd_name_length)} #{cmd[:description]}"
43
- end
44
-
45
- output.puts
46
- end
47
-
48
- # Append the debugger help at the end
49
- if irb_context.with_debugger
50
- output.puts DEBUGGER__.help
51
- end
52
-
53
- Pager.page_content(output.string)
54
- end
55
- end
56
- end
57
-
58
- # :startdoc:
59
- end