def start(options = {})
__init(options)
restore_history
EM.run do
Thread.start do
while buf = Readline.readline(config[:prompt], true)
unless Readline::HISTORY.count == 1
Readline::HISTORY.pop if buf.empty? || Readline::HISTORY[-1] == Readline::HISTORY[-2]
end
sync {
reload
store_history
input(buf.strip)
}
end
stop
end
EM.add_periodic_timer(config[:output_interval]) do
if @last_data_received_at && Time.now - @last_data_received_at > config[:no_data_timeout]
begin
reconnect
rescue EventMachine::ConnectionError => e
end
end
if Readline.line_buffer.nil? || Readline.line_buffer.empty?
sync { output }
end
end
reconnect unless options['no-stream''no-stream'] == true
trap('INT') { stop }
end
end