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?
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.
You can also use backspace characters to erase the ^C
:
trap("INT") do
puts "\b"*2 + "Shutting down..."
exit
end
© 2022 - 2024 — McMap. All rights reserved.
Closing link...
) and then omitting the 'C' :) (Still would have the^
though) – Arching