File tree Expand file tree Collapse file tree 2 files changed +24
-8
lines changed
modules/cli/src/main/scala/scala/cli/commands Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -11,14 +11,21 @@ object WatchUtil {
11
11
def waitMessage (message : String ): String = {
12
12
// Both short cuts actually always work, but Ctrl+C also exits mill in mill watch mode.
13
13
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"
17
21
}
18
22
19
23
def printWatchMessage (): Unit =
20
24
System .err.println(waitMessage(" Watching sources" ))
21
25
26
+ def printWatchWhileRunningMessage (): Unit =
27
+ System .err.println(gray(" Watching sources while your program is running." ))
28
+
22
29
def waitForCtrlC (
23
30
onPressEnter : () => Unit = () => (),
24
31
shouldReadInput : () => Boolean = () => true
Original file line number Diff line number Diff line change @@ -152,17 +152,22 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
152
152
val onExitProcess = process.onExit().thenApply { p1 =>
153
153
val retCode = p1.exitValue()
154
154
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 ) =>
157
162
sys.exit(retCode)
158
- else {
163
+ case (_, false ) =>
159
164
val red = Console .RED
160
165
val lightRed = " \u001b [91m"
161
166
val reset = Console .RESET
162
167
System .err.println(
163
168
s " ${red}Program exited with return code $lightRed$retCode$red. $reset"
164
169
)
165
- }
170
+ }
166
171
}
167
172
168
173
Some ((process, onExitProcess))
@@ -207,7 +212,11 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
207
212
buildTests = false ,
208
213
partial = None ,
209
214
actionableDiagnostics = actionableDiagnostics,
210
- postAction = () => WatchUtil .printWatchMessage()
215
+ postAction = () =>
216
+ if (processOpt.exists(_._1.isAlive()))
217
+ WatchUtil .printWatchWhileRunningMessage()
218
+ else
219
+ WatchUtil .printWatchMessage()
211
220
) { res =>
212
221
for ((process, onExitProcess) <- processOpt) {
213
222
onExitProcess.cancel(true )
You can’t perform that action at this time.
0 commit comments