class CursesClient

Public Class Methods

new(opts) click to toggle source
# File tclient.rb, line 67
def initialize(opts)
  super(opts)
  Curses.init_screen
  Curses.cbreak
  Curses.noecho if @opts.echo
  Curses.nl
  Curses.stdscr.scrollok(true)
  if !$opts.win32  # Need workaround for these
    Curses.stdscr.keypad(true)
    Curses.timeout = 0
  end
  Curses.start_color
end

Public Instance Methods

conmsg(msg) click to toggle source
# File tclient.rb, line 81
def conmsg msg
  Curses.addstr(msg)
  Curses.refresh
end
run() click to toggle source
# File tclient.rb, line 103
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 F10 to QUIT"
  until shutdown
    connection.poll(0.1)
    Curses.refresh
    c = Curses.getch
    case c
    when 32..127
      publish(c.chr)
    when Curses::KEY_ENTER
      publish("\r\n")
    when 10
      publish("\n")
    when 4294967295 # Error Timeout. This is -1 in Bignum format
    when Curses::KEY_F10
      conmsg "Quitting..."
      shutdown = true
    else
      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
  Curses.close_screen
end
update(msg) click to toggle source
# File tclient.rb, line 86
def update(msg)
  case msg
  when Connection, :initdone
    super(msg)
  when :disconnected
    unsubscribe_all
    $shutdown = true
    Curses.addstr "Disconnected."
    exit
  when String
    Curses.addstr(msg)
    Curses.refresh
  else
    Curses.addstr "Unknown msg - #{msg.inspect}"
  end
end