-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REPL arrow keys and other readline keys fail to work after C-z/fg on Mac OS X #6096
Comments
Imported From: https://issues.scala-lang.org/browse/SI-6096?orig=1
|
@paulp said: But that's a whole separate universe of code. |
Ben Wing (benwing) said: |
@paulp said: |
Ben Wing (benwing) said: |
@paulp said (edited on Dec 27, 2013 12:26:02 AM UTC): https://github.com/paulp/scala/compare/repl-signal-handlers It works like a charm as long as you're using oracle's java. The part I left for you is avoiding a hard dependency on sun.misc.*. That means rewriting it based on reflection, including implementing the SignalHandler interface via a proxy. I've done it before so I know it's doable. (The "you" in "left for you" can be generic you, as long as it isn't me.) |
@paulp said: |
Ben Wing (benwing) said: |
@paulp said: |
Ben Wing (benwing) said: |
@paulp said: |
Ben Wing (benwing) said: |
Ben Wing (benwing) said (edited on Dec 28, 2013 12:12:40 AM UTC): There may be better ways to handle the possibility of something going wrong; at least, convert the println statements into repldbg() or whatever. But the code as written will work. package testproxy
import java.lang.reflect.{Array=>_,_}
object SignalProxy {
val clazz = try {
Class.forName("sun.misc.Signal")
} catch {
case e: ClassNotFoundException => null
}
def apply(name: String) = {
try {
clazz.getConstructor(classOf[String]).newInstance(name).asInstanceOf[Object]
} catch {
case e: Exception => {
println("Caught exception in SignalProxy.apply: " + e)
null
}
}
}
def handle(rsig: Object, proxy: Object): Boolean = {
try {
if (clazz != null) {
val handlerclazz = SignalHandlerProxy.clazz
if (handlerclazz != null) {
val m = clazz.getMethod("handle", clazz, handlerclazz)
m.invoke(null, rsig, proxy)
}
}
} catch {
case e: Exception => {
println("Caught exception in SignalProxy.handle: " + e)
return false
}
}
return true
}
}
object SignalHandlerProxy {
val clazz = try {
Class.forName("sun.misc.SignalHandler")
} catch {
case e: ClassNotFoundException => null
}
def apply(rsig: Object)(body: => Unit) = {
if (clazz == null) null
else try {
Proxy.newProxyInstance(clazz.getClassLoader(), Array(clazz),
new SignalHandlerProxy(rsig)(body))
} catch {
case e: Exception => {
println("Caught exception in SignalHandlerProxy.apply: " + e)
null
}
}
}
}
class SignalHandlerProxy(rsig: Object)(body: => Unit) extends InvocationHandler
{
def invoke(proxy: Object, m: Method, args: Array[Object]) = {
if (m.getName == "handle")
{
val nsig = args(0)
if (nsig == rsig)
body
}
null
}
}
object TestSignal1 extends App {
object InstallSignalHandler {
import sun.misc.{ Signal, SignalHandler }
def apply(name: String)(body: => Unit): Unit = {
val rsig = new Signal(name)
Signal.handle(rsig, new SignalHandler { def handle(nsig: Signal): Unit = if (rsig == nsig) body })
}
}
InstallSignalHandler("INT") {
println("Caught SIGINT")
}
Thread.sleep(5000)
}
object TestSignal2 extends App {
object InstallSignalHandler {
def apply(name: String)(body: => Unit): Unit = {
val rsig = SignalProxy(name)
val handler =
if (rsig != null) SignalHandlerProxy(rsig)(body) else null
if (handler != null)
SignalProxy.handle(rsig, handler)
else
println("Unable to install signal handler for " + name)
}
}
InstallSignalHandler("INT") {
println("Caught SIGINT")
}
Thread.sleep(5000)
} |
@paulp said: That will probably depend on who you ask, but if it's written to do nothing on all platforms which aren't oracle (and that was the point of the exercise) there's no (good) reason why not. |
stale, closing. comment/reopen if this is still an issue in current Scala (JLine has been upgraded multiple times since 2012) |
This makes the REPL almost useless, because it's impossible to edit (other than with the Delete key) or retrieve previous lines.
The text was updated successfully, but these errors were encountered: