Skip to content

Commit 263f651

Browse files
Better output in revolver mode
1 parent c6cf4c8 commit 263f651

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

modules/cli/src/main/scala/scala/cli/commands/WatchUtil.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@ object WatchUtil {
1111
def waitMessage(message: String): String = {
1212
// Both short cuts actually always work, but Ctrl+C also exits mill in mill watch mode.
1313
val shortCut = if (isDevMode) "Ctrl+D" else "Ctrl+C"
14-
val gray = "\u001b[90m"
15-
val reset = Console.RESET
16-
s"$gray$message, press $shortCut to exit, or press Enter to re-run.$reset"
14+
gray(s"$message, press $shortCut to exit, or press Enter to re-run.")
15+
}
16+
17+
private def gray(message: String): String = {
18+
val gray = "\u001b[90m"
19+
val reset = Console.RESET
20+
s"$gray$message$reset"
1721
}
1822

1923
def printWatchMessage(): Unit =
2024
System.err.println(waitMessage("Watching sources"))
2125

26+
def printWatchWhileRunningMessage(): Unit =
27+
System.err.println(gray("Watching sources while your program is running."))
28+
2229
def waitForCtrlC(
2330
onPressEnter: () => Unit = () => (),
2431
shouldReadInput: () => Boolean = () => true

modules/cli/src/main/scala/scala/cli/commands/run/Run.scala

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,22 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
152152
val onExitProcess = process.onExit().thenApply { p1 =>
153153
val retCode = p1.exitValue()
154154
onExitOpt.foreach(_())
155-
if (retCode != 0)
156-
if (allowTerminate)
155+
(retCode, allowTerminate) match {
156+
case (0, true) =>
157+
case (0, false) =>
158+
val gray = "\u001b[90m"
159+
val reset = Console.RESET
160+
System.err.println(s"${gray}Program exited with return code $retCode.$reset")
161+
case (_, true) =>
157162
sys.exit(retCode)
158-
else {
163+
case (_, false) =>
159164
val red = Console.RED
160165
val lightRed = "\u001b[91m"
161166
val reset = Console.RESET
162167
System.err.println(
163168
s"${red}Program exited with return code $lightRed$retCode$red.$reset"
164169
)
165-
}
170+
}
166171
}
167172

168173
Some((process, onExitProcess))
@@ -207,7 +212,11 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
207212
buildTests = false,
208213
partial = None,
209214
actionableDiagnostics = actionableDiagnostics,
210-
postAction = () => WatchUtil.printWatchMessage()
215+
postAction = () =>
216+
if (processOpt.exists(_._1.isAlive()))
217+
WatchUtil.printWatchWhileRunningMessage()
218+
else
219+
WatchUtil.printWatchMessage()
211220
) { res =>
212221
for ((process, onExitProcess) <- processOpt) {
213222
onExitProcess.cancel(true)

0 commit comments

Comments
 (0)