Improve sbtn a bit

1. Remove experimental warning.
2. Buffer the boot log so ANSI output is fixed for JVM client.
3. Remove timestamp.
This commit is contained in:
Eugene Yokota 2025-08-24 03:57:16 -04:00
parent e70a526ef2
commit ff328a092d
2 changed files with 24 additions and 15 deletions

View File

@ -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"

View File

@ -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