Don't refresh until there's a keypress
This commit is contained in:
parent
77473f9602
commit
340dc459f5
13
kilo
13
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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user