2019-12-02 09:44:11 -05:00
|
|
|
#!/usr/bin/env php
|
2019-10-10 12:28:46 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
2019-11-08 16:27:08 -05:00
|
|
|
namespace Aviat\Kilo;
|
2019-10-10 12:28:46 -04:00
|
|
|
|
2019-11-08 16:27:08 -05:00
|
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
2019-10-24 12:00:14 -04:00
|
|
|
|
2019-10-25 10:47:44 -04:00
|
|
|
// Log notices/errors/warnings to file
|
2019-12-02 09:44:11 -05:00
|
|
|
set_error_handler(static function (int $no, $str, $file, $line) {
|
2019-10-25 10:47:44 -04:00
|
|
|
$msg = print_r([
|
|
|
|
'errno' => $no,
|
|
|
|
'message' => $str,
|
|
|
|
'file' => $file,
|
|
|
|
'line' => $line,
|
|
|
|
], TRUE);
|
|
|
|
file_put_contents('kilo.log', $msg, FILE_APPEND);
|
|
|
|
|
|
|
|
}, -1);
|
|
|
|
|
2019-10-24 17:07:07 -04:00
|
|
|
// ! Init with an IIFE
|
|
|
|
return (static function (int $argc, array $argv): int {
|
2019-11-08 16:27:08 -05:00
|
|
|
Termios::enableRawMode();
|
|
|
|
register_shutdown_function([Termios::class, 'disableRawMode']);
|
2019-10-14 16:21:41 -04:00
|
|
|
|
2019-10-24 10:58:38 -04:00
|
|
|
$editor = Editor::new();
|
2019-10-15 13:23:25 -04:00
|
|
|
|
|
|
|
if ($argc >= 2)
|
|
|
|
{
|
|
|
|
$editor->open($argv[1]);
|
|
|
|
}
|
|
|
|
|
2019-10-23 10:36:04 -04:00
|
|
|
$editor->setStatusMessage('HELP: Ctrl-S = save | Ctrl-Q = quit | Ctrl-F = find');
|
2019-10-11 16:32:47 -04:00
|
|
|
|
2020-02-05 16:32:17 -05:00
|
|
|
try
|
2019-10-10 12:28:46 -04:00
|
|
|
{
|
2020-02-05 16:32:17 -05:00
|
|
|
// Input Loop
|
|
|
|
while (true)
|
2019-10-16 22:14:30 -04:00
|
|
|
{
|
2020-02-05 16:32:17 -05:00
|
|
|
$editor->refreshScreen();
|
|
|
|
$char = $editor->processKeypress();
|
|
|
|
if ($char === NULL)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2019-10-16 22:14:30 -04:00
|
|
|
}
|
2019-10-10 12:28:46 -04:00
|
|
|
}
|
2020-02-05 16:32:17 -05:00
|
|
|
catch (\Throwable $e)
|
|
|
|
{
|
|
|
|
$msg = print_r([
|
|
|
|
'code' => $e->getCode(),
|
|
|
|
'message' => $e->getMessage(),
|
|
|
|
'file' => $e->getFile(),
|
|
|
|
'line' => $e->getLine(),
|
|
|
|
'trace' => $e->getTraceAsString(),
|
|
|
|
], TRUE);
|
|
|
|
file_put_contents('kilo.exception.log', $msg, FILE_APPEND);
|
|
|
|
}
|
2019-10-10 12:28:46 -04:00
|
|
|
|
|
|
|
return 0;
|
2019-10-24 17:07:07 -04:00
|
|
|
})($argc, $argv);
|
2020-02-05 16:32:17 -05:00
|
|
|
|