Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby - Hide "^C" on Interrupt

Tags:

ruby

interrupt

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?

like image 859
knpwrs Avatar asked Mar 20 '12 21:03

knpwrs


2 Answers

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.

like image 63
Kyle Jones Avatar answered Oct 30 '22 12:10

Kyle Jones


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.

like image 29
xolox Avatar answered Oct 30 '22 11:10

xolox