class ConsoleClient

Public Class Methods

new(opts) click to toggle source
# File tclient.rb, line 141
def initialize(opts)
  super(opts)
  system('stty cbreak -echo') if !@opts.win32 && @opts.echo
end

Public Instance Methods

conmsg(msg) click to toggle source
# File tclient.rb, line 146
def conmsg msg
  puts msg
end
run() click to toggle source
# File tclient.rb, line 166
  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 # Windows F10
        conmsg "Quitting..."
        shutdown = true
#      when 27 # xterm F10
#        if getkey == 91 && getkey == 50 && getkey == 49 && getkey == 126
#          conmsg "Quitting..."
#          shutdown = true
#        end

      when 338  # INS
        publish("\e[2~")
      when 339  # DEL
        publish("\0010")
      when 327  # HOME
        publish("\e[7~")
      when 335  # END
        publish("\e[8~")
      when 329  # PAGEUP
        publish("\e[5~")
      when 337  # PAGEDOWN
        publish("\e[6~")
      when 328  # UP
        publish("\e[A")
      when 336  # DOWN
        publish("\e[B")
      when 333  # RIGHT
        publish("\e[C")
      when 331  # LEFT
        publish("\e[D")


      when 256..512
        conmsg "Unknown key hit code - #{c.inspect}"
      else
        publish(c.chr)
#        conmsg "Unknown key hit code - #{c.inspect}"
      end
    end # until
    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
update(msg) click to toggle source
# File tclient.rb, line 150
def update(msg)
  case msg
  when Connection, :initdone
    super(msg)
  when :disconnected
    unsubscribe_all
    $shutdown = true
    puts "Disconnected."
    exit
  when String
    print msg
  else
    puts "Unknown msg - #{msg.inspect}"
  end
end