Timothy J Warren
f5aafb465a
Some checks failed
Gitea - Tutorials/php-kilo/master There was a failure building this commit
47 lines
899 B
PHP
Executable File
47 lines
899 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_error_handler(static function (int $no, $str, $file, $line) {
|
|
$msg = print_r([
|
|
'errno' => $no,
|
|
'message' => $str,
|
|
'file' => $file,
|
|
'line' => $line,
|
|
], TRUE);
|
|
file_put_contents('kilo.log', $msg, FILE_APPEND);
|
|
|
|
}, -1);
|
|
|
|
// ! Init with an IIFE
|
|
return (static function (int $argc, array $argv): int {
|
|
Termios::enableRawMode();
|
|
register_shutdown_function([Termios::class, 'disableRawMode']);
|
|
|
|
$editor = Editor::new();
|
|
|
|
if ($argc >= 2)
|
|
{
|
|
$editor->open($argv[1]);
|
|
}
|
|
|
|
$editor->setStatusMessage('HELP: Ctrl-S = save | Ctrl-Q = quit | Ctrl-F = find');
|
|
|
|
// Input Loop
|
|
while (true)
|
|
{
|
|
$editor->refreshScreen();
|
|
$char = $editor->processKeypress();
|
|
if ($char === NULL)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
})($argc, $argv);
|