Don't refresh until there's a keypress

This commit is contained in:
Timothy Warren 2019-10-16 22:14:30 -04:00
parent 77473f9602
commit 340dc459f5
2 changed files with 18 additions and 5 deletions

13
kilo
View File

@ -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;

View File

@ -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;
}