diff --git a/kilo b/kilo index d8b5f64..1fa1c2b 100755 --- a/kilo +++ b/kilo @@ -13,7 +13,6 @@ function main(int $argc, array $argv): int enableRawMode(); - // ob_start(); $editor = Editor::new($ffi); if ($argc >= 2) @@ -27,8 +26,16 @@ function main(int $argc, array $argv): int while (true) { $editor->refreshScreen(); - $editor->processKeypress(); - // ob_flush(); + $char = $editor->processKeypress(); + while ($char === '') + { + $char = $editor->processKeypress(); + } + + if ($char === NULL) + { + break; + } } return 0; diff --git a/src/Editor.php b/src/Editor.php index 3e768ee..38c538c 100644 --- a/src/Editor.php +++ b/src/Editor.php @@ -534,9 +534,15 @@ class Editor { } } - public function processKeypress(): string + public function processKeypress(): ?string { $c = $this->readKey(); + + if ($c === "\0") + { + return ''; + } + switch ($c) { case Key::HOME_KEY: @@ -565,7 +571,7 @@ class Editor { case chr(ctrl_key('q')): write_stdout("\x1b[2J"); // Clear the screen write_stdout("\x1b[H"); // Reposition cursor to top-left - exit(0); + return NULL; break; }