How to handle signals gracefully with Jline3?

64 views
Skip to first unread message

Wang Zhong

unread,
May 30, 2019, 3:52:37 AM5/30/19
to jline-users
Hello,

Is there any code example about how to handle signals in Jline3? 

I had a look at your code and noticed that Jline3 implements several classes to handle signals. It seems that the recommended way to handle signals is by calling the handle() method defined by Terminal like this
        SignalHandler intHandler = terminal.handle(Signal.INT, s -> {
            Job current = session.foregroundJob();
            if (current != null) {
                current.interrupt();
            }
        });

Currently I set SignalHandle like this:

    Signal.handle(new Signal("INT"), (sig) -> {
      System.err.println("interrupted");
    });

And it seems the handler is replaced by some unknown handler sometimes.


Brad Wood

unread,
May 30, 2019, 10:18:35 AM5/30/19
to jline...@googlegroups.com
I'm using JLine from CFML and I register my handler class with the terminal builder.  You can see that line here:


 My signal handler is here and simply interrupts the main thread of my console app when Ctrl-C is pressed:


That is a CFML class that implements org.jline.terminal.Terminal$SignalHandler

Thanks!

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 



--
You received this message because you are subscribed to the Google Groups "jline-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jline-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jline-users/5e5ca176-7c7f-419b-b240-35e71cf93f93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Wang Zhong

unread,
May 31, 2019, 4:05:55 AM5/31/19
to jline-users
Thanks for replying, I will have a look at your example! Btw, stared :P
To unsubscribe from this group and stop receiving emails from it, send an email to jline...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages