Xavi Montero
Xavi Montero

Reputation: 10725

Interactive console command in symfony (PHP)

There are console programs, like an editor (say: nano for example) or like a system monitor (say: htop) where you can "navigate" with arrows and freely interact with the content.

In this example, for example I have executed htop and while it's running I've pressed arrow-down multiple times until the PID 14 has been selected:

htop with PID 14 selected

In Symfony I can easily print and also format with colors with the OutputInterface that is injected into the commands.

But... can this "interactivity" be achieved easily with PHP and symfony console commands?

For the sake of the example: Could I code a simple "snake" game in PHP/symfony/console?

(PD: If needed, I MAY use ReactPhp to handle the event loop).

Upvotes: 0

Views: 609

Answers (1)

Simon Frings
Simon Frings

Reputation: 142

Yes, you can! This is an excellent use case for ReactPHP, especially if you're looking to create something interactive and reactive. I highly recommend checking out https://github.com/clue/reactphp-stdio, as it perfectly fits your use case.

Upvotes: 1

Related Questions