diff --git a/.Jules/palette.md b/.Jules/palette.md index 05d4366..42aa45c 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. + +## 2026-06-29 - Quantitative Readability in CLI +**Learning:** In fast-paced CLI games, raw numbers can become difficult to parse at a glance as they grow (e.g., 1000000 vs 1,000,000). Implementing localized-style formatting (like thousands separators) significantly reduces cognitive load and improves the "at-a-glance" readability of the HUD. Furthermore, providing context for achievements (e.g., showing the previous high score) enhances the emotional impact of the reward. +**Action:** Always provide thousands separators for large numeric values in CLI interfaces and include contextual benchmarks in achievement messages to maximize user satisfaction. diff --git a/src/main.cpp b/src/main.cpp index 60ae556..2f5d954 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,6 +51,17 @@ void save_highscore(long long score) { } } +std::string formatWithCommas(long long value) { + std::string s = std::to_string(value); + int n = s.length(); + int insertPosition = n - 3; + while (insertPosition > (value < 0 ? 1 : 0)) { + 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,10 @@ 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) << CLR_RESET + << " | " << CLR_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 +167,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! ✨" << CLR_RESET << " (Previous: " << formatWithCommas(initialHighscore) << ")\n"; } std::cout << "Thanks for playing!\n"; std::cout << "\033[?25h" << std::flush;