From 340dc459f5f0c809de88527be2d522f82e9170e1 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 16 Oct 2019 22:14:30 -0400 Subject: [PATCH] Don't refresh until there's a keypress --- kilo | 13 ++++++++++--- src/Editor.php | 10 ++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) 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; }