๐Ÿฉธ 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.py
  • test_all.sh โ†’ tests/test_all.sh
  • test_all_functions.sh โ†’ tests/test_all_functions.sh
  • test_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:

  1. Color rendering for all supported colors
  2. Processing animation
  3. 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 thread
  • processing_animation() - Processing indicator
  • main_simple() - Fallback for piped input

๐ŸŽฏ Features Comparison

FeatureBeforeAfter
Idle IndicatorStatic textAnimated heartbeat
ColorsStaticCycling (Red โ†” Purple)
EmojisStaticAlternating (โ˜ ๏ธ โ†” ๐Ÿ’€)
ProcessingNoneAnimated indicator
InputStandard input()Raw terminal with history
Arrow KeysNot supportedFull history navigation
Terminal ModesInteractive onlyInteractive + 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

  1. Idle State - Pulsing heartbeat (Red/Purple)

    • Shows system is alive and ready
    • Non-intrusive background animation
  2. Processing - Skull/Heartbeat animation

    • Indicates command execution
    • Brief, doesn't block display
  3. Output - Colored responses

    • Success = Green
    • Errors = Red
    • Info = Cyan
  4. Prompt - Purple "Lucifer>"

    • Consistent brand color
    • Always ready for input

๐Ÿš€ Future Enhancements (Optional)

  1. Variable Speed: Heartbeat speeds up under load
  2. Multiple States: Different animations for different states
  3. Sound Effects: Optional terminal bell on events
  4. Custom Animations: User-configurable heartbeat patterns
  5. Performance Monitoring: Show CPU/memory in heartbeat

๐Ÿ“ Files Changed

Modified

  • lucifer.py - Complete rewrite of main loop

Created

  • tests/test_heartbeat.py - Heartbeat test suite
  • tests/README.md - Test documentation
  • HEARTBEAT_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