Skip to content

Instantly share code, notes, and snippets.

@andyl
Created July 6, 2011 01:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyl/1066360 to your computer and use it in GitHub Desktop.
Save andyl/1066360 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'faye'
abort "Usage: #{$0} <url> <channel> <nick>" if ARGV.length != 3
$url, $channel, $nick = ARGV
$client = Faye::Client.new($url)
trap(:INT) { EM.stop_event_loop }
def printmsg(text) print text; STDOUT.flush; end
module KeyboardInput
include EM::Protocols::LineText2
def receive_line(message)
$client.publish($channel, "#{$nick}: #{message}")
end
end
puts "Starting chat client, ^C to exit..."
printmsg "#{$nick}> "
EM.run do
$client.subscribe($channel) { |message| printmsg "\n#{message}\n#{$nick}> "}
EM.open_keyboard(KeyboardInput)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment