Commit 7b7f2f1
authored
Trap Ctrl-C in the REPL: if no command is running clear the prompt, if some command is running ask for confirmation before exiting (#24127)
This ports over one of the other Ammonite features to the Scala 3 REPL,
making it behave much more similarly to other prompt environment (Bash,
Python, etc.):
- If there is no code running, `Ctrl-C` just resets the prompt without
exiting
- If there is code running, `Ctrl-C` first interrupts the thread to try
and force a gentle exit. A second `Ctrl-C` would then terminate the
process.
Unfortunately we will no longer be able to terminate the thread
forcefully, as `Thread.stop` is busted Java >20 (see
com-lihaoyi/Ammonite#1379), so using
`Thread.interrupt` and `sys.exit` is the best we have
Tested manually using `bin/scala`. Doesn't work in `sbt repl` due to SBT
also intercepting the signal, but that's a separate issue we can follow
up laterFile tree
2 files changed
+35
-3
lines changed- compiler/src/dotty/tools/repl
2 files changed
+35
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
85 | 89 | | |
86 | 90 | | |
87 | 91 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
214 | | - | |
215 | | - | |
| 214 | + | |
216 | 215 | | |
| 216 | + | |
| 217 | + | |
217 | 218 | | |
218 | 219 | | |
219 | 220 | | |
220 | 221 | | |
| 222 | + | |
221 | 223 | | |
222 | 224 | | |
223 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
224 | 252 | | |
225 | 253 | | |
226 | 254 | | |
| |||
0 commit comments