mirror of https://github.com/sbt/sbt.git
Add signal registration in LineReader
It is possible for the signal handler to get in a state where it has no effect in the shell. When this happens, entering ctrl+c does not exit the shell. To ensure that ctrl+c always exits the shell, we can register a signal handler in the line reader that write -1 to the terminal input stream, which should cause the line reader to return an exit command.
This commit is contained in:
parent
c24e7da844
commit
90ca463c70
|
|
@ -121,6 +121,10 @@ object LineReader {
|
|||
// ignore
|
||||
}
|
||||
historyPath.foreach(f => reader.setVariable(JLineReader.HISTORY_FILE, f))
|
||||
val signalRegistration = terminal match {
|
||||
case _: Terminal.ConsoleTerminal => Some(Signals.register(() => terminal.write(-1)))
|
||||
case _ => None
|
||||
}
|
||||
try terminal.withRawInput {
|
||||
Option(mask.map(reader.readLine(prompt, _)).getOrElse(reader.readLine(prompt)))
|
||||
} catch {
|
||||
|
|
@ -132,6 +136,7 @@ object LineReader {
|
|||
_: UncheckedIOException =>
|
||||
throw new InterruptedException
|
||||
} finally {
|
||||
signalRegistration.foreach(_.remove())
|
||||
terminal.prompt.reset()
|
||||
term.close()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue