Created
April 23, 2014 07:37
-
-
Save jimfoltz/11205794 to your computer and use it in GitHub Desktop.
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
require 'socket' | |
require 'nokogiri' | |
require 'nori' | |
require 'pp' | |
SETTINGS = "C:/ProgramData/SketchUp/RubyDebugger.settings" | |
def main | |
@parser = Nori.new | |
@bps = [] | |
print "> " | |
while line = gets | |
if line[/^help/] | |
puts "/connect" | |
puts "/disconnect" | |
puts "/load" | |
puts "/quit" | |
elsif line[/^\/connect$/] | |
connect() | |
next | |
elsif line[/^\/disconnect$/] | |
disconnect() | |
print "> " | |
next | |
elsif line[/^\/load/] | |
p @parser.parse(File.read(SETTINGS)) | |
puts | |
next | |
elsif line[/^\/b$/] | |
write_break_points() | |
next | |
elsif line[/^\/quit$/] | |
break | |
else | |
send(line) | |
rec() | |
end | |
print "> " | |
end # while | |
rescue => e | |
p e | |
puts e.backtrace.join("\n") | |
@s.close | |
end | |
def connect | |
@s = TCPSocket.open('localhost', 1234) | |
p @s | |
print "Connected.\n> " | |
end | |
def disconnect | |
@s.close | |
p @s | |
end | |
def send(msg) | |
puts "send: #{msg.inspect}" | |
@s.write(msg) | |
end | |
def rec(t = 0.2) | |
ready = IO.select([@s], nil, nil, t) | |
if ready | |
puts "Debugger(" | |
res = ready[0][0].recvfrom(4096) | |
puts decode_xml(res[0]) | |
puts ")" | |
h = @parser.parse(res[0]) | |
pp h | |
if h['breakpointAdded'] | |
@bps << h['breakpointAdded'] | |
end | |
else | |
#puts "timeout." | |
end | |
end | |
def decode_xml(xml) | |
xml.gsub!('<', '<') | |
xml.gsub!('>', '>') | |
xml | |
end | |
def write_break_points | |
@bps.each do |bp| | |
p bp | |
end | |
end | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment