Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Created March 8, 2023 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james2doyle/8d21951ede537a836f181f809d601df1 to your computer and use it in GitHub Desktop.
Save james2doyle/8d21951ede537a836f181f809d601df1 to your computer and use it in GitHub Desktop.
<?php
$mappings = [
82 => [
'key' => 'R',
'message' => 'Redownloading all pages...',
],
114 => [
'key' => 'r',
'message' => 'Redownloading all pages...',
],
];
echo "Running watcher..." . PHP_EOL;
// start the loop that wall wait for input
readline_callback_handler_install('', function () {
});
while (true) {
$read = [STDIN];
$write = null;
$except = null;
try {
$match = stream_select($read, $write, $except, null);
if ($match) {
$key = ord(stream_get_contents(STDIN, 1));
// echo "Char read: $key\n";
if (isset($mappings[$key])) {
echo $mappings[$key]['message'] . PHP_EOL;
// do stuff...
}
}
} catch (Exception $e) {
echo "Error caught..." . PHP_EOL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment