Skip to content

Commit

Permalink
No bidirectional pipes under Linux. t('-'t)
Browse files Browse the repository at this point in the history
  • Loading branch information
tailor committed Feb 13, 2008
1 parent 61b5547 commit dbce689
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
48 changes: 34 additions & 14 deletions lib/live_console.rb
Expand Up @@ -46,7 +46,7 @@ def run
loop { loop {
Thread.pass Thread.pass
if io.start if io.start
irb_io = GenericIOMethod.new io.raw irb_io = GenericIOMethod.new io.raw_input, io.raw_output
begin begin
IRB.start_with_io(irb_io) IRB.start_with_io(irb_io)
rescue Errno::EPIPE => e rescue Errno::EPIPE => e
Expand Down Expand Up @@ -134,32 +134,52 @@ def print(*args)
end end
end end


# The SocketIOMethod is a class that wraps I/O over a socket for IRB. # The GenericIOMethod is a class that wraps I/O for IRB.
class GenericIOMethod < IRB::StdioInputMethod class GenericIOMethod < IRB::StdioInputMethod
def initialize(io) # call-seq:
@io = io # GenericIOMethod.new io
# GenericIOMethod.new input, output
#
# Creates a GenericIOMethod, using either a single object for both input
# and output, or one object for input and another for output.
def initialize in, out = nil
@in, @out = in, out
@line = [] @line = []
@line_no = 0 @line_no = 0
end end


attr_reader :in
def out
@out || in
end

def gets def gets
@io.print @prompt out.print @prompt
@io.flush out.flush
@line[@line_no += 1] = @io.gets @line[@line_no += 1] = in.gets
@io.flush # @io.flush # Not sure this is needed.
@line[@line_no] @line[@line_no]
end end


# These just pass through to the io. # Returns the user input history.
%w(eof? close).each { |mname| def lines
define_method(mname) { || @io.send mname } @line.dup
} end


def print(*a) def print(*a)
@io.print *a out.print *a
end end


def file_name def file_name
@io.inspect in.inspect
end

def eof?
in.eof?
end

def close
in.close
out.close if @out
end end
end end
2 changes: 1 addition & 1 deletion lib/live_console/io_methods.rb
Expand Up @@ -33,7 +33,7 @@ def missing_opts


def self.included(other) def self.included(other)
other.instance_eval { other.instance_eval {
readers = [:opts, :raw] readers = [:opts, :raw_input, :raw_output]
attr_accessor *readers attr_accessor *readers
private *readers.map { |r| (r.to_s + '=').to_sym } private *readers.map { |r| (r.to_s + '=').to_sym }


Expand Down

0 comments on commit dbce689

Please sign in to comment.