I'm writing a php cli interactive program, it act as a shell by using readline
extension.
But I find that when I press Ctrl + C, the whole program exits. I hope it can get a new prompt instead of exit (just like bash
).
So I try pcntl_signal
to handle the SIGINT
pcntl_signal(SIGINT, SIG_IGN);
It doesn't exit and response nothing (just like dead)
I change the code to:
pcntl_signal(SIGINT, function(){
echo "\n";
});
This time it prints ^C
but no new line, when I press Enter these is a new line before the prompt.
I have read Readline: Get a new prompt on SIGINT , but it's using C
, and I found there is no siglongjmp
function in php
.
So I wonder is it possible to get a new prompt when I press Ctrl + C