Skip to content

Instantly share code, notes, and snippets.

@erikh
Created September 3, 2010 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save erikh/563768 to your computer and use it in GitHub Desktop.
Save erikh/563768 to your computer and use it in GitHub Desktop.
require 'eventmachine'
require 'kconv'
class BBSTerm < EM::Connection
def post_init
@read_buffer = ""
@initialization = true
end
def receive_data(data)
@read_buffer << data.force_encoding("IBM437").toutf8
if @initialization and @read_buffer =~ /\e\[6n/
@initialization = false
send_data "\e[1A\r\n"
end
@read_buffer.gsub!(/\r\n/, "\n")
print @read_buffer
@read_buffer = ""
end
end
class STDINReader < EM::Connection
def receive_data(data)
my_data = data.encode("IBM437", "UTF-8")
my_data.gsub!(/\n/, "\r\n")
EM.next_tick { $obj.send_data(my_data) }
end
end
EM.run do
$obj = EM.connect("bbs.hollensbe.org", 3000, BBSTerm)
EM.attach($stdin, STDINReader)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment