irb 1.1.0 → 1.1.1

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.
@@ -22,7 +22,7 @@ module IRB # :nodoc:
22
22
  def set_last_value(value)
23
23
  _set_last_value(value)
24
24
 
25
- if defined?(@eval_history) && @eval_history
25
+ if @eval_history
26
26
  @eval_history_values.push @line_no, @last_value
27
27
  @workspace.evaluate self, "__ = IRB.CurrentContext.instance_eval{@eval_history_values}"
28
28
  end
@@ -30,13 +30,9 @@ module IRB # :nodoc:
30
30
  @last_value
31
31
  end
32
32
 
33
- remove_method :eval_history= if method_defined?(:eval_history=)
34
- # The command result history limit. This method is not available until
35
- # #eval_history= was called with non-nil value (directly or via
36
- # setting <code>IRB.conf[:EVAL_HISTORY]</code> in <code>.irbrc</code>).
33
+ # The command result history limit.
37
34
  attr_reader :eval_history
38
- # Sets command result history limit. Default value is set from
39
- # <code>IRB.conf[:EVAL_HISTORY]</code>.
35
+ # Sets command result history limit.
40
36
  #
41
37
  # +no+ is an Integer or +nil+.
42
38
  #
@@ -45,9 +41,6 @@ module IRB # :nodoc:
45
41
  # If +no+ is 0, the number of history items is unlimited.
46
42
  #
47
43
  # If +no+ is +nil+, execution result history isn't used (default).
48
- #
49
- # History values are available via <code>__</code> variable, see
50
- # IRB::History.
51
44
  def eval_history=(no)
52
45
  if no
53
46
  if defined?(@eval_history) && @eval_history
@@ -65,51 +58,20 @@ module IRB # :nodoc:
65
58
  end
66
59
  end
67
60
 
68
- # Represents history of results of previously evaluated commands.
69
- #
70
- # Available via <code>__</code> variable, only if <code>IRB.conf[:EVAL_HISTORY]</code>
71
- # or <code>IRB::CurrentContext().eval_history</code> is non-nil integer value
72
- # (by default it is +nil+).
73
- #
74
- # Example (in `irb`):
75
- #
76
- # # Initialize history
77
- # IRB::CurrentContext().eval_history = 10
78
- # # => 10
79
- #
80
- # # Perform some commands...
81
- # 1 + 2
82
- # # => 3
83
- # puts 'x'
84
- # # x
85
- # # => nil
86
- # raise RuntimeError
87
- # # ...error raised
88
- #
89
- # # Inspect history (format is "<item number> <evaluated value>":
90
- # __
91
- # # => 1 10
92
- # # 2 3
93
- # # 3 nil
94
- #
95
- # __[1]
96
- # # => 10
97
- #
98
- class History
99
-
100
- def initialize(size = 16) # :nodoc:
61
+ class History # :nodoc:
62
+
63
+ def initialize(size = 16)
101
64
  @size = size
102
65
  @contents = []
103
66
  end
104
67
 
105
- def size(size) # :nodoc:
68
+ def size(size)
106
69
  if size != 0 && size < @size
107
70
  @contents = @contents[@size - size .. @size]
108
71
  end
109
72
  @size = size
110
73
  end
111
74
 
112
- # Get one item of the content (both positive and negative indexes work).
113
75
  def [](idx)
114
76
  begin
115
77
  if idx >= 0
@@ -122,14 +84,14 @@ module IRB # :nodoc:
122
84
  end
123
85
  end
124
86
 
125
- def push(no, val) # :nodoc:
87
+ def push(no, val)
126
88
  @contents.push [no, val]
127
89
  @contents.shift if @size != 0 && @contents.size > @size
128
90
  end
129
91
 
130
92
  alias real_inspect inspect
131
93
 
132
- def inspect # :nodoc:
94
+ def inspect
133
95
  if @contents.empty?
134
96
  return real_inspect
135
97
  end
@@ -27,7 +27,7 @@ module IRB
27
27
  IRB.conf[:SAVE_HISTORY]
28
28
  end
29
29
 
30
- remove_method :save_history= if method_defined?(:save_history=)
30
+ remove_method :save_history= if respond_to?(:save_history=)
31
31
  # Sets <code>IRB.conf[:SAVE_HISTORY]</code> to the given +val+ and calls
32
32
  # #init_save_history with this context.
33
33
  #
@@ -58,6 +58,8 @@ module IRB
58
58
  end
59
59
 
60
60
  module HistorySavingAbility # :nodoc:
61
+ include Readline
62
+
61
63
  def HistorySavingAbility.extended(obj)
62
64
  IRB.conf[:AT_EXIT].push proc{obj.save_history}
63
65
  obj.load_history
@@ -65,30 +67,18 @@ module IRB
65
67
  end
66
68
 
67
69
  def load_history
68
- return unless self.class.const_defined?(:HISTORY)
69
- history = self.class::HISTORY
70
70
  if history_file = IRB.conf[:HISTORY_FILE]
71
71
  history_file = File.expand_path(history_file)
72
72
  end
73
73
  history_file = IRB.rc_file("_history") unless history_file
74
74
  if File.exist?(history_file)
75
75
  open(history_file) do |f|
76
- f.each { |l|
77
- l = l.chomp
78
- if self.class == ReidlineInputMethod and history.last&.end_with?("\\")
79
- history.last.delete_suffix!("\\")
80
- history.last << "\n" << l
81
- else
82
- history << l
83
- end
84
- }
76
+ f.each {|l| HISTORY << l.chomp}
85
77
  end
86
78
  end
87
79
  end
88
80
 
89
81
  def save_history
90
- return unless self.class.const_defined?(:HISTORY)
91
- history = self.class::HISTORY
92
82
  if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
93
83
  if history_file = IRB.conf[:HISTORY_FILE]
94
84
  history_file = File.expand_path(history_file)
@@ -101,14 +91,12 @@ module IRB
101
91
  File.chmod(0600, history_file)
102
92
  end
103
93
  rescue Errno::ENOENT
104
- rescue Errno::EPERM
105
- return
106
94
  rescue
107
95
  raise
108
96
  end
109
97
 
110
98
  open(history_file, 'w', 0600 ) do |f|
111
- hist = history.map{ |l| l.split("\n").join("\\\n") }
99
+ hist = HISTORY.to_a
112
100
  f.puts(hist[-num..-1] || hist)
113
101
  end
114
102
  end
@@ -20,12 +20,10 @@ end
20
20
 
21
21
  module IRB
22
22
  module ExtendCommandBundle
23
- remove_method :irb_load if method_defined?(:irb_load)
24
23
  # Loads the given file similarly to Kernel#load, see IrbLoader#irb_load
25
24
  def irb_load(*opts, &b)
26
25
  ExtendCommand::Load.execute(irb_context, *opts, &b)
27
26
  end
28
- remove_method :irb_require if method_defined?(:irb_require)
29
27
  # Loads the given file similarly to Kernel#require
30
28
  def irb_require(*opts, &b)
31
29
  ExtendCommand::Require.execute(irb_context, *opts, &b)
@@ -46,7 +44,6 @@ module IRB
46
44
 
47
45
  alias use_loader? use_loader
48
46
 
49
- remove_method :use_loader= if method_defined?(:use_loader=)
50
47
  # Sets IRB.conf[:USE_LOADER]
51
48
  #
52
49
  # See #use_loader for more information.
@@ -46,80 +46,58 @@ module IRB # :nodoc:
46
46
  ]
47
47
 
48
48
  @EXTEND_COMMANDS = [
49
- [
50
- :irb_current_working_workspace, :CurrentWorkingWorkspace, "irb/cmd/chws",
51
- [:irb_print_working_workspace, OVERRIDE_ALL],
52
- [:irb_cwws, OVERRIDE_ALL],
53
- [:irb_pwws, OVERRIDE_ALL],
54
- [:cwws, NO_OVERRIDE],
55
- [:pwws, NO_OVERRIDE],
56
- [:irb_current_working_binding, OVERRIDE_ALL],
57
- [:irb_print_working_binding, OVERRIDE_ALL],
58
- [:irb_cwb, OVERRIDE_ALL],
59
- [:irb_pwb, OVERRIDE_ALL],
60
- ],
61
- [
62
- :irb_change_workspace, :ChangeWorkspace, "irb/cmd/chws",
63
- [:irb_chws, OVERRIDE_ALL],
64
- [:irb_cws, OVERRIDE_ALL],
65
- [:chws, NO_OVERRIDE],
66
- [:cws, NO_OVERRIDE],
67
- [:irb_change_binding, OVERRIDE_ALL],
68
- [:irb_cb, OVERRIDE_ALL],
69
- [:cb, NO_OVERRIDE],
70
- ],
49
+ [:irb_current_working_workspace, :CurrentWorkingWorkspace, "irb/cmd/chws",
50
+ [:irb_print_working_workspace, OVERRIDE_ALL],
51
+ [:irb_cwws, OVERRIDE_ALL],
52
+ [:irb_pwws, OVERRIDE_ALL],
53
+ [:cwws, NO_OVERRIDE],
54
+ [:pwws, NO_OVERRIDE],
55
+ [:irb_current_working_binding, OVERRIDE_ALL],
56
+ [:irb_print_working_binding, OVERRIDE_ALL],
57
+ [:irb_cwb, OVERRIDE_ALL],
58
+ [:irb_pwb, OVERRIDE_ALL],
59
+ ],
60
+ [:irb_change_workspace, :ChangeWorkspace, "irb/cmd/chws",
61
+ [:irb_chws, OVERRIDE_ALL],
62
+ [:irb_cws, OVERRIDE_ALL],
63
+ [:chws, NO_OVERRIDE],
64
+ [:cws, NO_OVERRIDE],
65
+ [:irb_change_binding, OVERRIDE_ALL],
66
+ [:irb_cb, OVERRIDE_ALL],
67
+ [:cb, NO_OVERRIDE]],
71
68
 
72
- [
73
- :irb_workspaces, :Workspaces, "irb/cmd/pushws",
74
- [:workspaces, NO_OVERRIDE],
75
- [:irb_bindings, OVERRIDE_ALL],
76
- [:bindings, NO_OVERRIDE],
77
- ],
78
- [
79
- :irb_push_workspace, :PushWorkspace, "irb/cmd/pushws",
80
- [:irb_pushws, OVERRIDE_ALL],
81
- [:pushws, NO_OVERRIDE],
82
- [:irb_push_binding, OVERRIDE_ALL],
83
- [:irb_pushb, OVERRIDE_ALL],
84
- [:pushb, NO_OVERRIDE],
85
- ],
86
- [
87
- :irb_pop_workspace, :PopWorkspace, "irb/cmd/pushws",
88
- [:irb_popws, OVERRIDE_ALL],
89
- [:popws, NO_OVERRIDE],
90
- [:irb_pop_binding, OVERRIDE_ALL],
91
- [:irb_popb, OVERRIDE_ALL],
92
- [:popb, NO_OVERRIDE],
93
- ],
69
+ [:irb_workspaces, :Workspaces, "irb/cmd/pushws",
70
+ [:workspaces, NO_OVERRIDE],
71
+ [:irb_bindings, OVERRIDE_ALL],
72
+ [:bindings, NO_OVERRIDE]],
73
+ [:irb_push_workspace, :PushWorkspace, "irb/cmd/pushws",
74
+ [:irb_pushws, OVERRIDE_ALL],
75
+ [:pushws, NO_OVERRIDE],
76
+ [:irb_push_binding, OVERRIDE_ALL],
77
+ [:irb_pushb, OVERRIDE_ALL],
78
+ [:pushb, NO_OVERRIDE]],
79
+ [:irb_pop_workspace, :PopWorkspace, "irb/cmd/pushws",
80
+ [:irb_popws, OVERRIDE_ALL],
81
+ [:popws, NO_OVERRIDE],
82
+ [:irb_pop_binding, OVERRIDE_ALL],
83
+ [:irb_popb, OVERRIDE_ALL],
84
+ [:popb, NO_OVERRIDE]],
94
85
 
95
- [
96
- :irb_load, :Load, "irb/cmd/load"],
97
- [
98
- :irb_require, :Require, "irb/cmd/load"],
99
- [
100
- :irb_source, :Source, "irb/cmd/load",
101
- [:source, NO_OVERRIDE],
102
- ],
86
+ [:irb_load, :Load, "irb/cmd/load"],
87
+ [:irb_require, :Require, "irb/cmd/load"],
88
+ [:irb_source, :Source, "irb/cmd/load",
89
+ [:source, NO_OVERRIDE]],
103
90
 
104
- [
105
- :irb, :IrbCommand, "irb/cmd/subirb"],
106
- [
107
- :irb_jobs, :Jobs, "irb/cmd/subirb",
108
- [:jobs, NO_OVERRIDE],
109
- ],
110
- [
111
- :irb_fg, :Foreground, "irb/cmd/subirb",
112
- [:fg, NO_OVERRIDE],
113
- ],
114
- [
115
- :irb_kill, :Kill, "irb/cmd/subirb",
116
- [:kill, OVERRIDE_PRIVATE_ONLY],
117
- ],
91
+ [:irb, :IrbCommand, "irb/cmd/subirb"],
92
+ [:irb_jobs, :Jobs, "irb/cmd/subirb",
93
+ [:jobs, NO_OVERRIDE]],
94
+ [:irb_fg, :Foreground, "irb/cmd/subirb",
95
+ [:fg, NO_OVERRIDE]],
96
+ [:irb_kill, :Kill, "irb/cmd/subirb",
97
+ [:kill, OVERRIDE_PRIVATE_ONLY]],
118
98
 
119
- [
120
- :irb_help, :Help, "irb/cmd/help",
121
- [:help, NO_OVERRIDE],
122
- ],
99
+ [:irb_help, :Help, "irb/cmd/help",
100
+ [:help, NO_OVERRIDE]],
123
101
 
124
102
  ]
125
103
 
@@ -43,19 +43,17 @@ module IRB # :nodoc:
43
43
  @CONF[:LOAD_MODULES] = []
44
44
  @CONF[:IRB_RC] = nil
45
45
 
46
- @CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod)
47
- @CONF[:USE_COLORIZE] = true
46
+ @CONF[:USE_READLINE] = false unless defined?(ReadlineInputMethod)
48
47
  @CONF[:INSPECT_MODE] = true
49
48
  @CONF[:USE_TRACER] = false
50
49
  @CONF[:USE_LOADER] = false
51
50
  @CONF[:IGNORE_SIGINT] = true
52
51
  @CONF[:IGNORE_EOF] = false
53
52
  @CONF[:ECHO] = nil
54
- @CONF[:ECHO_ON_ASSIGNMENT] = nil
55
53
  @CONF[:VERBOSE] = nil
56
54
 
57
55
  @CONF[:EVAL_HISTORY] = nil
58
- @CONF[:SAVE_HISTORY] = 1000
56
+ @CONF[:SAVE_HISTORY] = nil
59
57
 
60
58
  @CONF[:BACK_TRACE_LIMIT] = 16
61
59
 
@@ -84,7 +82,7 @@ module IRB # :nodoc:
84
82
  :SIMPLE => {
85
83
  :PROMPT_I => ">> ",
86
84
  :PROMPT_N => ">> ",
87
- :PROMPT_S => "%l> ",
85
+ :PROMPT_S => nil,
88
86
  :PROMPT_C => "?> ",
89
87
  :RETURN => "=> %s\n"
90
88
  },
@@ -106,7 +104,7 @@ module IRB # :nodoc:
106
104
  }
107
105
 
108
106
  @CONF[:PROMPT_MODE] = (STDIN.tty? ? :DEFAULT : :NULL)
109
- @CONF[:AUTO_INDENT] = true
107
+ @CONF[:AUTO_INDENT] = false
110
108
 
111
109
  @CONF[:CONTEXT_MODE] = 3 # use binding in function on TOPLEVEL_BINDING
112
110
  @CONF[:SINGLE_IRB] = false
@@ -114,6 +112,8 @@ module IRB # :nodoc:
114
112
  @CONF[:LC_MESSAGES] = Locale.new
115
113
 
116
114
  @CONF[:AT_EXIT] = []
115
+
116
+ @CONF[:DEBUG_LEVEL] = 0
117
117
  end
118
118
 
119
119
  def IRB.init_error
@@ -161,30 +161,18 @@ module IRB # :nodoc:
161
161
  end
162
162
  when "--noinspect"
163
163
  @CONF[:INSPECT_MODE] = false
164
- when "--singleline", "--readline", "--legacy"
165
- @CONF[:USE_SINGLELINE] = true
166
- when "--nosingleline", "--noreadline"
167
- @CONF[:USE_SINGLELINE] = false
168
- when "--multiline", "--reidline"
169
- @CONF[:USE_MULTILINE] = true
170
- when "--nomultiline", "--noreidline"
171
- @CONF[:USE_MULTILINE] = false
164
+ when "--readline"
165
+ @CONF[:USE_READLINE] = true
166
+ when "--noreadline"
167
+ @CONF[:USE_READLINE] = false
172
168
  when "--echo"
173
169
  @CONF[:ECHO] = true
174
170
  when "--noecho"
175
171
  @CONF[:ECHO] = false
176
- when "--echo-on-assignment"
177
- @CONF[:ECHO_ON_ASSIGNMENT] = true
178
- when "--noecho-on-assignment"
179
- @CONF[:ECHO_ON_ASSIGNMENT] = false
180
172
  when "--verbose"
181
173
  @CONF[:VERBOSE] = true
182
174
  when "--noverbose"
183
175
  @CONF[:VERBOSE] = false
184
- when "--colorize"
185
- @CONF[:USE_COLORIZE] = true
186
- when "--nocolorize"
187
- @CONF[:USE_COLORIZE] = false
188
176
  when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/
189
177
  opt = $1 || argv.shift
190
178
  prompt_mode = opt.upcase.tr("-", "_").intern
@@ -203,6 +191,8 @@ module IRB # :nodoc:
203
191
  @CONF[:CONTEXT_MODE] = ($1 || argv.shift).to_i
204
192
  when "--single-irb"
205
193
  @CONF[:SINGLE_IRB] = true
194
+ when /^--irb_debug(?:=(.+))?/
195
+ @CONF[:DEBUG_LEVEL] = ($1 || argv.shift).to_i
206
196
  when "-v", "--version"
207
197
  print IRB.version, "\n"
208
198
  exit 0
@@ -274,11 +264,11 @@ module IRB # :nodoc:
274
264
  if home = ENV["HOME"]
275
265
  yield proc{|rc| home+"/.irb#{rc}"}
276
266
  end
277
- current_dir = Dir.pwd
278
- yield proc{|rc| current_dir+"/.irb#{rc}"}
279
- yield proc{|rc| current_dir+"/irb#{rc.sub(/\A_?/, '.')}"}
280
- yield proc{|rc| current_dir+"/_irb#{rc}"}
281
- yield proc{|rc| current_dir+"/$irb#{rc}"}
267
+ home = Dir.pwd
268
+ yield proc{|rc| home+"/.irb#{rc}"}
269
+ yield proc{|rc| home+"/irb#{rc.sub(/\A_?/, '.')}"}
270
+ yield proc{|rc| home+"/_irb#{rc}"}
271
+ yield proc{|rc| home+"/$irb#{rc}"}
282
272
  end
283
273
 
284
274
  # loading modules
@@ -11,8 +11,6 @@
11
11
  #
12
12
  require_relative 'src_encoding'
13
13
  require_relative 'magic-file'
14
- require_relative 'completion'
15
- require 'reline'
16
14
 
17
15
  module IRB
18
16
  STDIN_FILE_NAME = "(line)" # :nodoc:
@@ -142,12 +140,6 @@ module IRB
142
140
 
143
141
  @stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
144
142
  @stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
145
-
146
- if Readline.respond_to?("basic_word_break_characters=")
147
- Readline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
148
- end
149
- Readline.completion_append_character = nil
150
- Readline.completion_proc = IRB::InputCompletor::CompletionProc
151
143
  end
152
144
 
153
145
  # Reads the next line from this input method.
@@ -194,105 +186,7 @@ module IRB
194
186
  def encoding
195
187
  @stdin.external_encoding
196
188
  end
197
-
198
- if Readline.respond_to?("basic_word_break_characters=")
199
- Readline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
200
- end
201
- Readline.completion_append_character = nil
202
- Readline.completion_proc = IRB::InputCompletor::CompletionProc
203
189
  end
204
190
  rescue LoadError
205
191
  end
206
-
207
- class ReidlineInputMethod < InputMethod
208
- include Reline
209
- # Creates a new input method object using Readline
210
- def initialize
211
- super
212
-
213
- @line_no = 0
214
- @line = []
215
- @eof = false
216
-
217
- @stdin = ::IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
218
- @stdout = ::IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
219
-
220
- if Reline.respond_to?("basic_word_break_characters=")
221
- Reline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
222
- end
223
- Reline.completion_append_character = nil
224
- Reline.completion_proc = IRB::InputCompletor::CompletionProc
225
- Reline.output_modifier_proc =
226
- if IRB.conf[:USE_COLORIZE]
227
- proc do |output, complete:|
228
- next unless IRB::Color.colorable?
229
- IRB::Color.colorize_code(output, complete: complete)
230
- end
231
- else
232
- proc do |output|
233
- Reline::Unicode.escape_for_print(output)
234
- end
235
- end
236
- Reline.dig_perfect_match_proc = IRB::InputCompletor::PerfectMatchedProc
237
- end
238
-
239
- def check_termination(&block)
240
- @check_termination_proc = block
241
- end
242
-
243
- def dynamic_prompt(&block)
244
- @prompt_proc = block
245
- end
246
-
247
- def auto_indent(&block)
248
- @auto_indent_proc = block
249
- end
250
-
251
- # Reads the next line from this input method.
252
- #
253
- # See IO#gets for more information.
254
- def gets
255
- Reline.input = @stdin
256
- Reline.output = @stdout
257
- Reline.prompt_proc = @prompt_proc
258
- Reline.auto_indent_proc = @auto_indent_proc if @auto_indent_proc
259
- if l = readmultiline(@prompt, false, &@check_termination_proc)
260
- HISTORY.push(l) if !l.empty?
261
- @line[@line_no += 1] = l + "\n"
262
- else
263
- @eof = true
264
- l
265
- end
266
- end
267
-
268
- # Whether the end of this input method has been reached, returns +true+
269
- # if there is no more data to read.
270
- #
271
- # See IO#eof? for more information.
272
- def eof?
273
- super
274
- end
275
-
276
- # Whether this input method is still readable when there is no more data to
277
- # read.
278
- #
279
- # See IO#eof for more information.
280
- def readable_after_eof?
281
- true
282
- end
283
-
284
- # Returns the current line number for #io.
285
- #
286
- # #line counts the number of times #gets is called.
287
- #
288
- # See IO#lineno for more information.
289
- def line(line_no)
290
- @line[line_no]
291
- end
292
-
293
- # The external encoding for standard input.
294
- def encoding
295
- @stdin.external_encoding
296
- end
297
- end
298
192
  end