diff options
author | keiju <keiju@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-07-09 11:17:17 +0000 |
---|---|---|
committer | keiju <keiju@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-07-09 11:17:17 +0000 |
commit | af064b04b1622897995fe1177aabfb60db90e6f7 (patch) | |
tree | 326cb343c08c55d2d93fa5223c01f940d3591f8b /lib/irb/context.rb | |
parent | 93602810e93b5da1c7161fb4b5c1a4025434a9ce (diff) | |
download | ruby-af064b04b1622897995fe1177aabfb60db90e6f7.tar.gz |
* irb 0.9
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/irb/context.rb')
-rw-r--r-- | lib/irb/context.rb | 164 |
1 files changed, 54 insertions, 110 deletions
diff --git a/lib/irb/context.rb b/lib/irb/context.rb index ffc77de875..1c504451cb 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -1,6 +1,6 @@ # # irb/context.rb - irb context -# $Release Version: 0.7.3$ +# $Release Version: 0.9$ # $Revision$ # $Date$ # by Keiju ISHITSUKA(keiju@ishitsuka.com) @@ -9,6 +9,8 @@ # # # +require "irb/workspace" + module IRB class Context # @@ -22,33 +24,30 @@ module IRB if workspace @workspace = workspace else - @workspace = WorkSpace.new unless workspace + @workspace = WorkSpace.new end @thread = Thread.current if defined? Thread - @irb_level = 0 +# @irb_level = 0 # copy of default configuration @ap_name = IRB.conf[:AP_NAME] @rc = IRB.conf[:RC] @load_modules = IRB.conf[:LOAD_MODULES] - self.math_mode = IRB.conf[:MATH_MODE] @use_readline = IRB.conf[:USE_READLINE] @inspect_mode = IRB.conf[:INSPECT_MODE] - self.use_tracer = IRB.conf[:USE_TRACER] -# @use_loader = IRB.conf[:USE_LOADER] - self.prompt_mode = IRB.conf[:PROMPT_MODE] - + self.math_mode = IRB.conf[:MATH_MODE] if IRB.conf[:MATH_MODE] + self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRASER] + self.use_loader = IRB.conf[:USE_LOADER] if IRB.conf[:USE_LOADER] + self.eval_history = IRB.conf[:EVAL_HISTORY] if IRB.conf[:EVEL_HISTORY] + @ignore_sigint = IRB.conf[:IGNORE_SIGINT] @ignore_eof = IRB.conf[:IGNORE_EOF] @back_trace_limit = IRB.conf[:BACK_TRACE_LIMIT] - debug_level = IRB.conf[:DEBUG_LEVEL] - @verbose = IRB.conf[:VERBOSE] - - @tracer_initialized = false + self.prompt_mode = IRB.conf[:PROMPT_MODE] if IRB.conf[:SINGLE_IRB] or !defined?(JobManager) @irb_name = IRB.conf[:IRB_NAME] @@ -59,7 +58,7 @@ module IRB case input_method when nil - if (use_readline.nil? && IRB.conf[:PROMPT_MODE] != :INF_RUBY || + if (use_readline.nil? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && STDIN.tty? || use_readline?) @io = ReadlineInputMethod.new else @@ -72,18 +71,24 @@ module IRB else @io = input_method end + + @verbose = IRB.conf[:VERBOSE] + @echo = IRB.conf[:ECHO] + if @echo.nil? + @echo = true + end + @debug_level = IRB.conf[:DEBUG_LEVEL] end def main @workspace.main end + attr_reader :workspace_home attr_accessor :workspace attr_reader :thread attr_accessor :io - attr_reader :_ - attr_accessor :irb attr_accessor :ap_name attr_accessor :rc @@ -91,14 +96,8 @@ module IRB attr_accessor :irb_name attr_accessor :irb_path - attr_accessor :math_mode attr_accessor :use_readline attr_reader :inspect_mode - attr_reader :use_tracer -# attr :use_loader - - attr_reader :debug_level - attr_accessor :verbose attr_reader :prompt_mode attr_accessor :prompt_i @@ -109,33 +108,43 @@ module IRB attr_accessor :ignore_sigint attr_accessor :ignore_eof + attr_accessor :echo + attr_accessor :verbose + attr_reader :debug_level attr_accessor :back_trace_limit -# alias use_loader? use_loader - alias use_tracer? use_tracer alias use_readline? use_readline alias rc? rc - alias math? math_mode - alias verbose? verbose alias ignore_sigint? ignore_sigint alias ignore_eof? ignore_eof + alias echo? echo + + def verbose? + if @verbose.nil? + if defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod) + false + elsif !STDIN.tty? or @io.kind_of?(FileInputMethod) + true + else + false + end + end + end - def _=(value) - @_ = value - @workspace.evaluate "_ = IRB.conf[:MAIN_CONTEXT]._" + def prompting? + verbose? || (STDIN.tty? && @io.kind_of?(StdioInputMethod) || + (defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod))) end - def irb_name - if @irb_level == 0 - @irb_name - elsif @irb_name =~ /#[0-9]*$/ - @irb_name + "." + @irb_level.to_s - else - @irb_name + "#0." + @irb_level.to_s - end + attr_reader :last_value + + def set_last_value(value) + @last_value = value end + attr_reader :irb_name + def prompt_mode=(mode) @prompt_mode = mode pconf = IRB.conf[:PROMPT][mode] @@ -151,42 +160,13 @@ module IRB end def inspect? - @inspect_mode.nil? && !@math_mode or @inspect_mode + @inspect_mode.nil? or @inspect_mode end def file_input? @io.type == FileInputMethod end - def use_tracer=(opt) - if opt - IRB.initialize_tracer - unless @tracer_initialized - Tracer.set_get_line_procs(@irb_path) { - |line_no| - @io.line(line_no) - } - @tracer_initialized = true - end - elsif !opt && @use_tracer - Tracer.off - end - @use_tracer=opt - end - - def use_loader - IRB.conf[:USE_LOADER] - end - - def use_loader=(opt) - IRB.conf[:USE_LOADER] = opt - if opt - IRB.initialize_loader - end - print "Switch to load/require#{unless use_loader; ' non';end} trace mode.\n" if verbose? - opt - end - def inspect_mode=(opt) if opt @inspect_mode = opt @@ -197,20 +177,6 @@ module IRB @inspect_mode end - def math_mode=(opt) - if @math_mode == true && opt == false - IRB.fail CantRetuenNormalMode - return - end - - @math_mode = opt - if math_mode - IRB.initialize_mathn - main.instance_eval("include Math") - print "start math mode\n" if verbose? - end - end - def use_readline=(opt) @use_readline = opt print "use readline module\n" if @use_readline @@ -226,41 +192,19 @@ module IRB @debug_level > 0 end - def change_binding(*_main) - back = @workspace - @workspace = WorkSpace.new(*_main) - unless _main.empty? - begin - main.extend ExtendCommand - rescue - print "can't change binding to: ", main.inspect, "\n" - @workspace = back - return nil - end - end - @irb_level += 1 - begin - catch(:SU_EXIT) do - @irb.eval_input - end - ensure - @irb_level -= 1 - @workspace = back - end + def evaluate(line, line_no) + @line_no = line_no + set_last_value(@workspace.evaluate(self, line, irb_path, line_no)) +# @workspace.evaluate("_ = IRB.conf[:MAIN_CONTEXT]._") +# @_ = @workspace.evaluate(line, irb_path, line_no) end - alias change_workspace change_binding - alias __exit__ exit def exit(ret = 0) - if @irb_level == 0 - IRB.irb_exit(@irb, ret) - else - throw :SU_EXIT, ret - end + IRB.irb_exit(@irb, ret) end - NOPRINTING_IVARS = ["@_"] + NOPRINTING_IVARS = ["@last_value"] NO_INSPECTING_IVARS = ["@irb", "@io"] IDNAME_IVARS = ["@prompt_mode"] @@ -272,7 +216,7 @@ module IRB val = instance_eval(ivar) case ivar when *NOPRINTING_IVARS - next + array.push format("conf.%s=%s", name, "...") when *NO_INSPECTING_IVARS array.push format("conf.%s=%s", name, val.to_s) when *IDNAME_IVARS |