Skip to content

Instantly share code, notes, and snippets.

@jimfoltz
Created April 23, 2014 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimfoltz/11205794 to your computer and use it in GitHub Desktop.
Save jimfoltz/11205794 to your computer and use it in GitHub Desktop.
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!('&lt;', '<')
xml.gsub!('&gt;', '>')
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