Termux Cat Charging Animation | Real-Time Battery Monitor Using Python Script

Termux Cat Charging Animation

🐱 Live Charging Cat Animation in Termux using Python

Do you want to spice up your Termux experience? Imagine plugging in your charger and being greeted by a cute cat animation that shows your real-time battery status! In this post, I’ll guide you through setting up a real-time charging monitor in Termux using Python and Termux:API. Let's make your terminal more alive! 🔋✨


📦 What You’ll Need

  • Latest Termux app (F-Droid recommended)
  • Termux:API installed (pkg install termux-api)
  • Python installed in Termux (pkg install python)

📜 Step-by-Step Installation Guide

1. Copy the Python Script

I’ve created a simple yet animated script to handle everything. Copy the following code or you can download it:



#!/usr/bin/env python3

import subprocess

import json

import time

import os

import sys

class ChargingCat:

    def __init__(self):

        self.animation_frame = 0

        

    def clear_screen(self):

        os.system('clear')

    def get_battery_info(self):

        try:

            result = subprocess.run(['termux-battery-status'], 

                                  capture_output=True, text=True, timeout=10)

            if result.returncode == 0 and result.stdout.strip():

                battery_info = json.loads(result.stdout)

                return battery_info

            else:

                return None

        except Exception as e:

            print(f"Error getting battery info: {e}")

            return None

    def create_battery_bar(self, level):

        bar_length = 20

        filled_length = int(bar_length * level / 100)

        bar = '█' * filled_length + '░' * (bar_length - filled_length)

        return f"[{bar}] {level}%"

    def get_cat_frame(self, plugged, level):

        if plugged != 'UNPLUGGED':

            if level == 100:

                return """

    ╭─────────────────────╮

    │   😴 Sleepy Cat     │

    ╰─────────────────────╯

           /\\   /\\  

          (  - -  )

           \\  ∆  /   💤

            │___│    

            ╰───╯    

                """

            else:

                effects = ['⚡', '✨', '💫', '⭐']

                effect = effects[self.animation_frame % len(effects)]

                if self.animation_frame % 2 == 0:

                    return f"""

    ╭─────────────────────╮

    │   🔋 Charging Cat   │

    ╰─────────────────────╯

           /\\   /\\  

          (  ◕ ◕  )

           \\  ∆  /   {effect}

            │___│    

            ╰───╯    

                    """

                else:

                    return f"""

    ╭─────────────────────╮

    │   🔋 Charging Cat   │

    ╰─────────────────────╯

           /\\   /\\  

          (  ◉ ◉  )

           \\  ∆  /   {effect}

            │___│    

            ╰───╯    

                    """

        else:

            return """

    ╭─────────────────────╮

    │  💔 Unplugged Cat  │

    ╰─────────────────────╯

           /\\   /\\  

          (  ◕ ◕  )

           \\  ~  /   

            │___│    

            ╰───╯    

            """

    def show_animation(self, battery_info):

        self.clear_screen()

        

        level = battery_info.get('percentage', 0)

        status = battery_info.get('status', 'UNKNOWN')

        plugged = battery_info.get('plugged', 'UNPLUGGED')

        

        # Header

        print("=" * 50)

        print("      🐱 TERMUX CHARGING CAT MONITOR 🐱     ".center(50))

        print("=" * 50)

        

        # Show cat

        print(self.get_cat_frame(plugged, level))

        

        # Battery info

        print("    ╭─────────────────────────╮")

        print("    │      Battery Info       │")

        print("    ├─────────────────────────┤")

        print(f"    │ Level: {self.create_battery_bar(level)}")

        print(f"    │ Status: {status}")

        print(f"    │ Plugged: {plugged}")

        

        if 'temperature' in battery_info:

            temp = battery_info['temperature']

            print(f"    │ Temp: {temp}°C")

            

        print("    ╰─────────────────────────╯")

        

        # Status message

        if plugged != 'UNPLUGGED':

            if level == 100:

                print("    😊 Fully charged and happy! 😊")

            else:

                messages = [

                    "🔋 Nom nom nom... eating electrons!",

                    "⚡ Powering up for adventures!",

                    "✨ Getting ready to code!",

                    "🌟 Charging up powers!",

                    "💫 Preparing for work!"

                ]

                print(f"    {messages[self.animation_frame % len(messages)]}")

        else:

            print("    😢 Please plug me in! 😢")

        

        print()

        print("Press Ctrl+C to exit".center(50))

    def send_notification(self, title, message):

        try:

            subprocess.run(['termux-notification', '--title', title, '--content', message],

                          capture_output=True, timeout=5)

        except:

            pass

    def run(self):

        print("🐱 Starting Charging Cat Monitor...")

        time.sleep(2)

        

        previous_plugged = None

        

        try:

            while True:

                battery_info = self.get_battery_info()

                

                if battery_info:

                    current_plugged = battery_info.get('plugged', 'UNPLUGGED')

                    

                    # Detect changes

                    if previous_plugged is not None and previous_plugged != current_plugged:

                        if current_plugged != 'UNPLUGGED':

                            self.send_notification("🔌 Charger Connected!", "Cat is happy! ⚡")

                        else:

                            self.send_notification("🔌 Charger Disconnected!", "Cat is sad 😢")

                    

                    previous_plugged = current_plugged

                    self.show_animation(battery_info)

                    self.animation_frame += 1

                    

                else:

                    self.clear_screen()

                    print("❌ Cannot access battery information")

                    print("⚠️  Make sure Termux:API is installed:")

                    print("   pkg install termux-api")

                    time.sleep(3)

                

                time.sleep(1)

                

        except KeyboardInterrupt:

            self.clear_screen()

            print("=" * 50)

            print("🐱 Goodbye from Charging Cat! 🐱".center(50))

            print("✨ Thanks for keeping me company! ✨".center(50))

            print("=" * 50)

            sys.exit(0)

if __name__ == "__main__":

    cat_monitor = ChargingCat()

    cat_monitor.run()



2. Create a Python File in Termux

Open Termux and type:

nano charging_cat.py

Paste the script you copied earlier and save it by pressing CTRL + X, then Y and hit Enter.

3. Run the Script

python charging_cat.py

Now, whenever your phone is plugged in, the script will detect the charger and display the animated cat with battery info. 🐱⚡


🔍 How It Works

  • Battery Info: It fetches battery level, plug status, and temperature using termux-battery-status.
  • Animations: Depending on your charge status, the cat changes expression and shows energy effects.
  • Notifications: You’ll get a real-time notification when charger is connected/disconnected.
  • Live Terminal View: A clear and clean UI using ASCII to present stats + animation.

💡 Why It’s Useful

  • Visual feedback while coding or charging
  • Fun and educational Python project
  • Great for practicing Termux:API and terminal UI

📲 Bonus Tip: Add to Termux Home Screen

If you love it, you can make it easier to launch by creating a shortcut:

echo "python /data/data/com.termux/files/home/charging_cat.py" > startcat.sh

chmod +x startcat.sh

Then run it anytime with ./startcat.sh or add an alias in your .bashrc or .zshrc.


🔗 Related Articles You May Like


🧠 My Thoughts

This project is not just fun — it's a hands-on way to learn how Python, Termux, and Termux:API work together. You get to see live animations, experiment with system data, and improve your scripting skills. I personally love setting up such tools as it makes terminal hacking more interactive. You can even share this with friends or integrate similar concepts into your own custom tools.

So go ahead, plug in your charger, and let the 🐱 cat take over your terminal! Got any ideas to improve it? Let me know in the comments!

Happy Hacking! ⚡🐱

Kumar's Magic

Post a Comment

Previous Post Next Post