2019-10-10 12:28:46 -04:00
|
|
|
#!/usr/bin/php
|
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Kilo;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/src/constants.php';
|
|
|
|
require_once __DIR__ . '/src/functions.php';
|
|
|
|
|
|
|
|
function main(): int
|
|
|
|
{
|
|
|
|
global $ffi;
|
|
|
|
|
|
|
|
enableRawMode();
|
|
|
|
|
|
|
|
// Input Loop
|
2019-10-10 15:49:01 -04:00
|
|
|
while (true)
|
2019-10-10 12:28:46 -04:00
|
|
|
{
|
2019-10-10 15:49:01 -04:00
|
|
|
$char = read_stdin(1);
|
|
|
|
$c = ord($char);
|
|
|
|
|
|
|
|
if (empty($char))
|
2019-10-10 12:28:46 -04:00
|
|
|
{
|
2019-10-10 15:49:01 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($ffi->iscntrl($c))
|
|
|
|
{
|
|
|
|
printf("%d\r\n", $c);
|
2019-10-10 12:28:46 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-10 15:49:01 -04:00
|
|
|
printf("%d ('%c')\r\n", $c, $c);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($char === 'q')
|
|
|
|
{
|
|
|
|
break;
|
2019-10-10 12:28:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
disableRawMode();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Init
|
|
|
|
main();
|