repo.or.cz
/
ruby-svn.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
history
|
raw
|
HEAD
* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git]
/
sample
/
cbreak.rb
blob
76b534a76a1f03e9762cc94ee39f25efc3f33e76
1
# ioctl example works on Sun
2
3
CBREAK = 0x00000002
4
ECHO = 0x00000008
5
TIOCGETP = 0x40067408
6
TIOCSETP = 0x80067409
7
8
def cbreak ()
9
set_cbreak(true)
10
end
11
12
def cooked ()
13
set_cbreak(false)
14
end
15
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();
31
32
print("this is no-echo line: ");
33
readline().print
34
cooked();
35
print("this is echo line: ");
36
readline()