Is there a way to run a ruby script and while executing commands in the script ,still respond to key stroke ?
I want to run a ruby script but be able to press “Space” and pause the script (after currently running command executes ), and then press “Space” again and resume the script .
My only idea (and im sure its a weird one) , is to open a new thread and wait for key strokes there ,
then when ill get a key stroke , set a stop_flag.
Only now it looks like i need to be checking this flag after each command to know when to stop.
You can use a signal to turn debug output on and off at will, if you have a logger set up with appropriate code sprinkled throughout your script:
The forking and SIGCLD trapping is to make the example fit into one file; any process may send a signal to another.
The code inside the fork block is your script. The script sets up a logger with a default log level of INFO, and a handler for the SIGUSR1 signal that toggles the logger between DEBUG and INFO levels.
The stuff outside of the fork block is just an example of sending a signal to another process. Pressing ENTER will send the signal and alter the logging level of the other process.
This works on POSIX systems, I have no idea about Windows.