irb 1.4.1 → 1.4.3

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.
data/lib/irb.rb CHANGED
@@ -51,61 +51,17 @@ require_relative "irb/easter-egg"
51
51
  #
52
52
  # == Command line options
53
53
  #
54
- # Usage: irb.rb [options] [programfile] [arguments]
55
- # -f Suppress read of ~/.irbrc
56
- # -d Set $DEBUG to true (same as `ruby -d')
57
- # -r load-module Same as `ruby -r'
58
- # -I path Specify $LOAD_PATH directory
59
- # -U Same as `ruby -U`
60
- # -E enc Same as `ruby -E`
61
- # -w Same as `ruby -w`
62
- # -W[level=2] Same as `ruby -W`
63
- # --context-mode n Set n[0-4] to method to create Binding Object,
64
- # when new workspace was created
65
- # --extra-doc-dir Add an extra doc dir for the doc dialog
66
- # --echo Show result (default)
67
- # --noecho Don't show result
68
- # --echo-on-assignment
69
- # Show result on assignment
70
- # --noecho-on-assignment
71
- # Don't show result on assignment
72
- # --truncate-echo-on-assignment
73
- # Show truncated result on assignment (default)
74
- # --inspect Use `inspect' for output
75
- # --noinspect Don't use inspect for output
76
- # --multiline Use multiline editor module
77
- # --nomultiline Don't use multiline editor module
78
- # --singleline Use singleline editor module
79
- # --nosingleline Don't use singleline editor module
80
- # --colorize Use colorization
81
- # --nocolorize Don't use colorization
82
- # --autocomplete Use autocompletion
83
- # --noautocomplete Don't use autocompletion
84
- # --prompt prompt-mode/--prompt-mode prompt-mode
85
- # Switch prompt mode. Pre-defined prompt modes are
86
- # `default', `simple', `xmp' and `inf-ruby'
87
- # --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
88
- # Suppresses --multiline and --singleline.
89
- # --sample-book-mode/--simple-prompt
90
- # Simple prompt mode
91
- # --noprompt No prompt mode
92
- # --single-irb Share self with sub-irb.
93
- # --tracer Display trace for each execution of commands.
94
- # --back-trace-limit n
95
- # Display backtrace top n and tail n. The default
96
- # value is 16.
97
- # --verbose Show details
98
- # --noverbose Don't show details
99
- # -v, --version Print the version of irb
100
- # -h, --help Print help
101
- # -- Separate options of irb from the list of command-line args
54
+ # :include: ./irb/lc/help-message
102
55
  #
103
56
  # == Configuration
104
57
  #
105
- # IRB reads from <code>~/.irbrc</code> when it's invoked.
106
- #
107
- # If <code>~/.irbrc</code> doesn't exist, +irb+ will try to read in the following order:
58
+ # IRB reads a personal initialization file when it's invoked.
59
+ # IRB searches a file in the following order and loads the first one found.
108
60
  #
61
+ # * <tt>$IRBRC</tt> (if <tt>$IRBRC</tt> is set)
62
+ # * <tt>$XDG_CONFIG_HOME/irb/irbrc</tt> (if <tt>$XDG_CONFIG_HOME</tt> is set)
63
+ # * <tt>~/.irbrc</tt>
64
+ # * +.config/irb/irbrc+
109
65
  # * +.irbrc+
110
66
  # * +irb.rc+
111
67
  # * +_irbrc+
@@ -433,11 +389,7 @@ module IRB
433
389
  #
434
390
  # Will raise an Abort exception, or the given +exception+.
435
391
  def IRB.irb_abort(irb, exception = Abort)
436
- if defined? Thread
437
- irb.context.thread.raise exception, "abort then interrupt!"
438
- else
439
- raise exception, "abort then interrupt!"
440
- end
392
+ irb.context.thread.raise exception, "abort then interrupt!"
441
393
  end
442
394
 
443
395
  class Irb
@@ -474,6 +426,10 @@ module IRB
474
426
  def initialize(workspace = nil, input_method = nil)
475
427
  @context = Context.new(self, workspace, input_method)
476
428
  @context.main.extend ExtendCommandBundle
429
+ @context.command_aliases.each do |alias_name, cmd_name|
430
+ next if @context.symbol_alias(alias_name)
431
+ @context.main.install_alias_method(alias_name, cmd_name)
432
+ end
477
433
  @signal_status = :IN_IRB
478
434
  @scanner = RubyLex.new
479
435
  end
@@ -554,13 +510,15 @@ module IRB
554
510
 
555
511
  @scanner.set_auto_indent(@context) if @context.auto_indent_mode
556
512
 
557
- @scanner.each_top_level_statement do |line, line_no|
513
+ @scanner.each_top_level_statement(@context) do |line, line_no|
558
514
  signal_status(:IN_EVAL) do
559
515
  begin
560
516
  line.untaint if RUBY_VERSION < '2.7'
561
517
  if IRB.conf[:MEASURE] && IRB.conf[:MEASURE_CALLBACKS].empty?
562
518
  IRB.set_measure_callback
563
519
  end
520
+ # Assignment expression check should be done before @context.evaluate to handle code like `a /2#/ if false; a = 1`
521
+ is_assignment = assignment_expression?(line)
564
522
  if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty?
565
523
  result = nil
566
524
  last_proc = proc{ result = @context.evaluate(line, line_no, exception: exc) }
@@ -577,7 +535,7 @@ module IRB
577
535
  @context.evaluate(line, line_no, exception: exc)
578
536
  end
579
537
  if @context.echo?
580
- if assignment_expression?(line)
538
+ if is_assignment
581
539
  if @context.echo_on_assignment?
582
540
  output_value(@context.echo_on_assignment? == :truncate)
583
541
  end
@@ -640,11 +598,7 @@ module IRB
640
598
 
641
599
  if exc.backtrace
642
600
  order = nil
643
- if '2.5.0' == RUBY_VERSION
644
- # Exception#full_message doesn't have keyword arguments.
645
- message = exc.full_message # the same of (highlight: true, order: bottom)
646
- order = :bottom
647
- elsif '2.5.1' <= RUBY_VERSION && RUBY_VERSION < '3.0.0'
601
+ if RUBY_VERSION < '3.0.0'
648
602
  if STDOUT.tty?
649
603
  message = exc.full_message(order: :bottom)
650
604
  order = :bottom
@@ -825,11 +779,11 @@ module IRB
825
779
  if diff_size.positive? and output_width > winwidth
826
780
  lines, _ = Reline::Unicode.split_by_width(first_line, winwidth - diff_size - 3)
827
781
  str = "%s..." % lines.first
828
- str += "\e[0m" if @context.use_colorize
782
+ str += "\e[0m" if Color.colorable?
829
783
  multiline_p = false
830
784
  else
831
785
  str = str.gsub(/(\A.*?\n).*/m, "\\1...")
832
- str += "\e[0m" if @context.use_colorize
786
+ str += "\e[0m" if Color.colorable?
833
787
  end
834
788
  else
835
789
  output_width = Reline::Unicode.calculate_width(@context.return_format % str, true)
@@ -837,7 +791,7 @@ module IRB
837
791
  if diff_size.positive? and output_width > winwidth
838
792
  lines, _ = Reline::Unicode.split_by_width(str, winwidth - diff_size - 3)
839
793
  str = "%s..." % lines.first
840
- str += "\e[0m" if @context.use_colorize
794
+ str += "\e[0m" if Color.colorable?
841
795
  end
842
796
  end
843
797
  end
@@ -875,9 +829,12 @@ module IRB
875
829
  # array of parsed expressions. The first element of each expression is the
876
830
  # expression's type.
877
831
  verbose, $VERBOSE = $VERBOSE, nil
878
- result = ASSIGNMENT_NODE_TYPES.include?(Ripper.sexp(line)&.dig(1,-1,0))
832
+ code = "#{RubyLex.generate_local_variables_assign_code(@context.local_variables) || 'nil;'}\n#{line}"
833
+ # Get the last node_type of the line. drop(1) is to ignore the local_variables_assign_code part.
834
+ node_type = Ripper.sexp(code)&.dig(1)&.drop(1)&.dig(-1, 0)
835
+ ASSIGNMENT_NODE_TYPES.include?(node_type)
836
+ ensure
879
837
  $VERBOSE = verbose
880
- result
881
838
  end
882
839
 
883
840
  ATTR_TTY = "\e[%sm"
data/man/irb.1 CHANGED
@@ -173,8 +173,19 @@ The default value is 16.
173
173
  .El
174
174
  .Pp
175
175
  .Sh ENVIRONMENT
176
- .Bl -tag -compact
176
+ .Bl -tag -compact -width "XDG_CONFIG_HOME"
177
+ .It Ev IRB_LANG
178
+ The locale used for
179
+ .Nm .
180
+ .Pp
177
181
  .It Ev IRBRC
182
+ The path to the personal initialization file.
183
+ .Pp
184
+ .It Ev XDG_CONFIG_HOME
185
+ .Nm
186
+ respects XDG_CONFIG_HOME. If this is set, load
187
+ .Pa $XDG_CONFIG_HOME/irb/irbrc
188
+ as a personal initialization file.
178
189
  .Pp
179
190
  .El
180
191
  .Pp
@@ -186,7 +197,17 @@ depends on same variables as
186
197
  .Sh FILES
187
198
  .Bl -tag -compact
188
199
  .It Pa ~/.irbrc
189
- Personal irb initialization.
200
+ Personal irb initialization. If
201
+ .Ev IRBRC
202
+ is set, read
203
+ .Pa $IRBRC
204
+ instead. If
205
+ .Ev IRBRC
206
+ is not set and
207
+ .Ev XDG_CONFIG_HOME
208
+ is set,
209
+ .Pa $XDG_CONFIG_HOME/irb/irbrc
210
+ is loaded.
190
211
  .Pp
191
212
  .El
192
213
  .Pp
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
+ - aycabta
7
8
  - Keiju ISHITSUKA
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2021-12-25 00:00:00.000000000 Z
12
+ date: 2022-11-17 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: reline
@@ -26,6 +27,7 @@ dependencies:
26
27
  version: 0.3.0
27
28
  description: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
28
29
  email:
30
+ - aycabta@gmail.com
29
31
  - keiju@ruby-lang.org
30
32
  executables:
31
33
  - irb
@@ -105,14 +107,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
107
  requirements:
106
108
  - - ">="
107
109
  - !ruby/object:Gem::Version
108
- version: '2.5'
110
+ version: '2.6'
109
111
  required_rubygems_version: !ruby/object:Gem::Requirement
110
112
  requirements:
111
113
  - - ">="
112
114
  - !ruby/object:Gem::Version
113
115
  version: '0'
114
116
  requirements: []
115
- rubygems_version: 3.2.22
117
+ rubygems_version: 3.4.0.dev
116
118
  signing_key:
117
119
  specification_version: 4
118
120
  summary: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).