From 90ca463c700567b751c6bf6d13fb6946abe16928 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Wed, 25 Nov 2020 14:03:10 -0800 Subject: [PATCH] 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. --- .../src/main/scala/sbt/internal/util/LineReader.scala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/util-complete/src/main/scala/sbt/internal/util/LineReader.scala b/internal/util-complete/src/main/scala/sbt/internal/util/LineReader.scala index aa022d3bb..ef1a345b2 100644 --- a/internal/util-complete/src/main/scala/sbt/internal/util/LineReader.scala +++ b/internal/util-complete/src/main/scala/sbt/internal/util/LineReader.scala @@ -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() }