我有一个用于scala REPL api (ILoop等)的包装器。使用重构后的2.9.x类。
这样做效果很好。
由于这是一个交付给用户的工具,因此用户可能会键入以下内容:
while(-1 < 1) {}
用户如何从当前正在执行的代码中解脱出来?
其他帖子讨论的是
<ctrl> + <c>
在一些平台上,在适当的键绑定下工作。
检查scala REPL api和任何可用的文档,并不清楚如何实际实现这一点。
发布于 2011-12-05 06:22:14
查看文件ILoopInit.scala
中的Scala REPL does it是如何。在那里安装了以下信号中断处理程序,
protected def installSigIntHandler() {
// ....
SignalManager("INT") = {
if (intp == null || intp.lineManager == null)
onExit()
else if (intp.lineManager.running)
intp.lineManager.cancel()
// ...
}
}
请注意,字段intp: IMain
是在类ILoop
中定义的,该类是ILoopInit
的自类型。
总而言之:在你的SIGINT处理程序中,你可以用intp.lineManager.cancel
中断REPL。
https://stackoverflow.com/questions/8340731
复制相似问题