-
-
Save raggi/563769 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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