summaryrefslogtreecommitdiff
path: root/lib/irb/context.rb
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2019-04-23 18:09:46 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-04-23 20:08:02 +0900
commitf2cd4f4cd0a1e352fcc48a216127beaeda2b2399 (patch)
tree8e02f39a8df8fa5708e446aeb8d42d45d8a28abe /lib/irb/context.rb
parent87cf45a512a7803f266e4782c49e0a99c06a4039 (diff)
IRB is improved with Reline and RDoc, take 2
Diffstat (limited to 'lib/irb/context.rb')
-rw-r--r--lib/irb/context.rb81
1 files changed, 46 insertions, 35 deletions
diff --git a/lib/irb/context.rb b/lib/irb/context.rb
index e8e6a118e6..866eb1de9d 100644
--- a/lib/irb/context.rb
+++ b/lib/irb/context.rb
@@ -22,7 +22,7 @@ module IRB
#
# The optional +input_method+ argument:
#
- # +nil+:: uses stdin or Readline
+ # +nil+:: uses stdin or Reidline or Readline
# +String+:: uses a File
# +other+:: uses this as InputMethod
def initialize(irb, workspace = nil, input_method = nil, output_method = nil)
@@ -40,6 +40,7 @@ module IRB
@load_modules = IRB.conf[:LOAD_MODULES]
@use_readline = IRB.conf[:USE_READLINE]
+ @use_reidline = IRB.conf[:USE_REIDLINE]
@verbose = IRB.conf[:VERBOSE]
@io = nil
@@ -64,23 +65,41 @@ module IRB
case input_method
when nil
- case use_readline?
+ @io = nil
+ case use_reidline?
when nil
- if (defined?(ReadlineInputMethod) && STDIN.tty? &&
- IRB.conf[:PROMPT_MODE] != :INF_RUBY)
- @io = ReadlineInputMethod.new
+ if STDIN.tty? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !use_readline?
+ @io = ReidlineInputMethod.new
else
- @io = StdioInputMethod.new
+ @io = nil
end
when false
- @io = StdioInputMethod.new
+ @io = nil
when true
- if defined?(ReadlineInputMethod)
- @io = ReadlineInputMethod.new
+ @io = ReidlineInputMethod.new
+ end
+ unless @io
+ case use_readline?
+ when nil
+ if (defined?(ReadlineInputMethod) && STDIN.tty? &&
+ IRB.conf[:PROMPT_MODE] != :INF_RUBY)
+ @io = ReadlineInputMethod.new
+ else
+ @io = nil
+ end
+ when false
+ @io = nil
+ when true
+ if defined?(ReadlineInputMethod)
+ @io = ReadlineInputMethod.new
+ else
+ @io = nil
+ end
else
- @io = StdioInputMethod.new
+ @io = nil
end
end
+ @io = StdioInputMethod.new unless @io
when String
@io = FileInputMethod.new(input_method)
@@ -101,7 +120,6 @@ module IRB
if @echo.nil?
@echo = true
end
- self.debug_level = IRB.conf[:DEBUG_LEVEL]
end
# The top-level workspace, see WorkSpace#main
@@ -117,9 +135,9 @@ module IRB
attr_reader :thread
# The current input method
#
- # Can be either StdioInputMethod, ReadlineInputMethod, FileInputMethod or
- # other specified when the context is created. See ::new for more
- # information on +input_method+.
+ # Can be either StdioInputMethod, ReadlineInputMethod,
+ # ReidlineInputMethod, FileInputMethod or other specified when the
+ # context is created. See ::new for more # information on +input_method+.
attr_accessor :io
# Current irb session
@@ -137,6 +155,12 @@ module IRB
# +input_method+ passed to Context.new
attr_accessor :irb_path
+ # Whether +Reidline+ is enabled or not.
+ #
+ # A copy of the default <code>IRB.conf[:USE_REIDLINE]</code>
+ #
+ # See #use_reidline= for more information.
+ attr_reader :use_reidline
# Whether +Readline+ is enabled or not.
#
# A copy of the default <code>IRB.conf[:USE_READLINE]</code>
@@ -211,10 +235,6 @@ module IRB
#
# A copy of the default <code>IRB.conf[:VERBOSE]</code>
attr_accessor :verbose
- # The debug level of irb
- #
- # See #debug_level= for more information.
- attr_reader :debug_level
# The limit of backtrace lines displayed as top +n+ and tail +n+.
#
@@ -225,6 +245,8 @@ module IRB
# See IRB@Command+line+options for more command line options.
attr_accessor :back_trace_limit
+ # Alias for #use_reidline
+ alias use_reidline? use_reidline
# Alias for #use_readline
alias use_readline? use_readline
# Alias for #rc
@@ -236,7 +258,9 @@ module IRB
# Returns whether messages are displayed or not.
def verbose?
if @verbose.nil?
- if defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)
+ if @io.kind_of?(ReidlineInputMethod)
+ false
+ elsif defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)
false
elsif !STDIN.tty? or @io.kind_of?(FileInputMethod)
true
@@ -249,9 +273,11 @@ module IRB
end
# Whether #verbose? is +true+, and +input_method+ is either
- # StdioInputMethod or ReadlineInputMethod, see #io for more information.
+ # StdioInputMethod or ReidlineInputMethod or ReadlineInputMethod, see #io
+ # for more information.
def prompting?
verbose? || (STDIN.tty? && @io.kind_of?(StdioInputMethod) ||
+ @io.kind_of?(ReidlineInputMethod) ||
(defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)))
end
@@ -361,21 +387,6 @@ module IRB
print "Do nothing."
end
- # Sets the debug level of irb
- #
- # Can also be set using the +--irb_debug+ command line option.
- #
- # See IRB@Command+line+options for more command line options.
- def debug_level=(value)
- @debug_level = value
- RubyLex.debug_level = value
- end
-
- # Whether or not debug mode is enabled, see #debug_level=.
- def debug?
- @debug_level > 0
- end
-
def evaluate(line, line_no, exception: nil) # :nodoc:
@line_no = line_no
if exception