48 lines
535 B
PHP
Executable File
48 lines
535 B
PHP
Executable File
#!/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
|
|
while (true)
|
|
{
|
|
$char = read_stdin(1);
|
|
$c = ord($char);
|
|
|
|
if (empty($char))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if ($ffi->iscntrl($c))
|
|
{
|
|
printf("%d\r\n", $c);
|
|
}
|
|
else
|
|
{
|
|
printf("%d ('%c')\r\n", $c, $c);
|
|
}
|
|
|
|
if ($char === 'q')
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
disableRawMode();
|
|
|
|
return 0;
|
|
}
|
|
|
|
//! Init
|
|
main();
|