In Ruby I have the following:
# Trap Interrupts
trap("INT") do
puts "Shutting down..."
exit
end
When I interrupt the program, the following is printed (Mac OSX Lion):
^CShutting down...
Is there any way to hide ^C
from within Ruby?
Whether control characters are echoed is a property of the tty you're using. stty -echoctl
is the Unix way to disable echoing of control characters. You can run this command from within your Ruby script and achieve the same effect if you're using a Unix-ish system.
I've found that in my Python programs on Linux and Mac OS X terminals I can hide the ^C by starting the message with a carriage return (\r). It feels like a hack but it works just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With