-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #2 WIP: writes to STD{OUT,ERR} and reads from STDIN will go to
client most likely to have initiated the write/read
- Loading branch information
Showing
5 changed files
with
182 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
module PryRemoteEm | ||
class IO | ||
attr_reader :fileno | ||
|
||
def initialize(io) | ||
@io = io.to_io | ||
@fileno = @io.fileno | ||
@clients = [] | ||
end | ||
|
||
def register(client) | ||
return if @clients.include?(client) | ||
@clients << client | ||
end | ||
|
||
def unregister(client) | ||
@clients.delete(client) | ||
end | ||
|
||
def puts(*args) | ||
# clients waiting for responses are not the client responsible | ||
# for this #puts call; not true in a Threaded environment | ||
@clients && @clients.each { |c| | ||
!c.waiting? && c.puts(*args) | ||
} | ||
@io.puts(*args) | ||
end | ||
|
||
def print(*args) | ||
# clients waiting for responses are not the client responsible | ||
# for this #puts call; not true in a Threaded environment | ||
@clients && @clients.each { |c| | ||
!c.waiting? && c.print(*args) | ||
} | ||
@io.print(*args) | ||
end | ||
alias :write :print | ||
|
||
def gets(*args) | ||
f = Fiber.current | ||
given = false | ||
@clients.each do |c| | ||
# clients waiting for responses are not the client responsible | ||
# for this #puts call; not true in a Threaded environment | ||
next if c.waiting? | ||
Fiber.new { | ||
got = c.gets(*args) | ||
if !given && f.alive? | ||
given = true | ||
f.resume(got) | ||
end | ||
}.resume | ||
end | ||
return Fiber.yield | ||
end | ||
|
||
def tty? | ||
true | ||
end | ||
|
||
def flush | ||
true | ||
end | ||
|
||
def eof? | ||
false | ||
end | ||
|
||
def to_io | ||
self | ||
end | ||
|
||
def method_missing(meth, *args, &blk) | ||
STDERR.puts "call to io (#{fileno}) #{meth.inspect} not overriden by PryRemoteEm::IO" | ||
block_given? ? send(meth, *args, &blk) : send(meth, *args) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env ruby | ||
require 'pry-remote-em/server' | ||
require 'highline' | ||
|
||
class Std | ||
def ping | ||
"pong" | ||
end | ||
|
||
def say(msg = "pry rocks!") | ||
puts msg | ||
end | ||
|
||
def ask | ||
"42" == HighLine.new.ask("What is the Ultimate Answer to the Ultimate Question of Life, The Universe, and Everything? ") | ||
end | ||
end | ||
|
||
EM.run { Std.new.remote_pry_em('0.0.0.0', :auto) } |