class Redirect

@private

Public Class Methods

new(dest) click to toggle source
Calls superclass method
# File lib/fox16/irb.rb, line 42
def initialize(dest)
        super()
        @dest = dest
end

Public Instance Methods

close() click to toggle source
# File lib/fox16/irb.rb, line 57
def close
        if @thread
                $defout = @old_out.dup
                $stderr = @old_err.dup
                $stdin = @old_in.dup
                @output[1].close
                @thread.join
        end
end
gets() click to toggle source
# File lib/fox16/irb.rb, line 47
def gets
        close
        @dest.write(prompt)
        str = @dest.gets(@prompt)
        if /^exit/ =~ str
                exit
        end
        @line[@line_no += 1] = str
end
redir() click to toggle source
# File lib/fox16/irb.rb, line 67
def redir
        @output = IO.pipe
        @old_out = $defout.dup
        @old_err = $stderr.dup
        @old_in = $stdin.dup
        $stdin = @dest.input[0]
        $defout = $stderr = @output[1]
        @output[1].fcntl(Fcntl::F_SETFL, File::NONBLOCK)
        @thread = Thread.new {
                while not @output[0].eof?
                        select([@output[0]])
                        @dest.write(@output[0].read)
                end
                @output[0].close
        }
end