php-kilo/kilo
Timothy Warren 99685f3fcb
All checks were successful
timw4mail/php-kilo/pipeline/head This commit looks good
Some refactoring
2021-03-09 17:22:49 -05:00

46 lines
936 B
PHP
Executable File

#!/usr/bin/env php
<?php declare(strict_types=1);
namespace Aviat\Kilo;
require_once __DIR__ . '/vendor/autoload.php';
// Log notices/errors/warnings to file
set_exception_handler(static function (mixed $e) {
$msg = print_r([
'code' => $e->getCode(),
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString(),
], TRUE);
file_put_contents('kilo.log', $msg, FILE_APPEND);
});
// ! Init with an IIFE
return (static function (int $argc, array $argv): int {
Termios::enableRawMode();
register_shutdown_function([Termios::class, 'disableRawMode']);
$editor = Editor::new();
$editor->setStatusMessage('HELP: Ctrl-S = save | Ctrl-Q = quit | Ctrl-F = find');
if ($argc >= 2)
{
$editor->open($argv[1]);
}
// Input Loop
while (true)
{
$editor->refreshScreen();
if ($editor->processKeypress() === NULL)
{
break;
}
}
return 0;
})($argc, $argv);