From 23cc371a6779bdeb65a7c392f2099ad5401ccfe9 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 13 Mar 2026 17:11:30 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Palette:=20Enhance=20terminal=20?= =?UTF-8?q?UI=20and=20inclusive=20feedback=20in=20SPEED=20CLICKER?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit introduces several micro-UX improvements to the SPEED CLICKER CLI: - Added `CLR_LINE` (\033[K) macro for robust terminal line clearing, replacing manual space padding. - Colorized countdown digits and the "GO!" prompt for better visual feedback. - Integrated a real-time high score display into the gameplay UI. - Updated "NEW BEST! 🥳" and congratulation logic to include first-time players. - Ensured terminal colors are reset on all line updates. These changes improve visual polish, information accessibility, and overall player engagement. Co-authored-by: aidasofialily-cmd <247843425+aidasofialily-cmd@users.noreply.github.com> --- .Jules/palette.md | 8 ++++++++ src/main.cpp | 14 ++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.Jules/palette.md b/.Jules/palette.md index c4e3778..0177c9a 100644 --- a/.Jules/palette.md +++ b/.Jules/palette.md @@ -25,3 +25,11 @@ ## 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. + +## 2025-01-24 - Inclusive Achievement Feedback +**Learning:** Requiring a pre-existing non-zero high score before celebrating a "New Best" excludes first-time players from a key moment of delight. Checking `score > initialHighscore` (where `initialHighscore` may be 0) ensures every player feels rewarded for their progress from the very first session. +**Action:** Always ensure achievement logic handles the "zero-state" gracefully to include first-time users in celebratory feedback loops. + +## 2025-01-24 - Robust Terminal Redrawing +**Learning:** Manual space padding (e.g., `" "`) to clear old text in a terminal is fragile and dependent on the previous string length. The ANSI "Erase in Line" sequence (`\033[K`) is a more robust and idiomatic way to ensure a clean redraw regardless of string length changes. +**Action:** Use `\033[K` (CLR_LINE) for all in-place terminal updates to prevent "ghost" characters and ensure a polished UI. diff --git a/src/main.cpp b/src/main.cpp index e72f1da..582dcd0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ #define CLR_NORM "\033[1;32m" #define CLR_CTRL "\033[1;33m" #define CLR_RESET "\033[0m" +#define CLR_LINE "\033[K" 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 << "... " << 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_LINE << "\n" << std::flush; std::this_thread::sleep_for(std::chrono::milliseconds(200)); tcflush(STDIN_FILENO, TCIFLUSH); @@ -137,10 +138,11 @@ 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, highscore) << " " << (hardMode ? CLR_HARD "[HARD MODE]" : CLR_NORM "[NORMAL MODE]") - << (score > initialHighscore && initialHighscore > 0 ? " NEW BEST! 🥳" : "") - << " " << std::flush; + << (score > initialHighscore ? " NEW BEST! 🥳" : "") + << CLR_LINE << std::flush; updateUI = false; } } @@ -151,7 +153,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";