How can I capture Cntl-C when using Perl Term :: ShellUI?

I used Term :: ShellUI and almost everything works as expected, but the problem is when I pressed Ctrl-C, I want to print:

Use ctrl + d to exit the shell

To do this, I process the signal, but the message is printed only after I pressed a new line. How to solve this problem?

+3
source share
1 answer

You can do the same without using the IO :: Handle library by setting $ | variable up to 1 before printing.

$SIG{INT} = sub {
   $| = 1;
   print "Please use ctrl+d to exit the shell";
}
+2
source

Source: https://habr.com/ru/post/1737290/


All Articles