diff --git a/src/ANSI.php b/src/ANSI.php index 03b80aa..0badbc0 100644 --- a/src/ANSI.php +++ b/src/ANSI.php @@ -78,7 +78,9 @@ class ANSI { */ public static function moveCursor(int $line, int $column): string { - return self::seq('%d;%dH', $line, $column); + // The terminal has a 1-based coordinate system, + // add one to each to allow 0-based coordinate system input + return self::seq('%d;%dH', $line + 1, $column + 1); } /** diff --git a/src/Editor.php b/src/Editor.php index ebef264..7e2ef92 100644 --- a/src/Editor.php +++ b/src/Editor.php @@ -688,8 +688,8 @@ class Editor { // Specify the current cursor position $this->outputBuffer .= ANSI::moveCursor( - ($this->cursorY - $this->rowOffset) + 1, - ($this->renderX - $this->colOffset) + 1 + $this->cursorY - $this->rowOffset, + $this->renderX - $this->colOffset ); $this->outputBuffer .= ANSI::SHOW_CURSOR; diff --git a/src/Terminal.php b/src/Terminal.php index 940fd27..9ca646b 100644 --- a/src/Terminal.php +++ b/src/Terminal.php @@ -33,6 +33,9 @@ class Terminal { return [25, 80]; } + /** + * Clear the screen and reset the cursor position + */ public static function clear(): void { self::write(ANSI::CLEAR_SCREEN . ANSI::RESET_CURSOR);