From 113cc1a0a1cb93d54cdd39082026f56c3e4f8384 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 5 Mar 2021 20:47:59 -0500 Subject: [PATCH] Minor tweaks --- src/ANSI.php | 4 +++- src/Editor.php | 4 ++-- src/Terminal.php | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) 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);