From 5c25d159edb4144e123a436def6144d533b794ba Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 17:36:55 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Palette:=20[UX=20improvement]=20?= =?UTF-8?q?Improve=20score=20readability=20and=20achievement=20feedback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 💡 What: - Added a `formatWithCommas` helper to improve the readability of large scores. - Refined the live HUD with consistent color styling for labels and values. - Enhanced the "NEW BEST!" achievement message with bold gold color and sparkles (✨). - Updated the final congratulations message to include the previous personal best for better context. - Ensured proper terminal color resetting to prevent color bleed. 🎯 Why: - Raw integers are hard to read as scores grow rapidly in clicker games. - Visual flair and contextual feedback make achievements feel more rewarding and delightful. ♿ Accessibility: - Improved readability of numeric data through standard comma-grouping. - Better visual hierarchy through consistent color-coding of data labels. - Clearer status indicators with explicit reset sequences for screen readers and varied terminal emulators. Co-authored-by: aidasofialily-cmd <247843425+aidasofialily-cmd@users.noreply.github.com> --- .Jules/palette.md | 4 ++++ src/main.cpp | 23 +++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.Jules/palette.md b/.Jules/palette.md index 05d4366..5350ec7 100644 --- a/.Jules/palette.md +++ b/.Jules/palette.md @@ -33,3 +33,7 @@ ## 2024-04-24 - Avoiding Trailing Artifacts in CLI Applications **Learning:** When dynamically updating terminal lines using carriage return (`\r`), relying on hardcoded padding spaces to overwrite old text is brittle and leads to trailing text artifacts when new lines are shorter than previous ones. **Action:** Always use the ANSI escape sequence `\033[K` (Erase in Line) immediately after the carriage return (`\r`) to cleanly clear the line before writing new content, rather than manually managing padding spaces. + +## 2025-01-25 - Improved Numeric Readability in CLI +**Learning:** Comma formatting for numeric scores (e.g., '1,234,567') significantly improves readability in clicker-style CLI games compared to raw integers, especially as scores grow rapidly. +**Action:** Use a comma-formatting helper for all large numeric displays in CLI applications to reduce cognitive load. diff --git a/src/main.cpp b/src/main.cpp index 60ae556..a25cb88 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,6 +51,17 @@ void save_highscore(long long score) { } } +std::string formatWithCommas(long long n) { + std::string s = std::to_string(n); + int insertPosition = static_cast(s.length()) - 3; + int limit = (n < 0) ? 1 : 0; + while (insertPosition > limit) { + s.insert(insertPosition, ","); + insertPosition -= 3; + } + return s; +} + int main() { struct termios newt; if (tcgetattr(STDIN_FILENO, &oldt) == -1) { @@ -78,7 +89,7 @@ int main() { std::cout << CLR_CTRL << "==========================\n SPEED CLICKER\n==========================\n" << CLR_RESET; if (highscore > 0) { - std::cout << " Personal Best: " << CLR_SCORE << highscore << CLR_RESET << "\n\n"; + std::cout << " Personal Best: " << CLR_SCORE << formatWithCommas(highscore) << CLR_RESET << "\n\n"; } std::cout << "Controls:\n " << CLR_CTRL << "[h]" << CLR_RESET << " Toggle Hard Mode (10x Speed!)\n " @@ -142,9 +153,9 @@ int main() { } if (updateUI) { - std::cout << "\r" ERASE_LINE << CLR_SCORE << "Score: " << score << CLR_RESET << " | High: " << highscore << " " - << (hardMode ? CLR_HARD "[HARD MODE]" : CLR_NORM "[NORMAL MODE]") - << (score > initialHighscore ? " NEW BEST! 🥳" : "") + std::cout << "\r" ERASE_LINE << CLR_SCORE << "Score: " << formatWithCommas(score) << " | High: " << formatWithCommas(highscore) << CLR_RESET << " " + << (hardMode ? CLR_HARD "[HARD MODE]" : CLR_NORM "[NORMAL MODE]") << CLR_RESET + << (score > initialHighscore ? CLR_CTRL " ✨ NEW BEST! 🥳" CLR_RESET : "") << std::flush; updateUI = false; } @@ -155,9 +166,9 @@ int main() { } tcsetattr(STDIN_FILENO, TCSANOW, &oldt); - std::cout << "\n\n" << CLR_SCORE << "Final Score: " << score << CLR_RESET << "\n"; + std::cout << "\n\n" << CLR_SCORE << "Final Score: " << formatWithCommas(score) << CLR_RESET << "\n"; if (score > initialHighscore) { - std::cout << "Congratulations! A new personal best!\n"; + std::cout << CLR_CTRL << "Congratulations! A new personal best! (Previous: " << formatWithCommas(initialHighscore) << ")" << CLR_RESET << "\n"; } std::cout << "Thanks for playing!\n"; std::cout << "\033[?25h" << std::flush;