Skip to content

Conversation

@lihaoyi
Copy link
Contributor

@lihaoyi lihaoyi commented Dec 28, 2025

Rather than using JVM signal handling to trap the Ctrl-C, we instead make JLine set the terminal to raw mode and handle the Ctrl-C as a standard input character.

This is similar to what Ammonite (link) and (I think) JShell does, and has the advantage that it works even for stdin/stdout terminals inherited from parent processes (e.g. Mill or SBT) v.s. the current signal handling that only works when the REPL process is receiving the Ctrl-C directly.

Fixes com-lihaoyi/mill#6452 downstream in Mill, tested manually by cherry picking onto release-3.8.0, publishing locally, and using it in Mill

sbt --client scala3-compiler-bootstrapped-new/publishLocalBin &&
sbt --client scala-library-bootstrapped/publishLocalBin &&
sbt --client scala3-library-bootstrapped-new/publishLocalBin &&
sbt --client tasty-core-bootstrapped-new/publishLocalBin &&
sbt --client scala3-repl/publishLocalBin &&
sbt --client scala3-interfaces/publishLocalBin &&
sbt --client scala3-sbt-bridge-bootstrapped/publishLocalBin

@lihaoyi lihaoyi changed the title Make REPL configure jline terminal to be in raw mode to make Ctrl-C handling work when REPL is a child process WIP Make REPL configure jline terminal to be in raw mode to make Ctrl-C handling work when REPL is a child process Dec 28, 2025
@lihaoyi lihaoyi marked this pull request as draft December 28, 2025 14:43
@lihaoyi lihaoyi force-pushed the terminal-raw branch 3 times, most recently from d1e53c7 to 938b55d Compare December 28, 2025 15:24
@lihaoyi lihaoyi changed the title WIP Make REPL configure jline terminal to be in raw mode to make Ctrl-C handling work when REPL is a child process WIP Replace REPL signal handling with raw mode jline terminal to make Ctrl-C handling work when REPL is a child process Dec 28, 2025
@lihaoyi lihaoyi force-pushed the terminal-raw branch 2 times, most recently from a3fb677 to 3c3de7b Compare December 28, 2025 15:58
@lihaoyi lihaoyi marked this pull request as ready for review December 28, 2025 16:00
@lihaoyi lihaoyi changed the title WIP Replace REPL signal handling with raw mode jline terminal to make Ctrl-C handling work when REPL is a child process Replace REPL signal handling with raw mode jline terminal to make Ctrl-C handling work when REPL is a child process Dec 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ctrl-C in ./mill --repl terminates the process

1 participant