[macruby-changes] [4762] DietRB/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 8 04:11:09 PDT 2010


Revision: 4762
          http://trac.macosforge.org/projects/ruby/changeset/4762
Author:   eloy.de.enige at gmail.com
Date:     2010-10-08 04:11:08 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Don't use output redirection by default. Only use it in bin/dietrb when the chosen driver is socket.

From: Eloy Duran <eloy.de.enige at gmail.com>

Modified Paths:
--------------
    DietRB/trunk/TODO
    DietRB/trunk/bin/dietrb
    DietRB/trunk/lib/irb/driver/tty.rb
    DietRB/trunk/lib/irb/driver.rb

Modified: DietRB/trunk/TODO
===================================================================
--- DietRB/trunk/TODO	2010-10-08 11:10:58 UTC (rev 4761)
+++ DietRB/trunk/TODO	2010-10-08 11:11:08 UTC (rev 4762)
@@ -1,9 +1,8 @@
 * Make Context take a ‘driver’ again, because we do not always want to redirect $stdout, but still receive output from the context. Ie, result, exception etc. A situation where we don’t want to redirect $stdout is in a server app.
-* Don't use load the output redirection lib by default (ie when using standard tty/readline)
 * Write docs for using a as library. Probably right after creating a Cocoa client.
 * Add specs for irb/driver/socket, and possibly for bin/dietrb
 * Configurable history file? (:HISTORY_FILE) Configurable number of saved history lines? (:SAVE_HISTORY)
 * Make sure the following formatters work: hirb, awesome_print, and looksee
 * Make sure the majority of the utils in utility_belt work
 * Possibly add copy-paste support as an ext
-* Decide whether or not we need more control for colorizing which could be done with Ripper::SexpBuilder
\ No newline at end of file
+* Decide whether or not we need more control for colorizing which could be done with Ripper::SexpBuilder

Modified: DietRB/trunk/bin/dietrb
===================================================================
--- DietRB/trunk/bin/dietrb	2010-10-08 11:10:58 UTC (rev 4761)
+++ DietRB/trunk/bin/dietrb	2010-10-08 11:11:08 UTC (rev 4762)
@@ -39,18 +39,25 @@
     IRB.formatter.filter_from_backtrace << /^#{__FILE__}/
     
     if ARGV.empty?
-      driver ||= begin
-        require 'readline'
-        'readline'
-      rescue LoadError
-        'tty'
+      if driver == 'socket'
+        require "irb/driver/socket"
+        IRB::Driver.redirect_output! do
+          irb(*IRB_CONTEXT_TOPLEVEL_ARGS)
+        end
+      else
+        driver ||= begin
+          require 'readline'
+          'readline'
+        rescue LoadError
+          'tty'
+        end
+        require "irb/driver/#{driver}"
+        irb(*IRB_CONTEXT_TOPLEVEL_ARGS)
       end
-      require "irb/driver/#{driver}"
-      irb(*IRB_CONTEXT_TOPLEVEL_ARGS)
     else
       path = ARGV.shift
       context = IRB::Context.new(*IRB_CONTEXT_TOPLEVEL_ARGS)
       File.open(path, 'r') { |f| f.each_line { |line| context.input_line(line) } }
     end
   end
-end
\ No newline at end of file
+end

Modified: DietRB/trunk/lib/irb/driver/tty.rb
===================================================================
--- DietRB/trunk/lib/irb/driver/tty.rb	2010-10-08 11:10:58 UTC (rev 4761)
+++ DietRB/trunk/lib/irb/driver/tty.rb	2010-10-08 11:11:08 UTC (rev 4762)
@@ -34,13 +34,11 @@
       # subclass thereof.
       def run(context)
         @context_stack << context
-        before, $stdout = $stdout, OutputRedirector.new unless $stdout.is_a?(OutputRedirector)
         while line = consume
           break unless context.process_line(line)
         end
       ensure
         @context_stack.pop
-        $stdout = before if before
       end
     end
   end

Modified: DietRB/trunk/lib/irb/driver.rb
===================================================================
--- DietRB/trunk/lib/irb/driver.rb	2010-10-08 11:10:58 UTC (rev 4761)
+++ DietRB/trunk/lib/irb/driver.rb	2010-10-08 11:11:08 UTC (rev 4762)
@@ -18,6 +18,13 @@
           end
         end
       end
+
+      def redirect_output!(redirector = OutputRedirector.new)
+        before, $stdout = $stdout, redirector unless $stdout.is_a?(redirector.class)
+        yield
+      ensure
+        $stdout = before if before
+      end
     end
     
     class OutputRedirector
@@ -58,4 +65,4 @@
       end
     end
   end
-end
\ No newline at end of file
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/ff10beaf/attachment.html>


More information about the macruby-changes mailing list