cli-menu icon indicating copy to clipboard operation
cli-menu copied to clipboard

How do I capture CTRL+C event?

Open temuri416 opened this issue 2 years ago • 2 comments

You can exit the menu by pressing CTRL+C. But in that case the following code does not get called:

protected function tearDownTerminal() : void
{
    ...
    $this->terminal->enableCursor();
}

And as a result, there's no cursor in the shell.

How can I enable cursor if user presses CTRL+C?

temuri416 avatar Nov 07 '23 14:11 temuri416

It's not possible currently. There was some work on it a long time ago but it was never finished: https://github.com/php-school/terminal/pull/12

AydinHassan avatar Nov 08 '23 10:11 AydinHassan

I am currently working around this issue by disabling Ctrl+C altogether. Here's my code in case it's helpful to anyone

$builder = new CliMenuBuilder();

// build the menu items, etc.

// Prevent Ctl+C doing anything so that we are not affected by losing
// the cursor https://github.com/php-school/cli-menu/issues/278
pcntl_signal(SIGINT, function ($signal) {
});

$builder->build()->open();

(PHP needs to be compiled with --enable-pcntl for this to work)

senyahnoj avatar May 01 '24 16:05 senyahnoj