#!/bin/bash

# Initial setup: Hide cursor and clear screen
echo -e "\e[?25l"
clear

# Get terminal dimensions
cols=$(tput cols)
rows=$(tput lines)

# Array to store the current vertical position of each column
declare -a positions
for ((i=0; i<cols; i++)); do
    positions[$i]=$((RANDOM % rows))
done

# Character set (Katatana-like and alphanumeric)
chars=(😊 😀 😃 😄 😁 😆 😅 🤣 😂 🙂 😉 😊 😇 🥰 😍 🤩 😘 😗 😚 😙 🥲 😏)

# Handle script interruption (Ctrl+C) to show the cursor again
trap "echo -e '\e[?25h'; clear; exit" SIGINT SIGTERM

while true; do
    for ((i=0; i<cols; i++)); do
        # Randomly decide to update a column to create a "rain" effect
        if [ $((RANDOM % 5)) -eq 0 ]; then
            # Move cursor to the current position of the column
            tput cup ${positions[$i]} $i
            
            # Print a random character in green
            char=${chars[$((RANDOM % ${#chars[@]}))]}
            echo -ne "\e[32m$char"
            
            # Update position for next loop
            positions[$i]=$(( (positions[$i] + 1) % rows ))
            
            # Occasionally "erase" the tail by printing a space at the new position
            if [ $((RANDOM % 10)) -eq 0 ]; then
                tput cup $(( (positions[$i] + rows - 5) % rows )) $i
                echo -ne " "
            fi
        fi
    done
    sleep 0.05
done

