Skip to content
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

How do I capture CTRL+C event? #278

Open
temuri416 opened this issue Nov 7, 2023 · 2 comments
Open

How do I capture CTRL+C event? #278

temuri416 opened this issue Nov 7, 2023 · 2 comments

Comments

@temuri416
Copy link

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?

@AydinHassan
Copy link
Member

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

@senyahnoj
Copy link

senyahnoj commented May 1, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants