diff --git a/build.sbt b/build.sbt index 47c94aebd..b6524d72d 100644 --- a/build.sbt +++ b/build.sbt @@ -11,7 +11,7 @@ import scala.util.Try // ThisBuild settings take lower precedence, // but can be shared across the multi projects. ThisBuild / version := { - val v = "1.11.1-SNAPSHOT" + val v = "1.11.5-SNAPSHOT" nightlyVersion.getOrElse(v) } ThisBuild / version2_13 := "2.0.0-SNAPSHOT" diff --git a/main-command/src/main/scala/sbt/internal/client/NetworkClient.scala b/main-command/src/main/scala/sbt/internal/client/NetworkClient.scala index 6bc13337f..551e5c2b8 100644 --- a/main-command/src/main/scala/sbt/internal/client/NetworkClient.scala +++ b/main-command/src/main/scala/sbt/internal/client/NetworkClient.scala @@ -432,6 +432,7 @@ class NetworkClient( start() override def run(): Unit = { try { + val buffer = mutable.ArrayBuffer.empty[Byte] while (readThreadAlive.get) { if (socket.isEmpty) { socket = Try(ClientSocket.localSocket(bootSocketName, useJNI)).toOption @@ -447,7 +448,12 @@ class NetworkClient( case 3 if gotInputBack => // ETX: end of text readThreadAlive.set(false) case i if gotInputBack => stdinBytes.offer(i) - case i => printStream.write(i) + case 10 => // CR + buffer.append(10) + printStream.write(buffer.toArray[Byte]) + buffer.clear() + case i => + buffer.append(i.toByte) } } catch { case e @ (_: IOException | _: InterruptedException) => @@ -572,7 +578,7 @@ class NetworkClient( case null => () case (q, startTime, name) => val now = System.currentTimeMillis - val message = NetworkClient.timing(startTime, now) + val message = NetworkClient.elapsedString(startTime, now) if (batchMode.get || !attached.get) { if (exitCode == 0) console.success(message) else console.appendLog(Level.Error, message) @@ -862,8 +868,7 @@ class NetworkClient( } } - def connect(log: Boolean, promptCompleteUsers: Boolean): Boolean = { - if (log) console.appendLog(Level.Info, "entering *experimental* thin client - BEEP WHIRR") + def connect(promptCompleteUsers: Boolean): Boolean = try { init(promptCompleteUsers, retry = true) true @@ -872,7 +877,6 @@ class NetworkClient( console.appendLog(Level.Error, "failed to connect to server") false } - } private[this] val contHandler: () => Unit = () => { if (Terminal.console.getLastLine.nonEmpty) @@ -913,9 +917,8 @@ class NetworkClient( catch { case _: InterruptedException => } if (exitClean.get) 0 else 1 } - console.appendLog(Level.Info, "terminate the server with `shutdown`") if (interactive) { - console.appendLog(Level.Info, "disconnect from the server with `exit`") + console.appendLog(Level.Info, "terminate the server with `shutdown`") block() } else if (exit) 0 else { @@ -927,8 +930,7 @@ class NetworkClient( } def batchExecute(userCommands: List[String]): Int = { - val cmd = userCommands mkString " " - printStream.println("> " + cmd) + val cmd = userCommands.mkString(" ") sendAndWait(cmd, None) } @@ -1230,8 +1232,16 @@ object NetworkClient { // Which sometimes becomes garbled in standard output // Therefore we replace NNBSP (u202f) with standard space (u0020) val nowString = format.format(new Date(endTime)).replace("\u202F", "\u0020") + val totalString = elapsedStr(startTime, endTime) + s"Total time: $totalString, completed $nowString" + } + + def elapsedString(startTime: Long, endTime: Long): String = + s"elapsed: ${elapsedStr(startTime, endTime)}" + + private def elapsedStr(startTime: Long, endTime: Long): String = { val total = (endTime - startTime + 500) / 1000 - val totalString = s"$total s" + + s"$total s" + (if (total <= 60) "" else { val hours = total / 3600 match { @@ -1242,7 +1252,6 @@ object NetworkClient { val secs = f"${total % 60}%02d" s" ($hours:$mins:$secs.0)" }) - s"Total time: $totalString, completed $nowString" } private[sbt] def timing(startTime: Long, endTime: Long): String = { @@ -1267,7 +1276,7 @@ object NetworkClient { useJNI, ) try { - if (client.connect(log = true, promptCompleteUsers = false)) client.run() + if (client.connect(promptCompleteUsers = false)) client.run() else 1 } catch { case _: Exception => 1 } finally client.close() } @@ -1297,7 +1306,7 @@ object NetworkClient { client.connectOrStartServerAndConnect(promptCompleteUsers = false, retry = true) BspClient.bspRun(socket) } else { - if (client.connect(log = true, promptCompleteUsers = false)) client.run() + if (client.connect(promptCompleteUsers = false)) client.run() else 1 } } catch { case _: Exception => 1 } finally client.close() @@ -1394,7 +1403,7 @@ object NetworkClient { ) try { val results = - if (client.connect(log = false, promptCompleteUsers = true)) client.getCompletions(cmd) + if (client.connect(promptCompleteUsers = true)) client.getCompletions(cmd) else Nil out.println(results.sorted.distinct mkString "\n") 0