๐ฉธ Heartbeat Animation Implementation
January 23, 2026 ยท View on GitHub
Date: 2025-10-23
Summary
Successfully integrated idle heartbeat animation from the backup LuciferAI package with color cycling and emoji alternation.
โ What Was Implemented
1. Idle Heartbeat Animation
Continuous color-cycling animation that runs in the background while terminal is idle.
Features:
- Color Cycling: Alternates between Red and Purple every second
- Emoji Alternation: Cycles between โ ๏ธ (skull & bones) and ๐ (skull)
- Non-Blocking: Runs in background thread, doesn't interfere with input
- Smart Pausing: Automatically stops when user is typing
Visual Effect:
๐ฉธ Idle โข Awaiting Commands... โ ๏ธ (Red)
๐ฉธ Idle โข Awaiting Commands... ๐ (Purple)
๐ฉธ Idle โข Awaiting Commands... โ ๏ธ (Red)
... cycles continuously
2. Processing Animation
Shown during command execution to indicate activity.
Effect:
๐ Processing... (Purple)
๐ฉธ Processing... (Red)
... animates 3 times
3. Terminal State Management
Proper handling of different terminal modes:
-
Interactive Mode: Full heartbeat + raw input handling
- Arrow key history navigation
- Backspace handling
- Non-blocking input
-
Piped Mode: Simple input/output
- No termios manipulation
- Works with scripts and pipes
- Clean fallback behavior
4. Improved Input System
Enhanced from standard input() to raw terminal control:
Features:
- Command history with โ/โ arrows
- Real-time character-by-character input
- Proper backspace handling
- Clean terminal state restoration
๐ Test Organization
Cleaned Up Main Directory
Moved all test files from root to tests/ directory:
Moved Files:
demo_autofix.pyโtests/demo_autofix.pytest_all.shโtests/test_all.shtest_all_functions.shโtests/test_all_functions.shtest_broken_script.pyโtests/test_broken_script.py
New Test:
- Created
tests/test_heartbeat.py- Complete heartbeat test suite
Created:
tests/README.md- Full documentation of all tests
Test Directory Structure
tests/
โโโ README.md # Test documentation
โโโ demo_autofix.py # Auto-fix demonstration
โโโ test_all.sh # Quick test suite
โโโ test_all_functions.sh # Full test suite
โโโ test_broken_script.py # Intentionally broken for testing
โโโ test_heartbeat.py # Heartbeat animation tests
๐ง Technical Details
Heartbeat Thread
def heartbeat():
"""Idle heartbeat animation that cycles colors and emojis."""
colors = [Colors.RED, Colors.PURPLE]
skulls = [Emojis.SKULL_BONES, Emojis.SKULL]
i = 0
while RUNNING:
if HEART_STATE == "idle" and not USER_TYPING:
color = colors[i % 2]
skull = skulls[i % 2]
# Save cursor, move down, print, restore cursor
msg = f"\0337\033[1B\r{color}{Emojis.HEARTBEAT} Idle โข Awaiting Commands... {skull}{Colors.RESET}{CLEAR_LINE}\0338"
os.write(1, msg.encode())
i += 1
time.sleep(1.0)
Terminal Control Codes Used
\0337- Save cursor position\033[1B- Move cursor down 1 line\r- Carriage return (start of line)\033[K- Clear line from cursor\0338- Restore cursor position
State Management
RUNNING = True # Global loop control
USER_TYPING = False # Pause heartbeat during typing
HEART_STATE = "idle" # "idle" or "busy"
๐งช Testing
Test the Heartbeat
cd tests
python3 test_heartbeat.py
Tests:
- Color rendering for all supported colors
- Processing animation
- Live heartbeat with color cycling (Ctrl+C to stop)
Test in Interactive Mode
python3 lucifer.py
# Watch the heartbeat pulse while idle
# Type 'help' to see processing animation
# Type 'exit' to quit gracefully
๐ Code Changes
Modified Files
lucifer.py- Added heartbeat, processing animation, improved input handling
Imports Added
import threading # For background heartbeat thread
import time # For animation timing
import termios # For raw terminal control
import tty # For terminal modes
import select # For non-blocking input
New Functions
heartbeat()- Background animation threadprocessing_animation()- Processing indicatormain_simple()- Fallback for piped input
๐ฏ Features Comparison
| Feature | Before | After |
|---|---|---|
| Idle Indicator | Static text | Animated heartbeat |
| Colors | Static | Cycling (Red โ Purple) |
| Emojis | Static | Alternating (โ ๏ธ โ ๐) |
| Processing | None | Animated indicator |
| Input | Standard input() | Raw terminal with history |
| Arrow Keys | Not supported | Full history navigation |
| Terminal Modes | Interactive only | Interactive + Piped |
โ Verification Checklist
- Heartbeat animates with color cycling
- Emojis alternate correctly
- Pauses when user types
- Processing animation shows during commands
- Arrow keys navigate history
- Backspace works properly
- Terminal state restores on exit
- Works in piped mode
- All tests organized in tests/ directory
- Test documentation complete
- Main directory clean
๐ญ User Experience
Visual Feedback Hierarchy
-
Idle State - Pulsing heartbeat (Red/Purple)
- Shows system is alive and ready
- Non-intrusive background animation
-
Processing - Skull/Heartbeat animation
- Indicates command execution
- Brief, doesn't block display
-
Output - Colored responses
- Success = Green
- Errors = Red
- Info = Cyan
-
Prompt - Purple "Lucifer>"
- Consistent brand color
- Always ready for input
๐ Future Enhancements (Optional)
- Variable Speed: Heartbeat speeds up under load
- Multiple States: Different animations for different states
- Sound Effects: Optional terminal bell on events
- Custom Animations: User-configurable heartbeat patterns
- Performance Monitoring: Show CPU/memory in heartbeat
๐ Files Changed
Modified
lucifer.py- Complete rewrite of main loop
Created
tests/test_heartbeat.py- Heartbeat test suitetests/README.md- Test documentationHEARTBEAT_UPDATE.md- This file
Organized
- Moved 4 test files to
tests/directory - Clean main directory structure
Status: โ COMPLETE
The heartbeat animation system is fully functional with:
- โ Color cycling (Red โ Purple)
- โ Emoji alternation (โ ๏ธ โ ๐)
- โ Non-blocking background operation
- โ Smart pause during user input
- โ Processing animation
- โ Improved terminal handling
- โ Full test suite
- โ Clean project organization
Ready for production use!
Run python3 lucifer.py to see the heartbeat in action.
"Forged in Neon, Born of Silence." ๐พ
Implementation completed
Date: 2025-10-23