Skip to content

Instantly share code, notes, and snippets.

@raggi
Forked from erikh/bbsterm.rb
Created September 3, 2010 11:26
Show Gist options
  • Save raggi/563769 to your computer and use it in GitHub Desktop.
Save raggi/563769 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 initialize(term)
@term = term
end
def receive_data(data)
my_data = data.encode("IBM437", "UTF-8")
my_data.gsub!(/\n/, "\r\n")
EM.next_tick { @term.send_data(my_data) }
end
end
EM.run do
term = EM.connect("bbs.hollensbe.org", 3000, BBSTerm)
EM.attach($stdin, STDINReader, term)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment