Closed stof closed 12 months ago
i think it's specific to the events.php
example? but yes, adding error handling would be good - these examples are honestly quite quick-and-dirty.
r.e. withRawMode
"raw mode" might not be the only thing that should be reset, e.g. enabling/disabling "mouse capture", showing/hiding the cursor etc also mutates the terminal.
some setup/teardown should be expected in any app, I wonder if trying to anticipate that in the API would overcomplicate things?
created a PR to handle errors: https://github.com/php-tui/term/pull/8
merged that, closing this issue but feel free to continue the discussion :)
Currently, examples will leave the terminal in a broken state by leaving them in raw mode in case a PHP exception happens.
I think it would be great that all examples that enable raw mode wrap the following code in a try/finally block to disable it again in case of exception.
Btw, if
exit
is not used inside that code block, it might be the only place that needs to disable it back. And maybe aTerminal::withRawMode(callable(): T): T
API would make sense to run that callable with raw mode enabled (theT
is might proposal is about making that method generic and returning the return value of the callback) in a finally block (this would not be a good idea if the most common case is to useexit
as that would not reach the end of the callback to re-disable it)