From 8937cbee2f196eeb7a6044500102a87078c8f729 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 29 Mar 2026 12:24:36 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Palette:=20Use=20ANSI=20Erase=20?= =?UTF-8?q?in=20Line=20to=20prevent=20trailing=20artifacts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced hardcoded padding spaces with \033[K (Erase in Line) immediately following carriage returns when updating dynamic terminal lines. This prevents trailing text artifacts more efficiently. Also added an entry to .Jules/palette.md to record this UX learning. Co-authored-by: EiJackGH <172181576+EiJackGH@users.noreply.github.com> --- .Jules/palette.md | 3 +++ .gitignore | 1 + src/main.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.Jules/palette.md b/.Jules/palette.md index 853ef9c..ad342c1 100644 --- a/.Jules/palette.md +++ b/.Jules/palette.md @@ -29,3 +29,6 @@ ## 2025-01-24 - Real-time Achievement Feedback in CLI **Learning:** In terminal-based games, displaying achievement progress (like a live high score) in real-time provides immediate tactile reward and engagement. Furthermore, inclusive UX means ensuring first-time players also receive "New Best" feedback, even when their initial record is zero. **Action:** Update session-high-score variables immediately upon record-breaking and display them in the live HUD. Ensure achievement conditions (`score > highscore`) don't exclude the first-time user experience. +## 2026-03-29 - Prevent Trailing Text Artifacts +**Learning:** When updating dynamic terminal lines via ' ', hardcoding padding spaces is inefficient and error-prone. +**Action:** Always use the ANSI escape sequence '' (Erase in Line) immediately after the carriage return instead of hardcoding padding spaces. diff --git a/.gitignore b/.gitignore index eb2c19a..d07c78a 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ highscore.txt # Persistent data highscore.txt +venv/ diff --git a/src/main.cpp b/src/main.cpp index af692c8..a74d829 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,7 +94,7 @@ int main() { } for (int i = 3; i > 0; --i) { - std::cout << "\rStarting in " << CLR_CTRL << i << CLR_RESET << "... " << std::flush; + std::cout << "\r\033[KStarting in " << CLR_CTRL << i << CLR_RESET << "... " << std::flush; auto start_wait = std::chrono::steady_clock::now(); while (std::chrono::duration_cast(std::chrono::steady_clock::now() - start_wait).count() < 1000) { int elapsed = std::chrono::duration_cast(std::chrono::steady_clock::now() - start_wait).count(); @@ -108,7 +108,7 @@ int main() { } } } - std::cout << "\r" << CLR_NORM << "GO! " << CLR_RESET << "\n" << std::flush; + std::cout << "\r\033[K" << CLR_NORM << "GO!" << CLR_RESET << "\n" << std::flush; std::this_thread::sleep_for(std::chrono::milliseconds(200)); tcflush(STDIN_FILENO, TCIFLUSH); @@ -141,10 +141,10 @@ int main() { } if (updateUI) { - std::cout << "\r" << CLR_SCORE << "Score: " << score << CLR_RESET << " | High: " << highscore << " " + std::cout << "\r\033[K" << CLR_SCORE << "Score: " << score << CLR_RESET << " | High: " << highscore << " " << (hardMode ? CLR_HARD "[HARD MODE]" : CLR_NORM "[NORMAL MODE]") << (score > initialHighscore ? " NEW BEST! 🥳" : "") - << " " << std::flush; + << std::flush; updateUI = false; } }