Skip to content
Browse files

Don't use output redirection by default. Only use it in bin/dietrb wh…

…en the chosen driver is socket.
  • Loading branch information...
1 parent 7366450 commit d00de78cea5ef019d6b844a0c0c06be232454ef3 @alloy committed Oct 3, 2010
Showing with 24 additions and 13 deletions.
  1. +1 −2 TODO
  2. +15 −8 bin/dietrb
  3. +8 −1 lib/irb/driver.rb
  4. +0 −2 lib/irb/driver/tty.rb
View
3 TODO
@@ -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
+* Decide whether or not we need more control for colorizing which could be done with Ripper::SexpBuilder
View
23 bin/dietrb
@@ -39,18 +39,25 @@ module IRB
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
+end
View
9 lib/irb/driver.rb
@@ -18,6 +18,13 @@ def current
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 @@ def send_to_target(method, *args)
end
end
end
-end
+end
View
2 lib/irb/driver/tty.rb
@@ -34,13 +34,11 @@ def consume
# 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

0 comments on commit d00de78

Please sign in to comment.
Something went wrong with that request. Please try again.