tclient.rb

Path: tclient.rb
Last Update: Sat Mar 18 09:16:52 -0400 2006
Client
CursesClient
ConsoleClient
Publisher
dot/f_4.png
file:tclient.rb
author:Jon A. Lambert
version:2.8.0
date:01/19/2006

This source code copyright (C) 2005, 2006 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

Required files

pp   network/reactor   optparse   ostruct   curses   Win32API  

Methods

get_options   getkey   getkey  

Constants

Version = "0.2.0"
BANNER = <<-EOH This is TeensyClient version #{Version} Copyright (C) 2005, 2006 by Jon A. Lambert Released under the terms of the TeensyMUD Public License EOH
Kbhit = Win32API.new("msvcrt", "_kbhit", [], 'I')
Getch = Win32API.new("msvcrt", "_getch", [], 'I')

Public Instance methods

[Source]

# File tclient.rb, line 257
def get_options
  # parse options
  begin
    # The myopts specified on the command line will be collected in *myopts*.
    # We set default values here.
    myopts = OpenStruct.new
    myopts.port = 4000
    myopts.address = 'localhost'
    myopts.curses = false
    myopts.echo = false
    myopts.verbose = false
    myopts.trace = false
    RUBY_PLATFORM =~ /win32/ ? myopts.win32 = true : myopts.win32 = false

    opts = OptionParser.new do |opts|
      opts.banner = BANNER
      opts.separator ""
      opts.separator "Usage: ruby #{$0} [options]"
      opts.separator ""
      opts.on("-p", "--port PORT", Integer,
        "Select the port of the mud",
        "  (defaults to 4000)") {|myopts.port|}
      opts.on("-a", "--address URL", String,
        "Select the address of the mud",
        "  (defaults to \'localhost\')") {|myopts.address|}
      opts.on("-e", "--[no-]echo", "Run in server echo mode") {|myopts.echo|}
      opts.on("-t", "--[no-]trace", "Trace execution") {|myopts.trace|}
      opts.on("-c", "--[no-]curses", "Run with curses support") {|myopts.curses|}
      opts.on("-v", "--[no-]verbose", "Run verbosely") {|myopts.verbose|}
      opts.on_tail("-h", "--help", "Show this message") do
        $stdout.puts opts.help
        exit
      end
      opts.on_tail("--version", "Show version") do
        $stdout.puts "TeensyClient #{Version}"
        exit
      end
    end

    opts.parse!(ARGV)

    return myopts
  rescue OptionParser::ParseError
    $stderr.puts "ERROR - #{$!}"
    $stderr.puts "For help..."
    $stderr.puts " ruby #{$0} --help"
    exit
  end
end

[Source]

# File tclient.rb, line 328
    def getkey
      sleep 0.01
      return nil if Kbhit.call.zero?
      c = Getch.call
      c = Getch.call + 256 if c.zero? || c == 0xE0
      c
    end

[Source]

# File tclient.rb, line 336
    def getkey
      select( [$stdin], nil, nil, 0.01 ) ?  c = $stdin.getc : c = nil
    end

[Validate]