File tree Expand file tree Collapse file tree 7 files changed +29
-16
lines changed
modules/cli/src/main/scala/scala/cli/commands Expand file tree Collapse file tree 7 files changed +29
-16
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ object Compile extends ScalaCommand[CompileOptions] with BuildCommandHelpers {
97
97
for (builds <- res.orReport(logger))
98
98
postBuild(builds, allowExit = false )
99
99
}
100
- try WatchUtil .waitForCtrlC()
100
+ try WatchUtil .waitForCtrlC(() => watcher.schedule() )
101
101
finally watcher.dispose()
102
102
}
103
103
else {
Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ object Package extends ScalaCommand[PackageOptions] with BuildCommandHelpers {
104
104
System .err.println(" Build cancelled" )
105
105
}
106
106
}
107
- try WatchUtil .waitForCtrlC()
107
+ try WatchUtil .waitForCtrlC(() => watcher.schedule() )
108
108
finally watcher.dispose()
109
109
}
110
110
else {
Original file line number Diff line number Diff line change @@ -126,17 +126,23 @@ object Repl extends ScalaCommand[ReplOptions] {
126
126
127
127
if (inputs.isEmpty) {
128
128
val artifacts = initialBuildOptions.artifacts(logger, Scope .Main ).orExit(logger)
129
- doRunRepl(
130
- initialBuildOptions,
131
- artifacts,
132
- None ,
133
- allowExit = ! options.sharedRepl.watch.watchMode,
134
- buildOpt = None
135
- )
129
+ // synchronizing, so that multiple presses to enter (handled by WatchUtil.waitForCtrlC)
130
+ // don't try to run repls in parallel
131
+ val lock = new Object
132
+ def runThing () = lock.synchronized {
133
+ doRunRepl(
134
+ initialBuildOptions,
135
+ artifacts,
136
+ None ,
137
+ allowExit = ! options.sharedRepl.watch.watchMode,
138
+ buildOpt = None
139
+ )
140
+ }
141
+ runThing()
136
142
if (options.sharedRepl.watch.watchMode) {
137
143
// nothing to watch, just wait for Ctrl+C
138
144
WatchUtil .printWatchMessage()
139
- WatchUtil .waitForCtrlC()
145
+ WatchUtil .waitForCtrlC(() => runThing() )
140
146
}
141
147
}
142
148
else if (options.sharedRepl.watch.watchMode) {
@@ -159,7 +165,7 @@ object Repl extends ScalaCommand[ReplOptions] {
159
165
case _ : Build .Cancelled => buildCancelled(allowExit = false )
160
166
}
161
167
}
162
- try WatchUtil .waitForCtrlC()
168
+ try WatchUtil .waitForCtrlC(() => watcher.schedule() )
163
169
finally watcher.dispose()
164
170
}
165
171
else {
Original file line number Diff line number Diff line change @@ -230,7 +230,7 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
230
230
System .err.println(" Compilation failed" )
231
231
}
232
232
}
233
- try WatchUtil .waitForCtrlC()
233
+ try WatchUtil .waitForCtrlC(() => watcher.schedule() )
234
234
finally watcher.dispose()
235
235
}
236
236
else {
Original file line number Diff line number Diff line change @@ -137,7 +137,7 @@ object Test extends ScalaCommand[TestOptions] {
137
137
for (builds <- res.orReport(logger))
138
138
maybeTest(builds, allowExit = false )
139
139
}
140
- try WatchUtil .waitForCtrlC()
140
+ try WatchUtil .waitForCtrlC(() => watcher.schedule() )
141
141
finally watcher.dispose()
142
142
}
143
143
else {
Original file line number Diff line number Diff line change @@ -17,7 +17,14 @@ object WatchUtil {
17
17
def printWatchMessage (): Unit =
18
18
System .err.println(waitMessage(" Watching sources" ))
19
19
20
- def waitForCtrlC (): Unit =
21
- while (System .in.read() != - 1 ) {}
20
+ def waitForCtrlC (onPressEnter : () => Unit = () => ()): Unit = {
21
+ var readKey = - 1
22
+ while ({
23
+ readKey = System .in.read()
24
+ readKey != - 1
25
+ })
26
+ if (readKey == '\n ' )
27
+ onPressEnter()
28
+ }
22
29
23
30
}
Original file line number Diff line number Diff line change @@ -276,7 +276,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
276
276
)
277
277
}
278
278
}
279
- try WatchUtil .waitForCtrlC()
279
+ try WatchUtil .waitForCtrlC(() => watcher.schedule() )
280
280
finally watcher.dispose()
281
281
}
282
282
else {
You can’t perform that action at this time.
0 commit comments