From f2cd4f4cd0a1e352fcc48a216127beaeda2b2399 Mon Sep 17 00:00:00 2001 From: aycabta Date: Tue, 23 Apr 2019 18:09:46 +0900 Subject: IRB is improved with Reline and RDoc, take 2 --- lib/irb/context.rb | 81 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 35 deletions(-) (limited to 'lib/irb/context.rb') 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 IRB.conf[:USE_REIDLINE] + # + # See #use_reidline= for more information. + attr_reader :use_reidline # Whether +Readline+ is enabled or not. # # A copy of the default IRB.conf[:USE_READLINE] @@ -211,10 +235,6 @@ module IRB # # A copy of the default IRB.conf[:VERBOSE] 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 -- cgit v1.2.3