From 1ba7485cefbb15173df054e8f2188dafacad8127 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 22 Mar 2026 17:29:22 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Palette:=20Improved=20CLI=20Feed?= =?UTF-8?q?back=20and=20Inclusive=20Achievements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added CLR_ERASE (\033[K) to ensure clean terminal updates by clearing residual characters. - Colorized countdown digits (Yellow) and "GO!" prompt (Green) for better visual feedback. - Implemented real-time high-score tracking (Score | High) in the gameplay UI. - Made achievement feedback ("NEW BEST!") and final congratulations inclusive for first-time players by removing the initialHighscore > 0 check. - Updated .Jules/palette.md with new UX learnings. Co-authored-by: aidasofialily-cmd <247843425+aidasofialily-cmd@users.noreply.github.com> --- .Jules/palette.md | 4 ++++ src/main.cpp | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.Jules/palette.md b/.Jules/palette.md index c4e3778..3202931 100644 --- a/.Jules/palette.md +++ b/.Jules/palette.md @@ -25,3 +25,7 @@ ## 2026-03-02 - Hiding the Cursor in CLI Games **Learning:** In terminal applications that require rapid visual updates or where user input doesn't involve typing text, an actively blinking cursor can be a visual distraction. Hiding it during interaction (`\033[?25l`) and rigorously ensuring it is restored (`\033[?25h`) on exit—including signal interrupts—significantly improves the aesthetic and focus. **Action:** Always hide the cursor for interactive CLI games and explicitly restore it across all exit paths, including async-signal-safe signal handlers. + +## 2026-03-22 - Inclusive Achievements and Clean Terminal Updates +**Learning:** Forgetting to celebrate first-time achievements (e.g., using `score > highscore && highscore > 0`) excludes new players from early delight. Also, in-place terminal updates using `\r` can leave "ghost" characters if the new line is shorter than the old one; the ANSI escape sequence `\033[K` (Erase in Line) is essential for a clean UI. +**Action:** Always make achievement logic inclusive of first-time records and use `\033[K` when performing in-place terminal updates. diff --git a/src/main.cpp b/src/main.cpp index e72f1da..e88ae56 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,6 +20,7 @@ #define CLR_HARD "\033[1;31m" #define CLR_NORM "\033[1;32m" #define CLR_CTRL "\033[1;33m" +#define CLR_ERASE "\033[K" #define CLR_RESET "\033[0m" struct termios oldt; @@ -94,7 +95,7 @@ int main() { } for (int i = 3; i > 0; --i) { - std::cout << "\rStarting in " << i << "... " << std::flush; + std::cout << "\rStarting in " << CLR_CTRL << i << CLR_RESET << "... " << CLR_ERASE << 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 +109,7 @@ int main() { } } } - std::cout << "\rGO! \n" << std::flush; + std::cout << "\r" << CLR_NORM << "GO!" << CLR_RESET << CLR_ERASE << "\n" << std::flush; std::this_thread::sleep_for(std::chrono::milliseconds(200)); tcflush(STDIN_FILENO, TCIFLUSH); @@ -137,10 +138,10 @@ int main() { } if (updateUI) { - std::cout << "\r" << CLR_SCORE << "Score: " << score << CLR_RESET << " " + std::cout << "\r" << CLR_SCORE << "Score: " << score << CLR_RESET << " | High: " << std::max(score, initialHighscore) << " " << (hardMode ? CLR_HARD "[HARD MODE]" : CLR_NORM "[NORMAL MODE]") - << (score > initialHighscore && initialHighscore > 0 ? " NEW BEST! 🥳" : "") - << " " << std::flush; + << (score > initialHighscore ? " NEW BEST! 🥳" : "") + << CLR_ERASE << CLR_RESET << std::flush; updateUI = false; } } @@ -151,7 +152,7 @@ int main() { tcsetattr(STDIN_FILENO, TCSANOW, &oldt); std::cout << "\n\n" << CLR_SCORE << "Final Score: " << score << CLR_RESET << "\n"; - if (score > initialHighscore && initialHighscore > 0) { + if (score > initialHighscore) { std::cout << "Congratulations! A new personal best!\n"; } std::cout << "Thanks for playing!\n";