Hello, just looking for a way to do character-at-a-time input in Ruby.
Is there an interface to termios, or a higher-level module that abstracts
such system-dependent details?
-Mark
Hello, just looking for a way to do character-at-a-time input in Ruby.
Is there an interface to termios, or a higher-level module that abstracts
such system-dependent details?
-Mark
Well, I don’t know how useful this is, but here’s an extension
that wraps the POSIX termios structure. With it, you can enable
cbreak mode (character-at-a-time input) in a way that mirrors
C usage:
require 'termios'
t = $stdin.getattr
t.lflag &= ~Termios::ICANON
$stdin.setattr(0, t)
After which, $stdin.getc will return the next key pressed without waiting
for a newline, at least on a UNIX system.
-Mark
termios.c (12.1 KB)
extconf.rb (42 Bytes)