Merge pull request #6000 from eatkins/canonical-ctrl-d

Handle ctrl+d in canonical mode
This commit is contained in:
eugene yokota 2020-10-20 22:58:50 -04:00 committed by GitHub
commit d1ff067d54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 5 deletions

View File

@ -450,12 +450,16 @@ object Terminal {
private[sbt] class WriteableInputStream(in: InputStream, name: String)
extends SimpleInputStream
with AutoCloseable {
private[this] val isRaw = new AtomicBoolean(false)
final def write(bytes: Int*): Unit = readThread.synchronized {
bytes.foreach(b => buffer.put(b))
}
def setRawMode(toggle: Boolean): Unit = in match {
case win: WindowsInputStream => win.setRawMode(toggle)
case _ =>
def setRawMode(toggle: Boolean): Unit = {
isRaw.set(toggle)
in match {
case win: WindowsInputStream => win.setRawMode(toggle)
case _ =>
}
}
private[this] val executor =
Executors.newSingleThreadExecutor(r => new Thread(r, s"sbt-$name-input-reader"))
@ -479,8 +483,8 @@ object Terminal {
val _ = readQueue.take
val b = in.read
buffer.put(b)
if (b != -1 && !Thread.interrupted()) impl()
else closed.set(true)
if (Thread.interrupted() || (b != -1 && !isRaw.get)) closed.set(true)
else impl()
}
try impl()
catch { case _: InterruptedException => closed.set(true) }