Module: PryRemoteEm::Client::Keyboard

Defined in:
lib/pry-remote-em/client/keyboard.rb

Instance Method Summary collapse

Instance Method Details

#bufferio(enable) ⇒ Object

Makes stdin buffered or unbuffered. In unbuffered mode read and select will not wait for “n”; also will not echo characters. This probably does not work on Windows. On EventMachine < 1.0.0.beta.4 this method doesn’t do anything



36
37
38
39
40
41
42
# File 'lib/pry-remote-em/client/keyboard.rb', line 36

def bufferio(enable)
  return if !@manip_buff || (enable && @buff_enabled) || (!enable && !@buff_enabled)
  attr = Termios.getattr($stdin)
  enable ? (attr.c_lflag |= Termios::ICANON | Termios::ECHO) : (attr.c_lflag &= ~(Termios::ICANON|Termios::ECHO))
  Termios.setattr($stdin, Termios::TCSANOW, attr)
  @buff_enabled = enable
end

#initialize(c) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pry-remote-em/client/keyboard.rb', line 6

def initialize(c)
  @con            = c
  # TODO check actual current values to determine if it's enabled or not
  @buff_enabled   = true
  # On EM < 1.0.0.beta.4 the keyboard handler and Termios don't work well together
  # readline will complain that STDIN isn't a tty after Termios manipulation, so
  # just don't let it happen
  @manip_buff     = Gem.loaded_specs["eventmachine"].version >= Gem::Version.new("1.0.0.beta.4")
  bufferio(false)
  # TODO retain the old SIGINT handler and reset it later
  trap :SIGINT do
    @con.send_data({:ssc => true})
  end
end

#receive_data(d) ⇒ Object



21
22
23
# File 'lib/pry-remote-em/client/keyboard.rb', line 21

def receive_data(d)
  @con.send_data({:sd => d})
end

#unbindObject



25
26
27
28
29
30
# File 'lib/pry-remote-em/client/keyboard.rb', line 25

def unbind
  bufferio(true)
  trap :SIGINT do
    Process.exit
  end
end