Sha256: 7f48727a25cb62f15c0676b02f63235afcfd40306d516f5edd1a7d8b221f1f10

Contents?: true

Size: 731 Bytes

Versions: 7

Compression:

Stored size: 731 Bytes

Contents

module EventMachine
  module Synchrony
    class Keyboard
      attr_reader :current_fiber, :separator
      
      def gets
        @current_fiber = Fiber.current        
        EM.open_keyboard(EventMachine::Synchrony::KeyboardHandler, self)
        
        Fiber.yield
      end
    end
    
    class KeyboardHandler < EM::Connection      
      include EM::Protocols::LineText2
      
      def initialize(keyboard)
        @keyboard = keyboard
      end
          
      def receive_line(line)
        # Simulate gets by adding a trailing line feed
        @input = "#{line}#{$/}"
        
        close_connection
      end
      
      def unbind
        @keyboard.current_fiber.resume @input
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
em-synchrony-1.0.6 lib/em-synchrony/keyboard.rb
em-synchrony-1.0.5 lib/em-synchrony/keyboard.rb
em-synchrony-1.0.4 lib/em-synchrony/keyboard.rb
em-synchrony-1.0.3 lib/em-synchrony/keyboard.rb
em-synchrony-1.0.2 lib/em-synchrony/keyboard.rb
em-synchrony-1.0.1 lib/em-synchrony/keyboard.rb
em-synchrony-1.0.0 lib/em-synchrony/keyboard.rb