Skip to content

Commit

Permalink
Don't use output redirection by default. Only use it in bin/dietrb wh…
Browse files Browse the repository at this point in the history
…en the chosen driver is socket.

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

git-svn-id: http://svn.macosforge.org/repository/ruby/DietRB/trunk@4762 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
alloy committed Oct 8, 2010
1 parent 0d36fc8 commit e201fe1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
3 changes: 1 addition & 2 deletions 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
23 changes: 15 additions & 8 deletions bin/dietrb
Expand Up @@ -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
9 changes: 8 additions & 1 deletion lib/irb/driver.rb
Expand Up @@ -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
Expand Down Expand Up @@ -58,4 +65,4 @@ def send_to_target(method, *args)
end
end
end
end
end
2 changes: 0 additions & 2 deletions lib/irb/driver/tty.rb
Expand Up @@ -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
Expand Down

0 comments on commit e201fe1

Please sign in to comment.