def run
shutdown = false
connection = Reactor.new(@opts.port, $conntype, $connio, $connopts,
$connfilters, @opts.address)
raise "Unable to start TeensyClient" unless connection.start(self)
conmsg "Connected to #{@opts.address}:#{@opts.port}. Use CTL-C to QUIT"
until shutdown
connection.poll(0.1)
c = getkey
case c
when nil
when 32..127
publish(c.chr)
when 13
publish("\n") if @opts.win32
when 10
publish("\n") if !@opts.win32
when 315
publish("\e[11~")
when 316
publish("\e[12~")
when 317
publish("\e[13~")
when 318
publish("\e[14~")
when 319
publish("\e[15~")
when 320
publish("\e[17~")
when 321
publish("\e[18~")
when 322
publish("\e[19~")
when 323
publish("\e[20~")
when 324
conmsg "Quitting..."
shutdown = true
when 338
publish("\e[2~")
when 339
publish("\0010")
when 327
publish("\e[7~")
when 335
publish("\e[8~")
when 329
publish("\e[5~")
when 337
publish("\e[6~")
when 328
publish("\e[A")
when 336
publish("\e[B")
when 333
publish("\e[C")
when 331
publish("\e[D")
when 256..512
conmsg "Unknown key hit code - #{c.inspect}"
else
publish(c.chr)
end
end
connection.stop
rescue SystemExit, Interrupt
conmsg "\nConnection closed exiting"
rescue Exception
conmsg "\nException caught error in client: " + $!
conmsg $@
ensure
system('stty -cbreak echo') if !@opts.win32 && @opts.echo
end