php-kilo/kilo

58 lines
1.1 KiB
Plaintext
Raw Normal View History

2019-10-10 12:28:46 -04:00
#!/usr/bin/php
<?php declare(strict_types=1);
namespace Kilo;
2019-11-08 12:02:00 -05:00
require_once __DIR__ . '/src/functions.php';
require_once __DIR__ . '/src/hldb.php';
// Log notices/errors/warnings to file
set_error_handler(static function (int $no, $str, $file, $line, $context) {
$msg = print_r([
'errno' => $no,
'message' => $str,
'file' => $file,
'line' => $line,
2019-11-05 12:28:10 -05:00
// 'context' => $context,
], TRUE);
file_put_contents('kilo.log', $msg, FILE_APPEND);
}, -1);
2019-10-24 16:57:27 -04:00
// Set up autoloading
spl_autoload_register(static function ($class) {
$parts = explode('\\', $class);
$file = __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $parts[1] . '.php';
if (file_exists($file))
{
require_once $file;
}
});
2019-10-10 12:28:46 -04:00
2019-10-24 17:07:07 -04:00
// ! Init with an IIFE
return (static function (int $argc, array $argv): int {
enable_raw_mode();
2019-10-14 16:21:41 -04:00
$editor = Editor::new();
2019-10-15 13:23:25 -04:00
if ($argc >= 2)
{
$editor->open($argv[1]);
}
$editor->setStatusMessage('HELP: Ctrl-S = save | Ctrl-Q = quit | Ctrl-F = find');
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();
if ($char === NULL)
{
break;
}
2019-10-10 12:28:46 -04:00
}
return 0;
2019-10-24 17:07:07 -04:00
})($argc, $argv);