* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / sample / cbreak.rb
blob76b534a76a1f03e9762cc94ee39f25efc3f33e76
1 # ioctl example works on Sun
3 CBREAK = 0x00000002
4 ECHO = 0x00000008
5 TIOCGETP = 0x40067408
6 TIOCSETP = 0x80067409
8 def cbreak ()
9   set_cbreak(true)
10 end
12 def cooked ()
13   set_cbreak(false)
14 end
16 def set_cbreak (on)
17   tty = "\0" * 256
18   STDIN.ioctl(TIOCGETP, tty)
19   ttys = tty.unpack("C4 S")
20   if on
21     ttys[4] |= CBREAK
22     ttys[4] &= ~ECHO
23   else
24     ttys[4] &= ~CBREAK
25     ttys[4] |= ECHO
26   end
27   tty = ttys.pack("C4 S")
28   STDIN.ioctl(TIOCSETP, tty)
29 end
30 cbreak();
32 print("this is no-echo line: ");
33 readline().print
34 cooked();
35 print("this is echo line: ");
36 readline()