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
@@ -0,0 +1,265 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "command"
|
4
|
+
require_relative "command/internal_helpers"
|
5
|
+
require_relative "command/backtrace"
|
6
|
+
require_relative "command/break"
|
7
|
+
require_relative "command/catch"
|
8
|
+
require_relative "command/chws"
|
9
|
+
require_relative "command/context"
|
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"
|
16
|
+
require_relative "command/finish"
|
17
|
+
require_relative "command/force_exit"
|
18
|
+
require_relative "command/help"
|
19
|
+
require_relative "command/history"
|
20
|
+
require_relative "command/info"
|
21
|
+
require_relative "command/irb_info"
|
22
|
+
require_relative "command/load"
|
23
|
+
require_relative "command/ls"
|
24
|
+
require_relative "command/measure"
|
25
|
+
require_relative "command/next"
|
26
|
+
require_relative "command/pushws"
|
27
|
+
require_relative "command/show_doc"
|
28
|
+
require_relative "command/show_source"
|
29
|
+
require_relative "command/step"
|
30
|
+
require_relative "command/subirb"
|
31
|
+
require_relative "command/whereami"
|
32
|
+
|
33
|
+
module IRB
|
34
|
+
module Command
|
35
|
+
NO_OVERRIDE = 0
|
36
|
+
OVERRIDE_PRIVATE_ONLY = 0x01
|
37
|
+
OVERRIDE_ALL = 0x02
|
38
|
+
|
39
|
+
class << self
|
40
|
+
# This API is for IRB's internal use only and may change at any time.
|
41
|
+
# Please do NOT use it.
|
42
|
+
def _register_with_aliases(name, command_class, *aliases)
|
43
|
+
@commands[name.to_sym] = [command_class, aliases]
|
44
|
+
end
|
45
|
+
|
46
|
+
def all_commands_info
|
47
|
+
user_aliases = IRB.CurrentContext.command_aliases.each_with_object({}) do |(alias_name, target), result|
|
48
|
+
result[target] ||= []
|
49
|
+
result[target] << alias_name
|
50
|
+
end
|
51
|
+
|
52
|
+
commands.map do |command_name, (command_class, aliases)|
|
53
|
+
aliases = aliases.map { |a| a.first }
|
54
|
+
|
55
|
+
if additional_aliases = user_aliases[command_name]
|
56
|
+
aliases += additional_aliases
|
57
|
+
end
|
58
|
+
|
59
|
+
display_name = aliases.shift || command_name
|
60
|
+
{
|
61
|
+
display_name: display_name,
|
62
|
+
description: command_class.description,
|
63
|
+
category: command_class.category
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def command_override_policies
|
69
|
+
@@command_override_policies ||= commands.flat_map do |cmd_name, (cmd_class, aliases)|
|
70
|
+
[[cmd_name, OVERRIDE_ALL]] + aliases
|
71
|
+
end.to_h
|
72
|
+
end
|
73
|
+
|
74
|
+
def execute_as_command?(name, public_method:, private_method:)
|
75
|
+
case command_override_policies[name]
|
76
|
+
when OVERRIDE_ALL
|
77
|
+
true
|
78
|
+
when OVERRIDE_PRIVATE_ONLY
|
79
|
+
!public_method
|
80
|
+
when NO_OVERRIDE
|
81
|
+
!public_method && !private_method
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def command_names
|
86
|
+
command_override_policies.keys.map(&:to_s)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Convert a command name to its implementation class if such command exists
|
90
|
+
def load_command(command)
|
91
|
+
command = command.to_sym
|
92
|
+
commands.each do |command_name, (command_class, aliases)|
|
93
|
+
if command_name == command || aliases.any? { |alias_name, _| alias_name == command }
|
94
|
+
return command_class
|
95
|
+
end
|
96
|
+
end
|
97
|
+
nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
_register_with_aliases(:irb_context, Command::Context,
|
102
|
+
[:context, NO_OVERRIDE]
|
103
|
+
)
|
104
|
+
|
105
|
+
_register_with_aliases(:irb_exit, Command::Exit,
|
106
|
+
[:exit, OVERRIDE_PRIVATE_ONLY],
|
107
|
+
[:quit, OVERRIDE_PRIVATE_ONLY],
|
108
|
+
[:irb_quit, OVERRIDE_PRIVATE_ONLY]
|
109
|
+
)
|
110
|
+
|
111
|
+
_register_with_aliases(:irb_exit!, Command::ForceExit,
|
112
|
+
[:exit!, OVERRIDE_PRIVATE_ONLY]
|
113
|
+
)
|
114
|
+
|
115
|
+
_register_with_aliases(:irb_current_working_workspace, Command::CurrentWorkingWorkspace,
|
116
|
+
[:cwws, NO_OVERRIDE],
|
117
|
+
[:pwws, NO_OVERRIDE],
|
118
|
+
[:irb_print_working_workspace, OVERRIDE_ALL],
|
119
|
+
[:irb_cwws, OVERRIDE_ALL],
|
120
|
+
[:irb_pwws, OVERRIDE_ALL],
|
121
|
+
[:irb_current_working_binding, OVERRIDE_ALL],
|
122
|
+
[:irb_print_working_binding, OVERRIDE_ALL],
|
123
|
+
[:irb_cwb, OVERRIDE_ALL],
|
124
|
+
[:irb_pwb, OVERRIDE_ALL],
|
125
|
+
)
|
126
|
+
|
127
|
+
_register_with_aliases(:irb_change_workspace, Command::ChangeWorkspace,
|
128
|
+
[:chws, NO_OVERRIDE],
|
129
|
+
[:cws, NO_OVERRIDE],
|
130
|
+
[:irb_chws, OVERRIDE_ALL],
|
131
|
+
[:irb_cws, OVERRIDE_ALL],
|
132
|
+
[:irb_change_binding, OVERRIDE_ALL],
|
133
|
+
[:irb_cb, OVERRIDE_ALL],
|
134
|
+
[:cb, NO_OVERRIDE],
|
135
|
+
)
|
136
|
+
|
137
|
+
_register_with_aliases(:irb_workspaces, Command::Workspaces,
|
138
|
+
[:workspaces, NO_OVERRIDE],
|
139
|
+
[:irb_bindings, OVERRIDE_ALL],
|
140
|
+
[:bindings, NO_OVERRIDE],
|
141
|
+
)
|
142
|
+
|
143
|
+
_register_with_aliases(:irb_push_workspace, Command::PushWorkspace,
|
144
|
+
[:pushws, NO_OVERRIDE],
|
145
|
+
[:irb_pushws, OVERRIDE_ALL],
|
146
|
+
[:irb_push_binding, OVERRIDE_ALL],
|
147
|
+
[:irb_pushb, OVERRIDE_ALL],
|
148
|
+
[:pushb, NO_OVERRIDE],
|
149
|
+
)
|
150
|
+
|
151
|
+
_register_with_aliases(:irb_pop_workspace, Command::PopWorkspace,
|
152
|
+
[:popws, NO_OVERRIDE],
|
153
|
+
[:irb_popws, OVERRIDE_ALL],
|
154
|
+
[:irb_pop_binding, OVERRIDE_ALL],
|
155
|
+
[:irb_popb, OVERRIDE_ALL],
|
156
|
+
[:popb, NO_OVERRIDE],
|
157
|
+
)
|
158
|
+
|
159
|
+
_register_with_aliases(:irb_load, Command::Load)
|
160
|
+
_register_with_aliases(:irb_require, Command::Require)
|
161
|
+
_register_with_aliases(:irb_source, Command::Source,
|
162
|
+
[:source, NO_OVERRIDE]
|
163
|
+
)
|
164
|
+
|
165
|
+
_register_with_aliases(:irb, Command::IrbCommand)
|
166
|
+
_register_with_aliases(:irb_jobs, Command::Jobs,
|
167
|
+
[:jobs, NO_OVERRIDE]
|
168
|
+
)
|
169
|
+
_register_with_aliases(:irb_fg, Command::Foreground,
|
170
|
+
[:fg, NO_OVERRIDE]
|
171
|
+
)
|
172
|
+
_register_with_aliases(:irb_kill, Command::Kill,
|
173
|
+
[:kill, OVERRIDE_PRIVATE_ONLY]
|
174
|
+
)
|
175
|
+
|
176
|
+
_register_with_aliases(:irb_debug, Command::Debug,
|
177
|
+
[:debug, NO_OVERRIDE]
|
178
|
+
)
|
179
|
+
_register_with_aliases(:irb_edit, Command::Edit,
|
180
|
+
[:edit, NO_OVERRIDE]
|
181
|
+
)
|
182
|
+
|
183
|
+
_register_with_aliases(:irb_break, Command::Break)
|
184
|
+
_register_with_aliases(:irb_catch, Command::Catch)
|
185
|
+
_register_with_aliases(:irb_next, Command::Next)
|
186
|
+
_register_with_aliases(:irb_delete, Command::Delete,
|
187
|
+
[:delete, NO_OVERRIDE]
|
188
|
+
)
|
189
|
+
|
190
|
+
_register_with_aliases(:irb_step, Command::Step,
|
191
|
+
[:step, NO_OVERRIDE]
|
192
|
+
)
|
193
|
+
_register_with_aliases(:irb_continue, Command::Continue,
|
194
|
+
[:continue, NO_OVERRIDE]
|
195
|
+
)
|
196
|
+
_register_with_aliases(:irb_finish, Command::Finish,
|
197
|
+
[:finish, NO_OVERRIDE]
|
198
|
+
)
|
199
|
+
_register_with_aliases(:irb_backtrace, Command::Backtrace,
|
200
|
+
[:backtrace, NO_OVERRIDE],
|
201
|
+
[:bt, NO_OVERRIDE]
|
202
|
+
)
|
203
|
+
|
204
|
+
_register_with_aliases(:irb_debug_info, Command::Info,
|
205
|
+
[:info, NO_OVERRIDE]
|
206
|
+
)
|
207
|
+
|
208
|
+
_register_with_aliases(:irb_help, Command::Help,
|
209
|
+
[:help, NO_OVERRIDE],
|
210
|
+
[:show_cmds, NO_OVERRIDE]
|
211
|
+
)
|
212
|
+
|
213
|
+
_register_with_aliases(:irb_show_doc, Command::ShowDoc,
|
214
|
+
[:show_doc, NO_OVERRIDE]
|
215
|
+
)
|
216
|
+
|
217
|
+
_register_with_aliases(:irb_info, Command::IrbInfo)
|
218
|
+
|
219
|
+
_register_with_aliases(:irb_ls, Command::Ls,
|
220
|
+
[:ls, NO_OVERRIDE]
|
221
|
+
)
|
222
|
+
|
223
|
+
_register_with_aliases(:irb_measure, Command::Measure,
|
224
|
+
[:measure, NO_OVERRIDE]
|
225
|
+
)
|
226
|
+
|
227
|
+
_register_with_aliases(:irb_show_source, Command::ShowSource,
|
228
|
+
[:show_source, NO_OVERRIDE]
|
229
|
+
)
|
230
|
+
|
231
|
+
_register_with_aliases(:irb_whereami, Command::Whereami,
|
232
|
+
[:whereami, NO_OVERRIDE]
|
233
|
+
)
|
234
|
+
|
235
|
+
_register_with_aliases(:irb_history, Command::History,
|
236
|
+
[:history, NO_OVERRIDE],
|
237
|
+
[:hist, NO_OVERRIDE]
|
238
|
+
)
|
239
|
+
|
240
|
+
_register_with_aliases(:irb_disable_irb, Command::DisableIrb,
|
241
|
+
[:disable_irb, NO_OVERRIDE]
|
242
|
+
)
|
243
|
+
end
|
244
|
+
|
245
|
+
ExtendCommand = Command
|
246
|
+
|
247
|
+
# For backward compatibility, we need to keep this module:
|
248
|
+
# - As a container of helper methods
|
249
|
+
# - As a place to register commands with the deprecated def_extend_command method
|
250
|
+
module ExtendCommandBundle
|
251
|
+
# For backward compatibility
|
252
|
+
NO_OVERRIDE = Command::NO_OVERRIDE
|
253
|
+
OVERRIDE_PRIVATE_ONLY = Command::OVERRIDE_PRIVATE_ONLY
|
254
|
+
OVERRIDE_ALL = Command::OVERRIDE_ALL
|
255
|
+
|
256
|
+
# Deprecated. Doesn't have any effect.
|
257
|
+
@EXTEND_COMMANDS = []
|
258
|
+
|
259
|
+
# Drepcated. Use Command.regiser instead.
|
260
|
+
def self.def_extend_command(cmd_name, cmd_class, _, *aliases)
|
261
|
+
Command._register_with_aliases(cmd_name, cmd_class, *aliases)
|
262
|
+
Command.class_variable_set(:@@command_override_policies, nil)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
data/lib/irb/easter-egg.rb
CHANGED
@@ -98,18 +98,26 @@ module IRB
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
+
private def easter_egg_logo(type)
|
102
|
+
@easter_egg_logos ||= File.read(File.join(__dir__, 'ruby_logo.aa'), encoding: 'UTF-8:UTF-8')
|
103
|
+
.split(/TYPE: ([A-Z]+)\n/)[1..]
|
104
|
+
.each_slice(2)
|
105
|
+
.to_h
|
106
|
+
@easter_egg_logos[type.to_s.upcase]
|
107
|
+
end
|
108
|
+
|
101
109
|
private def easter_egg(type = nil)
|
102
110
|
type ||= [:logo, :dancing].sample
|
103
111
|
case type
|
104
112
|
when :logo
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
IO.copy_stream(f, io)
|
109
|
-
end
|
113
|
+
require "rdoc"
|
114
|
+
RDoc::RI::Driver.new.page do |io|
|
115
|
+
io.write easter_egg_logo(:large)
|
110
116
|
end
|
111
117
|
when :dancing
|
112
|
-
|
118
|
+
STDOUT.cooked do
|
119
|
+
interrupted = false
|
120
|
+
prev_trap = trap("SIGINT") { interrupted = true }
|
113
121
|
canvas = Canvas.new(Reline.get_screen_size)
|
114
122
|
Reline::IOGate.set_winch_handler do
|
115
123
|
canvas = Canvas.new(Reline.get_screen_size)
|
@@ -125,10 +133,12 @@ module IRB
|
|
125
133
|
buff[0, 20] = "\e[0mPress Ctrl+C to stop\e[31m\e[1m"
|
126
134
|
print "\e[H" + buff
|
127
135
|
sleep 0.05
|
136
|
+
break if interrupted
|
128
137
|
end
|
129
138
|
rescue Interrupt
|
130
139
|
ensure
|
131
140
|
print "\e[0m\e[?1049l"
|
141
|
+
trap("SIGINT", prev_trap)
|
132
142
|
end
|
133
143
|
end
|
134
144
|
end
|
data/lib/irb/ext/change-ws.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# irb/ext/cb.rb -
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
@@ -12,7 +12,7 @@ module IRB # :nodoc:
|
|
12
12
|
if defined? @home_workspace
|
13
13
|
@home_workspace
|
14
14
|
else
|
15
|
-
@home_workspace =
|
15
|
+
@home_workspace = workspace
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -25,15 +25,13 @@ module IRB # :nodoc:
|
|
25
25
|
# See IRB::WorkSpace.new for more information.
|
26
26
|
def change_workspace(*_main)
|
27
27
|
if _main.empty?
|
28
|
-
|
28
|
+
replace_workspace(home_workspace)
|
29
29
|
return main
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
main.extend ExtendCommandBundle
|
36
|
-
end
|
32
|
+
workspace = WorkSpace.new(_main[0])
|
33
|
+
replace_workspace(workspace)
|
34
|
+
workspace.load_helper_methods_to_main
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# history.rb -
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
@@ -18,7 +18,7 @@ module IRB # :nodoc:
|
|
18
18
|
|
19
19
|
if defined?(@eval_history) && @eval_history
|
20
20
|
@eval_history_values.push @line_no, @last_value
|
21
|
-
|
21
|
+
workspace.evaluate "__ = IRB.CurrentContext.instance_eval{@eval_history_values}"
|
22
22
|
end
|
23
23
|
|
24
24
|
@last_value
|
@@ -40,16 +40,16 @@ module IRB # :nodoc:
|
|
40
40
|
#
|
41
41
|
# If +no+ is +nil+, execution result history isn't used (default).
|
42
42
|
#
|
43
|
-
#
|
44
|
-
# IRB::
|
43
|
+
# EvalHistory values are available via <code>__</code> variable, see
|
44
|
+
# IRB::EvalHistory.
|
45
45
|
def eval_history=(no)
|
46
46
|
if no
|
47
47
|
if defined?(@eval_history) && @eval_history
|
48
48
|
@eval_history_values.size(no)
|
49
49
|
else
|
50
|
-
@eval_history_values =
|
50
|
+
@eval_history_values = EvalHistory.new(no)
|
51
51
|
IRB.conf[:__TMP__EHV__] = @eval_history_values
|
52
|
-
|
52
|
+
workspace.evaluate("__ = IRB.conf[:__TMP__EHV__]")
|
53
53
|
IRB.conf.delete(:__TMP_EHV__)
|
54
54
|
end
|
55
55
|
else
|
@@ -89,7 +89,7 @@ module IRB # :nodoc:
|
|
89
89
|
# __[1]
|
90
90
|
# # => 10
|
91
91
|
#
|
92
|
-
class
|
92
|
+
class EvalHistory
|
93
93
|
|
94
94
|
def initialize(size = 16) # :nodoc:
|
95
95
|
@size = size
|
data/lib/irb/ext/loader.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# loader.rb -
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
@@ -98,13 +98,13 @@ module IRB # :nodoc:
|
|
98
98
|
|
99
99
|
def old # :nodoc:
|
100
100
|
back_io = @io
|
101
|
-
back_path =
|
101
|
+
back_path = irb_path
|
102
102
|
back_name = @irb_name
|
103
103
|
back_scanner = @irb.scanner
|
104
104
|
begin
|
105
105
|
@io = FileInputMethod.new(path)
|
106
106
|
@irb_name = File.basename(path)
|
107
|
-
|
107
|
+
self.irb_path = path
|
108
108
|
@irb.signal_status(:IN_LOAD) do
|
109
109
|
if back_io.kind_of?(FileInputMethod)
|
110
110
|
@irb.eval_input
|
@@ -119,7 +119,7 @@ module IRB # :nodoc:
|
|
119
119
|
ensure
|
120
120
|
@io = back_io
|
121
121
|
@irb_name = back_name
|
122
|
-
|
122
|
+
self.irb_path = back_path
|
123
123
|
@irb.scanner = back_scanner
|
124
124
|
end
|
125
125
|
end
|
data/lib/irb/ext/multi-irb.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# irb/multi-irb.rb - multiple irb module
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
5
5
|
#
|
6
6
|
|
7
7
|
module IRB
|
8
|
-
class JobManager
|
8
|
+
class JobManager # :nodoc:
|
9
9
|
|
10
10
|
# Creates a new JobManager object
|
11
11
|
def initialize
|
@@ -166,12 +166,12 @@ module IRB
|
|
166
166
|
@JobManager = JobManager.new
|
167
167
|
|
168
168
|
# The current JobManager in the session
|
169
|
-
def IRB.JobManager
|
169
|
+
def IRB.JobManager # :nodoc:
|
170
170
|
@JobManager
|
171
171
|
end
|
172
172
|
|
173
173
|
# The current Context in this session
|
174
|
-
def IRB.CurrentContext
|
174
|
+
def IRB.CurrentContext # :nodoc:
|
175
175
|
IRB.JobManager.irb(Thread.current).context
|
176
176
|
end
|
177
177
|
|
@@ -179,7 +179,7 @@ module IRB
|
|
179
179
|
#
|
180
180
|
# The optional +file+ argument is given to Context.new, along with the
|
181
181
|
# workspace created with the remaining arguments, see WorkSpace.new
|
182
|
-
def IRB.irb(file = nil, *main)
|
182
|
+
def IRB.irb(file = nil, *main) # :nodoc:
|
183
183
|
workspace = WorkSpace.new(*main)
|
184
184
|
parent_thread = Thread.current
|
185
185
|
Thread.start do
|
data/lib/irb/ext/tracer.rb
CHANGED
@@ -1,78 +1,39 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# irb/lib/tracer.rb -
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
5
5
|
#
|
6
|
-
|
6
|
+
# Loading the gem "tracer" will cause it to extend IRB commands with:
|
7
|
+
# https://github.com/ruby/tracer/blob/v0.2.2/lib/tracer/irb.rb
|
7
8
|
begin
|
8
9
|
require "tracer"
|
9
10
|
rescue LoadError
|
10
11
|
$stderr.puts "Tracer extension of IRB is enabled but tracer gem wasn't found."
|
11
|
-
module IRB
|
12
|
-
class Context
|
13
|
-
def use_tracer=(opt)
|
14
|
-
# do nothing
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
12
|
return # This is about to disable loading below
|
19
13
|
end
|
20
14
|
|
21
15
|
module IRB
|
16
|
+
class CallTracer < ::CallTracer
|
17
|
+
IRB_DIR = File.expand_path('../..', __dir__)
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
Tracer.verbose = false
|
26
|
-
Tracer.add_filter {
|
27
|
-
|event, file, line, id, binding, *rests|
|
28
|
-
/^#{Regexp.quote(@CONF[:IRB_LIB_PATH])}/ !~ file and
|
29
|
-
File::basename(file) != "irb.rb"
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
class Context
|
34
|
-
# Whether Tracer is used when evaluating statements in this context.
|
35
|
-
#
|
36
|
-
# See +lib/tracer.rb+ for more information.
|
37
|
-
attr_reader :use_tracer
|
38
|
-
alias use_tracer? use_tracer
|
39
|
-
|
40
|
-
# Sets whether or not to use the Tracer library when evaluating statements
|
41
|
-
# in this context.
|
42
|
-
#
|
43
|
-
# See +lib/tracer.rb+ for more information.
|
44
|
-
def use_tracer=(opt)
|
45
|
-
if opt
|
46
|
-
Tracer.set_get_line_procs(@irb_path) {
|
47
|
-
|line_no, *rests|
|
48
|
-
@io.line(line_no)
|
49
|
-
}
|
50
|
-
elsif !opt && @use_tracer
|
51
|
-
Tracer.off
|
52
|
-
end
|
53
|
-
@use_tracer=opt
|
19
|
+
def skip?(tp)
|
20
|
+
super || tp.path.match?(IRB_DIR) || tp.path.match?('<internal:prelude>')
|
54
21
|
end
|
55
22
|
end
|
56
|
-
|
57
23
|
class WorkSpace
|
58
24
|
alias __evaluate__ evaluate
|
59
25
|
# Evaluate the context of this workspace and use the Tracer library to
|
60
26
|
# output the exact lines of code are being executed in chronological order.
|
61
27
|
#
|
62
|
-
# See
|
63
|
-
def evaluate(
|
64
|
-
if
|
65
|
-
|
66
|
-
begin
|
28
|
+
# See https://github.com/ruby/tracer for more information.
|
29
|
+
def evaluate(statements, file = __FILE__, line = __LINE__)
|
30
|
+
if IRB.conf[:USE_TRACER] == true
|
31
|
+
CallTracer.new(colorize: Color.colorable?).start do
|
67
32
|
__evaluate__(statements, file, line)
|
68
|
-
ensure
|
69
|
-
Tracer.off
|
70
33
|
end
|
71
34
|
else
|
72
|
-
__evaluate__(statements, file
|
35
|
+
__evaluate__(statements, file, line)
|
73
36
|
end
|
74
37
|
end
|
75
38
|
end
|
76
|
-
|
77
|
-
IRB.initialize_tracer
|
78
39
|
end
|
data/lib/irb/ext/use-loader.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# use-loader.rb -
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
5
5
|
#
|
6
6
|
|
7
|
-
require_relative "../
|
7
|
+
require_relative "../command/load"
|
8
8
|
require_relative "loader"
|
9
9
|
|
10
10
|
class Object
|
@@ -17,12 +17,12 @@ module IRB
|
|
17
17
|
remove_method :irb_load if method_defined?(:irb_load)
|
18
18
|
# Loads the given file similarly to Kernel#load, see IrbLoader#irb_load
|
19
19
|
def irb_load(*opts, &b)
|
20
|
-
|
20
|
+
Command::Load.execute(irb_context, *opts, &b)
|
21
21
|
end
|
22
22
|
remove_method :irb_require if method_defined?(:irb_require)
|
23
23
|
# Loads the given file similarly to Kernel#require
|
24
24
|
def irb_require(*opts, &b)
|
25
|
-
|
25
|
+
Command::Require.execute(irb_context, *opts, &b)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -49,14 +49,12 @@ module IRB
|
|
49
49
|
if IRB.conf[:USE_LOADER] != opt
|
50
50
|
IRB.conf[:USE_LOADER] = opt
|
51
51
|
if opt
|
52
|
-
|
53
|
-
end
|
54
|
-
(class<<@workspace.main;self;end).instance_eval {
|
52
|
+
(class<<workspace.main;self;end).instance_eval {
|
55
53
|
alias_method :load, :irb_load
|
56
54
|
alias_method :require, :irb_require
|
57
55
|
}
|
58
56
|
else
|
59
|
-
(class
|
57
|
+
(class<<workspace.main;self;end).instance_eval {
|
60
58
|
alias_method :load, :__original__load__IRB_use_loader__
|
61
59
|
alias_method :require, :__original__require__IRB_use_loader__
|
62
60
|
}
|
data/lib/irb/ext/workspaces.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# push-ws.rb -
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
@@ -6,21 +6,6 @@
|
|
6
6
|
|
7
7
|
module IRB # :nodoc:
|
8
8
|
class Context
|
9
|
-
|
10
|
-
# Size of the current WorkSpace stack
|
11
|
-
def irb_level
|
12
|
-
workspace_stack.size
|
13
|
-
end
|
14
|
-
|
15
|
-
# WorkSpaces in the current stack
|
16
|
-
def workspaces
|
17
|
-
if defined? @workspaces
|
18
|
-
@workspaces
|
19
|
-
else
|
20
|
-
@workspaces = []
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
9
|
# Creates a new workspace with the given object or binding, and appends it
|
25
10
|
# onto the current #workspaces stack.
|
26
11
|
#
|
@@ -28,20 +13,15 @@ module IRB # :nodoc:
|
|
28
13
|
# information.
|
29
14
|
def push_workspace(*_main)
|
30
15
|
if _main.empty?
|
31
|
-
if
|
32
|
-
|
33
|
-
|
16
|
+
if @workspace_stack.size > 1
|
17
|
+
# swap the top two workspaces
|
18
|
+
previous_workspace, current_workspace = @workspace_stack.pop(2)
|
19
|
+
@workspace_stack.push current_workspace, previous_workspace
|
34
20
|
end
|
35
|
-
|
36
|
-
|
37
|
-
@
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
workspaces.push @workspace
|
42
|
-
@workspace = WorkSpace.new(@workspace.binding, _main[0])
|
43
|
-
if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
|
44
|
-
main.extend ExtendCommandBundle
|
21
|
+
else
|
22
|
+
new_workspace = WorkSpace.new(workspace.binding, _main[0])
|
23
|
+
@workspace_stack.push new_workspace
|
24
|
+
new_workspace.load_helper_methods_to_main
|
45
25
|
end
|
46
26
|
end
|
47
27
|
|
@@ -50,11 +30,7 @@ module IRB # :nodoc:
|
|
50
30
|
#
|
51
31
|
# Also, see #push_workspace.
|
52
32
|
def pop_workspace
|
53
|
-
if
|
54
|
-
print "workspace stack empty\n"
|
55
|
-
return
|
56
|
-
end
|
57
|
-
@workspace = workspaces.pop
|
33
|
+
@workspace_stack.pop if @workspace_stack.size > 1
|
58
34
|
end
|
59
35
|
end
|
60
36
|
end
|
data/lib/irb/frame.rb
CHANGED
data/lib/irb/help.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# irb/help.rb - print usage module
|
4
4
|
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
|
5
5
|
#
|
6
6
|
|
7
7
|
module IRB
|
8
|
-
# Outputs the irb help message, see IRB@Command+
|
9
|
-
def IRB.print_usage
|
8
|
+
# Outputs the irb help message, see IRB@Command-Line+Options.
|
9
|
+
def IRB.print_usage # :nodoc:
|
10
10
|
lc = IRB.conf[:LC_MESSAGES]
|
11
11
|
path = lc.find("irb/help-message")
|
12
12
|
space_line = false
|