sbt/sbt — pull request #833 by jroper (2013-07-30 09:03:33+00:00)
Title: Ensure terminal is restored when user presses Ctrl+C

In Boot.scala, jline shutdown hooks are disabled, because it causes classloader leaks. Indeed, if Terminal.init() is invoked multiple times, without calling restore in between, such a classloader leak will happen (but this should probably be fixed in jline). But we need to call init multiple times because this does platform specific initing of the console, and it may not be inited from a previous use that restored it.

We are careful to always restore the terminal in a finally block, however finally blocks don't get executed when the JVM receives a TERM signal (eg, when a user presses Ctrl+C). This means that the terminal could be left with echo off. The only way to execute code to reset the terminal when TERM is received is using a shutdown hook.

This change adds a shutdown hook, and removes it in a finally block to prevent classloader leaks. It won't prevent against accidentally forgetting to restore the terminal after using it, but it will ensure that the terminal is restored when the user presses Ctrl+C.