php-kilo/kilo

67 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

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
use Aviat\Kilo\Terminal\Termios;
require_once __DIR__ . '/src/Kilo.php';
2023-10-09 09:15:37 -04:00
// Remove the composer install requirement by
2023-10-09 09:15:37 -04:00
// manually handling autoloading
spl_autoload_register(static function (string $class): void {
2023-10-09 09:15:37 -04:00
$nsParts = explode('\\', $class);
array_shift($nsParts);
array_shift($nsParts);
array_unshift($nsParts, __DIR__, 'src');
$file = implode(DIRECTORY_SEPARATOR, $nsParts) . '.php';
if (file_exists($file))
{
require_once($file);
return;
2023-10-09 09:15:37 -04:00
}
});
// Log notices/errors/warnings to file
set_error_handler(static function (
int $errno,
string $errstr,
string $errfile,
int $errline,
) {
$msg = print_r([
2021-03-17 15:38:52 -04:00
'code' => error_code_name($errno),
'message' => $errstr,
'file' => $errfile,
'line' => $errline,
], TRUE);
2021-03-17 15:38:52 -04:00
file_put_contents('kilo.log', $msg, FILE_APPEND);
return true;
}, -1);
2021-03-09 17:22:49 -05:00
set_exception_handler(static function (mixed $e) {
$msg = print_r([
2020-12-04 11:18:21 -05:00
'code' => $e->getCode(),
2021-03-17 15:38:52 -04:00
'codeName' => error_code_name($e->getCode()),
2020-12-04 11:18:21 -05:00
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString(),
], TRUE);
2021-03-17 15:38:52 -04:00
file_put_contents('kilo.log', $msg, FILE_APPEND);
2020-12-04 11:18:21 -05:00
});
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
Editor::new($argc, $argv)->run();
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