Skip to content

Instantly share code, notes, and snippets.

@dtinth
Created June 12, 2013 13:48
Show Gist options
  • Save dtinth/5765419 to your computer and use it in GitHub Desktop.
Save dtinth/5765419 to your computer and use it in GitHub Desktop.
require 'pty'
require 'io/console'
STDIN.raw do
File.open('keylog.txt', 'a') do |log|
PTY.spawn('vim wtf') do |r, w, pid|
w.winsize = STDIN.winsize
rs = { STDIN => w, r => STDOUT }
rs.compare_by_identity
loop do
x = IO.select(rs.keys)
if x
x[0].each do |io|
data = io.read_nonblock(4096)
rs[io].write(data)
if io == STDIN
log.write(data)
log.flush
end
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment