Created
March 8, 2023 19:03
-
-
Save james2doyle/8d21951ede537a836f181f809d601df1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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