def read_char
system "stty raw -echo"
STDIN.getc
ensure
system "stty -raw echo"
end
good luck
Might be better to use Termios or Curses, though.
--
Posted via http://www.ruby-forum.com/.
> Nguyen Huu Bach wrote:
>> This is a simple way to achieve that. Maybe there are others
>>
>> def read_char
> # Save previous state
> old = `stty -g`
>> system "stty raw -echo"
>> STDIN.getc
>> ensure
> system "stty #{old}"
>> end
>>
>> good luck
>
> Might be better to use Termios or Curses, though.
Or use HighLine which handles all these details for you.
James Edward Gray II
Nguyen Huu Bach wrote:
> def read_char
> system "stty raw -echo" STDIN.getc ensure system "stty -raw echo"
> end
Won't work on Windows.
The sooner everybody on Earth to switches to *nix, the sooner we can
stop worrying about these silly little differences. :)