I’d also like to know if there is a way to trap the
user pressing Ctrl-C
and do some stuff before closing ?
you should use something like
trap “SIGINT” { block_to_do (some, stuff)}
^C in unix sends SIGINT , tipically.
You could even try
at_exit { endBlock }
In this way you’ll have endBlock anyway.
I suppose that trap SIGINT won’t work in dos, but you
could do something like this to check if the program
actually ended or had been interrupted
#start
#good end
$ended=TRUE
at_exit {
unless $ended
<interrupted, exception…>
end
}
If we implemented a cross-platform “keypressed”, might there be
any chance of it getting into the builtin library?
A frequent beginner C/C++ FAQ is the one above. It seems like a
high-level language such as ruby should be able to give a good
solution to it, rather than a lengthy answer involving Win32 API
or Termios witchery.
I’m looking for an equivalent to pascal’s old keypressed.
I’m trying to execute a block till the user presses a key, something like :
while (!keypressed)
print “.”
end
Is there any such functionality ?
If we implemented a cross-platform “keypressed”, might there be
any chance of it getting into the builtin library?
A frequent beginner C/C++ FAQ is the one above. It seems like a
high-level language such as ruby should be able to give a good
solution to it, rather than a lengthy answer involving Win32 API
or Termios witchery.
select[[$stdin], nil, nil]
if key_pressed() does not allow mixing with select(), it lost its efficiency.
^ There’s the problem. Surely something could be worked out for
Windows, too. However, expecting individual programmers to
reinvent those wheels is a violation of the DRY principle.
I think it would be handy to have key_pressed, or preferably
“getch”, as a part of the standard library.
If we implemented a cross-platform “keypressed”, might there be
any chance of it getting into the builtin library?
A frequent beginner C/C++ FAQ is the one above. It seems like a
high-level language such as ruby should be able to give a good
solution to it, rather than a lengthy answer involving Win32 API
or Termios witchery.
select[[$stdin], nil, nil]
if key_pressed() does not allow mixing with select(), it lost its efficiency.
If we implemented a cross-platform “keypressed”, might there be
any chance of it getting into the builtin library?
A frequent beginner C/C++ FAQ is the one above. It seems like a
high-level language such as ruby should be able to give a good
solution to it, rather than a lengthy answer involving Win32 API
or Termios witchery.
select[[$stdin], nil, nil]
if key_pressed() does not allow mixing with select(), it lost its
efficiency.
disclaimer: unlikely to work on Win*
^ There’s the problem. Surely something could be worked out for
Windows, too. However, expecting individual programmers to
reinvent those wheels is a violation of the DRY principle.
I think it would be handy to have key_pressed, or preferably
“getch”, as a part of the standard library.
I could be wrong, though.
I think I’m generally in favor of this kind of thing,
but I’d like it to be isolated in some kind of “OS-
sensitive” library.
It’s likely to be implemented differently on every
different OS, not just Win and *nix.
I’m not sure how much of that it’s appropriate to reveal
to the coder and how much to conceal.
The old fork() that worked under Cygwin is a case in point.
Should we have a fork() on Win32 that perhaps calls
CreateProcess? Or should we just not even pretend that
Win is anything like *nix? Many of the file operations
work transparently between the two. Where do you draw
the line?
Hal
···
----- Original Message -----
From: “Ryan King” rking@panoptic.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, September 10, 2002 4:14 PM
Subject: Re: Equivalent of pascal’s keypressed ?