Misc bugfixes

This commit is contained in:
Timothy Warren 2019-10-18 16:20:34 -04:00
parent 340dc459f5
commit 5ced2d1f09
4 changed files with 21 additions and 14 deletions

4
kilo
View File

@ -20,12 +20,14 @@ function main(int $argc, array $argv): int
$editor->open($argv[1]); $editor->open($argv[1]);
} }
$editor->setStatusMessage("HELP: Ctrl-Q = quit"); $editor->setStatusMessage('HELP: Ctrl-Q = quit');
// Input Loop // Input Loop
while (true) while (true)
{ {
$editor->refreshScreen(); $editor->refreshScreen();
// Spin while waiting for a keypress
$char = $editor->processKeypress(); $char = $editor->processKeypress();
while ($char === '') while ($char === '')
{ {

View File

@ -22,10 +22,10 @@ trait MagicProperties {
} }
class Key { class Key {
public const ARROW_LEFT = 'ARROW_LEFT'; public const ARROW_LEFT = 'a';//'ARROW_LEFT';
public const ARROW_RIGHT = 'ARROW_RIGHT'; public const ARROW_RIGHT = 'd';//ARROW_RIGHT';
public const ARROW_UP = 'ARROW_UP'; public const ARROW_UP = 'w';//'ARROW_UP';
public const ARROW_DOWN = 'ARROW_DOWN'; public const ARROW_DOWN = 's';//'ARROW_DOWN';
public const DEL_KEY = 'DEL'; public const DEL_KEY = 'DEL';
public const HOME_KEY = 'HOME'; public const HOME_KEY = 'HOME';
public const END_KEY = 'END'; public const END_KEY = 'END';
@ -327,7 +327,7 @@ class Editor {
{ {
$this->rowOffset = $this->cursorY; $this->rowOffset = $this->cursorY;
} }
if ($this->cursorY >= $this->rowOffset + $this->screenRows) if ($this->cursorY >= ($this->rowOffset + $this->screenRows))
{ {
$this->rowOffset = $this->cursorY - $this->screenRows + 1; $this->rowOffset = $this->cursorY - $this->screenRows + 1;
} }
@ -337,7 +337,7 @@ class Editor {
{ {
$this->colOffset = $this->renderX; $this->colOffset = $this->renderX;
} }
if ($this->renderX >= $this->colOffset + $this->screenCols) if ($this->renderX >= ($this->colOffset + $this->screenCols))
{ {
$this->colOffset = $this->renderX - $this->screenCols + 1; $this->colOffset = $this->renderX - $this->screenCols + 1;
} }
@ -348,7 +348,7 @@ class Editor {
for ($y = 0; $y < $this->screenRows; $y++) for ($y = 0; $y < $this->screenRows; $y++)
{ {
$filerow = $y + $this->rowOffset; $filerow = $y + $this->rowOffset;
if ($filerow >= count($this->rows)) if ($filerow >= $this->numRows)
{ {
if ($this->numRows === 0 && $y === $this->screenRows / 3) if ($this->numRows === 0 && $y === $this->screenRows / 3)
{ {
@ -365,7 +365,7 @@ class Editor {
$this->ab .= '~'; $this->ab .= '~';
$padding--; $padding--;
} }
while ($padding--) for (; $padding >= 0; $padding--)
{ {
$this->ab .= ' '; $this->ab .= ' ';
} }
@ -402,8 +402,8 @@ class Editor {
$this->ab .= "\x1b[7m"; $this->ab .= "\x1b[7m";
$statusFilename = $this->filename !== '' ? $this->filename : '[No Name]'; $statusFilename = $this->filename !== '' ? $this->filename : '[No Name]';
$status = sprintf("%.20s - %d lines", $statusFilename, count($this->rows)); $status = sprintf("%.20s - %d lines", $statusFilename, $this->numRows);
$rstatus = sprintf("%d/%d", $this->cursorY + 1, count($this->rows)); $rstatus = sprintf("%d/%d", $this->cursorY + 1, $this->numRows);
$len = strlen($status); $len = strlen($status);
$rlen = strlen($rstatus); $rlen = strlen($rstatus);
if ($len > $this->screenCols) if ($len > $this->screenCols)
@ -573,6 +573,9 @@ class Editor {
write_stdout("\x1b[H"); // Reposition cursor to top-left write_stdout("\x1b[H"); // Reposition cursor to top-left
return NULL; return NULL;
break; break;
default:
return $c;
} }
return $c; return $c;
@ -595,7 +598,7 @@ class Editor {
} }
$times = $this->screenRows; $times = $this->screenRows;
while ($times--) for (; $times > 0; $times--)
{ {
$this->moveCursor($c === Key::PAGE_UP ? Key::ARROW_UP : Key::ARROW_DOWN); $this->moveCursor($c === Key::PAGE_UP ? Key::ARROW_UP : Key::ARROW_DOWN);
} }

View File

@ -18,7 +18,7 @@ define('STDERR_FILENO', 2);
define('TCSAFLUSH', 2); define('TCSAFLUSH', 2);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// ! Termios bitflags // ! Termios flags and constants
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/* Input modes */ /* Input modes */

View File

@ -44,6 +44,8 @@ function disableRawMode(): void
$res = $ffi->tcsetattr(STDIN_FILENO, TCSAFLUSH, FFI::addr($original_termios)); $res = $ffi->tcsetattr(STDIN_FILENO, TCSAFLUSH, FFI::addr($original_termios));
echo "\n";
if ($res === -1) if ($res === -1)
{ {
die('tcsetattr'); die('tcsetattr');