Permalink
Browse files

Some more cleanup.

* Replace Notifier with Logger
* Remove CONTEXT_MODEs other than 3
* make Colorizer a first-class concept (IRB.puts to invoke the current colorizer)
* eliminate XMP
* Add RubyLex#get_lex for later use
1 parent efc94c3 commit f8e3331586f9a6181025e2d1e40a700c33aeb4a4 Yehuda Katz committed Nov 30, 2009
Showing with 412 additions and 1,103 deletions.
  1. +0 −1 bin/irb
  2. +17 −4 irb.rb
  3. +0 −67 irb/cmd/load.rb
  4. +1 −2 irb/cmd/pushws.rb
  5. +3 −3 irb/cmd/subirb.rb
  6. +1 −5 irb/colorize.rb
  7. +2 −9 irb/completion.rb
  8. +4 −2 irb/context.rb
  9. +4 −8 irb/ext/change-ws.rb
  10. +0 −177 irb/ext/loader.rb
  11. +8 −8 irb/ext/math-mode.rb
  12. +14 −19 irb/ext/multi-irb.rb
  13. +0 −65 irb/ext/use-loader.rb
  14. +4 −4 irb/ext/workspaces.rb
  15. +14 −19 irb/extend-command.rb
  16. +0 −67 irb/frame.rb
  17. +10 −11 irb/help.rb
  18. +8 −21 irb/init.rb
  19. +45 −45 irb/locale.rb
  20. +0 −145 irb/notifier.rb
  21. +16 −28 irb/output-method.rb
  22. +10 −0 irb/ruby-lex.rb
  23. +72 −64 irb/ruby-token.rb
  24. +164 −159 irb/slex.rb
  25. +15 −79 irb/workspace.rb
  26. +0 −15 irb/ws-for-case-2.rb
  27. +0 −76 irb/xmp.rb
View
@@ -2,5 +2,4 @@
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), ".."))
require "irb"
-require "tracer"
IRB.start
View
21 irb.rb
@@ -16,8 +16,12 @@
require "irb/ruby-lex"
require "irb/input-method"
+require "irb/output-method"
require "irb/locale"
require "irb/colorize"
+require "irb/proxy"
+require "pp"
+require "stringio"
STDOUT.sync = true
@@ -33,6 +37,15 @@ class << self
attr_reader :conf
attr_accessor :main_context
+ def puts(*args)
+ main_context.output_method.puts(*args)
+ nil
+ end
+
+ def p(arg)
+ puts arg.inspect
+ end
+
def pause
sleep
STDOUT.flush
@@ -106,10 +119,10 @@ def handle_exception(exc)
exc.backtrace.each do |line|
line = @context.workspace.filter_backtrace(line) unless irb_bug
- puts "\tfrom #{line}" if line
+ IRB.puts "\tfrom #{line}" if line
end
- puts "Maybe IRB bug!" if irb_bug
+ IRB.puts "Maybe IRB bug!" if irb_bug
end
def eval_input
@@ -140,12 +153,12 @@ def set_input
def signal_handle
case @signal_status
when :IN_INPUT
- puts "^C"
+ IRB.puts "^C"
raise RubyLex::TerminateLineInput
when :IN_EVAL
IRB.irb_abort(self)
when :IN_LOAD
- puts "\nabort!!" if @context.verbose?
+ IRB.puts "\nabort!!" if @context.verbose?
IRB.irb_abort(self, LoadAbort)
when :IN_IRB
# ignore
View
@@ -1,67 +0,0 @@
-#
-# load.rb -
-# $Release Version: 0.9.5$
-# $Revision: 11708 $
-# $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "irb/cmd/nop.rb"
-require "irb/ext/loader"
-
-module IRB
- module ExtendCommand
- class Load<Nop
- include IrbLoader
-
- def execute(file_name, priv = nil)
-# return ruby_load(file_name) unless IRB.conf[:USE_LOADER]
- return irb_load(file_name, priv)
- end
- end
-
- class Require<Nop
- include IrbLoader
-
- def execute(file_name)
-# return ruby_require(file_name) unless IRB.conf[:USE_LOADER]
-
- rex = Regexp.new("#{Regexp.quote(file_name)}(\.o|\.rb)?")
- return false if $".find{|f| f =~ rex}
-
- case file_name
- when /\.rb$/
- begin
- if irb_load(file_name)
- $".push file_name
- return true
- end
- rescue LoadError
- end
- when /\.(so|o|sl)$/
- return ruby_require(file_name)
- end
-
- begin
- irb_load(f = file_name + ".rb")
- $".push f
- return true
- rescue LoadError
- return ruby_require(file_name)
- end
- end
- end
-
- class Source<Nop
- include IrbLoader
- def execute(file_name)
- source_file(file_name)
- end
- end
- end
-
-end
View
@@ -18,8 +18,7 @@ module ExtendCommand
class Workspaces<Nop
def execute(*obj)
workspaces = irb_context.workspaces.map {|w| w.main.inspect} + ["[green]#{irb_context.main.inspect}[/]"]
- puts IRB.colorize("[blue]Workspaces\n----------[/]\n" <<
- workspaces.join("\n"))
+ IRB.puts "[blue]Workspaces\n----------[/]\n" << workspaces.join("\n")
IRB::CommandResult
end
end
View
@@ -24,16 +24,16 @@ def execute(*obj)
class Jobs < Nop
def execute
- puts IRB.job_manager.inspect
+ IRB.p IRB.job_manager
IRB::CommandResult
end
end
class Foreground < Nop
def execute(key = nil)
unless key
- puts IRB.colorize("[red]You need to specify a job to foreground[/]")
- puts
+ IRB.puts "[red]You need to specify a job to foreground[/]"
+ IRB.puts
IRB.job_manager.display_jobs
return IRB::CommandResult
end
View
@@ -1,9 +1,5 @@
module IRB
- def self.colorize(str)
- ColoredString.new(str)
- end
-
- class ColoredString
+ class ColoredShellString
COLORS = {
:"\\/" => '0;0',
:nothing => '0;0',
View
@@ -38,7 +38,7 @@ module InputCompletor
bind = IRB.current_context.workspace.binding
case input
- when /^(\/[^\/]*\/)\.([^.]*)$/
+ when %r{^(/[^/]*/)\.([^.]*)$}
# Regexp
receiver = $1
message = Regexp.quote($2)
@@ -64,13 +64,7 @@ module InputCompletor
when /^(:[^:.]*)$/
# Symbol
- if Symbol.respond_to?(:all_symbols)
- sym = $1
- candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
- candidates.grep(/^#{sym}/)
- else
- []
- end
+ Symbol.all_symbols.map(&:inspect).grep(/^#{$1}/)
when /^::([A-Z][^:\.\(]*)$/
# Absolute Constant or class methods
@@ -124,7 +118,6 @@ module InputCompletor
when /^(\$[^.]*)$/
candidates = global_variables.grep(Regexp.new(Regexp.quote($1)))
-# when /^(\$?(\.?[^.]+)+)\.([^.]*)$/
when /^((\.?[^.]+)+)\.([^.]*)$/
# variable
receiver = $1
View
@@ -33,7 +33,6 @@ def initialize(irb, workspace = nil, input_method = nil, output_method = nil)
# Extra modules
self.math_mode = IRB.conf[:MATH_MODE] if IRB.conf[:MATH_MODE]
self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRACER]
- self.use_loader = IRB.conf[:USE_LOADER] if IRB.conf[:USE_LOADER]
self.eval_history = IRB.conf[:EVAL_HISTORY] if IRB.conf[:EVAL_HISTORY]
self.prompt_mode = IRB.conf[:PROMPT_MODE]
@@ -108,6 +107,9 @@ def main
attr_accessor :verbose
attr_reader :debug_level
+ attr_reader :input_method
+ attr_reader :output_method
+
alias use_readline? use_readline
alias rc? rc
alias echo? echo
@@ -206,7 +208,7 @@ def set_prompt(scanner)
end
def print_verbose(str)
- puts str if verbose?
+ IRB.puts str if verbose?
end
# Formats the prompt according to a format string. Available
View
@@ -17,14 +17,10 @@ def home_workspace
@home_workspace ||= @workspace
end
- def change_workspace(_main = nil)
- unless _main
- @workspace = home_workspace
- return main
- end
-
- @workspace = WorkSpace.new(_main)
- @workspace.main.extend ExtendCommandBundle
+ def change_workspace(_main = home_workspace)
+ home_workspace
+ @workspace = _main.is_a?(WorkSpace) ? _main : WorkSpace.new(_main)
+ main
end
end
end
Oops, something went wrong.

0 comments on commit f8e3331

Please sign in to comment.