42 lines
562 B
PHP
Executable File
42 lines
562 B
PHP
Executable File
#!/usr/bin/php
|
|
<?php declare(strict_types=1);
|
|
|
|
namespace Kilo;
|
|
|
|
use FFI;
|
|
|
|
require_once __DIR__ . '/src/constants.php';
|
|
require_once __DIR__ . '/src/functions.php';
|
|
|
|
$ffi = FFI::load(__DIR__ . '/src/ffi.h');
|
|
$original_termios = $ffi->new("struct termios");
|
|
|
|
function main(): int
|
|
{
|
|
global $ffi;
|
|
|
|
enableRawMode();
|
|
|
|
// Input Loop
|
|
do
|
|
{
|
|
$input = read_stdin();
|
|
if ($ffi->iscntrl($input))
|
|
{
|
|
printf("%d\n", $input);
|
|
}
|
|
else
|
|
{
|
|
printf("%d ('%c')\n", $input, $input);
|
|
}
|
|
}
|
|
while ($input !== 'q');
|
|
|
|
disableRawMode();
|
|
|
|
return 0;
|
|
}
|
|
|
|
//! Init
|
|
main();
|