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';
|
2019-10-14 16:21:41 -04:00
|
|
|
require_once __DIR__ . '/src/Editor.php';
|
2019-10-10 12:28:46 -04:00
|
|
|
|
2019-10-15 13:23:25 -04:00
|
|
|
function main(int $argc, array $argv): int
|
2019-10-10 12:28:46 -04:00
|
|
|
{
|
2019-10-14 16:21:41 -04:00
|
|
|
global $ffi;
|
|
|
|
|
2019-10-10 12:28:46 -04:00
|
|
|
enableRawMode();
|
|
|
|
|
2019-10-15 13:23:25 -04:00
|
|
|
$editor = Editor::new($ffi);
|
|
|
|
|
|
|
|
if ($argc >= 2)
|
|
|
|
{
|
|
|
|
$editor->open($argv[1]);
|
|
|
|
}
|
|
|
|
|
2019-10-16 16:43:15 -04:00
|
|
|
$editor->setStatusMessage("HELP: Ctrl-Q = quit");
|
2019-10-11 16:32:47 -04:00
|
|
|
|
2019-10-10 12:28:46 -04:00
|
|
|
// Input Loop
|
2019-10-10 15:49:01 -04:00
|
|
|
while (true)
|
2019-10-10 12:28:46 -04:00
|
|
|
{
|
2019-10-14 16:21:41 -04:00
|
|
|
$editor->refreshScreen();
|
2019-10-16 22:14:30 -04:00
|
|
|
$char = $editor->processKeypress();
|
|
|
|
while ($char === '')
|
|
|
|
{
|
|
|
|
$char = $editor->processKeypress();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($char === NULL)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2019-10-10 12:28:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Init
|
2019-10-15 13:23:25 -04:00
|
|
|
main($argc, $argv);
|