150 lines
3.7 KiB
Bash
Executable File
150 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# čd - Czech motorak animation (Czech Railways version of sl)
|
|
# Usage: čd [options]
|
|
|
|
# Parse options
|
|
DELAY=0.03
|
|
REVERSE=0
|
|
|
|
while getopts "hr" opt; do
|
|
case $opt in
|
|
h)
|
|
echo "čd - Czech motorak animation"
|
|
echo "Usage: čd [-h] [-r]"
|
|
echo " -h Show this help"
|
|
echo " -r Reverse direction"
|
|
exit 0
|
|
;;
|
|
r)
|
|
REVERSE=1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Get terminal width
|
|
COLS=$(tput cols)
|
|
|
|
# Czech motorak (ČD Class 810/810.0 "Orchestrion")
|
|
MOTORAK=(
|
|
" "
|
|
" ___ "
|
|
" | |___ "
|
|
" _____________ |___|___| _______________ "
|
|
" | ___ ___ |=|_________|==|___ ___ | "
|
|
" | | | | || O O | | | | | | "
|
|
" |_|___|__|___||___\_____/___|__|__|__|___|__| "
|
|
" \_O_/ \_O_/ \_______/ \_O_/ \_O_/ "
|
|
" "
|
|
" České dráhy - Motorák 810 "
|
|
)
|
|
|
|
# Smoke/exhaust variants
|
|
EXHAUST1=(
|
|
" ( ) ( ) "
|
|
" ( ) "
|
|
" ( ) ( ) "
|
|
)
|
|
|
|
EXHAUST2=(
|
|
" ( ) ( ) "
|
|
" ( ) "
|
|
" ( ) ( ) "
|
|
)
|
|
|
|
# Reverse the motorak if needed
|
|
if [ $REVERSE -eq 1 ]; then
|
|
# Flip the motorak horizontally
|
|
NEW_MOTORAK=()
|
|
for line in "${MOTORAK[@]}"; do
|
|
reversed=$(echo "$line" | rev)
|
|
NEW_MOTORAK+=("$reversed")
|
|
done
|
|
MOTORAK=("${NEW_MOTORAK[@]}")
|
|
fi
|
|
|
|
# Animation function
|
|
animate() {
|
|
local position=$1
|
|
local use_exhaust1=$2
|
|
|
|
# Move cursor to home position
|
|
tput cup 0 0
|
|
|
|
# Determine which exhaust to use
|
|
local exhaust
|
|
if [ $use_exhaust1 -eq 1 ]; then
|
|
exhaust=("${EXHAUST1[@]}")
|
|
else
|
|
exhaust=("${EXHAUST2[@]}")
|
|
fi
|
|
|
|
# Print exhaust lines
|
|
for line in "${exhaust[@]}"; do
|
|
if [ $REVERSE -eq 0 ]; then
|
|
# Left to right
|
|
printf "%${position}s%s" "" "$line"
|
|
tput el # Clear to end of line
|
|
echo
|
|
else
|
|
# Right to left
|
|
local spaces=$(($COLS - $position - ${#line}))
|
|
if [ $spaces -gt 0 ]; then
|
|
printf "%${spaces}s%s" "" "$line"
|
|
fi
|
|
tput el
|
|
echo
|
|
fi
|
|
done
|
|
|
|
# Print motorak lines
|
|
for line in "${MOTORAK[@]}"; do
|
|
if [ $REVERSE -eq 0 ]; then
|
|
# Left to right
|
|
printf "%${position}s%s" "" "$line"
|
|
tput el # Clear to end of line
|
|
echo
|
|
else
|
|
# Right to left
|
|
local spaces=$(($COLS - $position - ${#line}))
|
|
if [ $spaces -gt 0 ]; then
|
|
printf "%${spaces}s%s" "" "$line"
|
|
fi
|
|
tput el
|
|
echo
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Main animation loop
|
|
# Clear screen and hide cursor
|
|
clear
|
|
tput civis
|
|
|
|
if [ $REVERSE -eq 0 ]; then
|
|
# Left to right
|
|
for ((pos=0; pos<=$COLS+60; pos++)); do
|
|
if [ $((pos % 2)) -eq 0 ]; then
|
|
animate $pos 1
|
|
else
|
|
animate $pos 0
|
|
fi
|
|
sleep $DELAY
|
|
done
|
|
else
|
|
# Right to left
|
|
for ((pos=$COLS+60; pos>=0; pos--)); do
|
|
if [ $((pos % 2)) -eq 0 ]; then
|
|
animate $pos 1
|
|
else
|
|
animate $pos 0
|
|
fi
|
|
sleep $DELAY
|
|
done
|
|
fi
|
|
|
|
# Show cursor and clear
|
|
tput cnorm
|
|
clear
|
|
echo "Děkujeme, že jste cestovali s Českými drahami! 🚃"
|