2023-04-27 08:14:47 +03:00
|
|
|
#!/bin/bash
|
2023-04-27 07:52:20 +03:00
|
|
|
|
|
|
|
# Clear screen
|
|
|
|
# echo -e "\033[2J"
|
|
|
|
clear
|
|
|
|
|
|
|
|
TERMINAL_WALLPAPER=/home/io/Projects/textual-paint/samples/galaxies.ans
|
2023-04-27 08:09:45 +03:00
|
|
|
TERMINAL_WALLPAPER_MODE=TILE
|
|
|
|
|
|
|
|
# Draw terminal background according to mode
|
|
|
|
if [[ $TERMINAL_WALLPAPER_MODE == "TOP_LEFT" ]]; then
|
|
|
|
cat $TERMINAL_WALLPAPER
|
2023-04-27 08:15:11 +03:00
|
|
|
else
|
2023-04-27 08:09:45 +03:00
|
|
|
# Split lines of terminal background into array
|
|
|
|
IFS=$'\n' read -d '' -r -a lines < $TERMINAL_WALLPAPER
|
|
|
|
|
|
|
|
# Measure image size
|
|
|
|
image_height=${#lines[@]}
|
|
|
|
image_width=0
|
|
|
|
for (( y=0; y<$image_height; y++ )); do
|
|
|
|
line=${lines[$y]}
|
|
|
|
# Have to strip ANSI escape sequences from line length
|
|
|
|
line_length=${#line}
|
|
|
|
filtered_line=$(sed -r "s/\x1B\[[0-9;]*[mK]//g" <<< "$line")
|
|
|
|
line_width=${#filtered_line}
|
|
|
|
|
|
|
|
# echo "y=$y line : $line line_length=$line_length"
|
|
|
|
# echo "y=$y filtered line: $filtered_line line_width=$line_width"
|
|
|
|
|
|
|
|
if [[ $line_width -gt $image_width ]]; then
|
|
|
|
image_width=$line_width
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2023-04-27 08:15:11 +03:00
|
|
|
if [[ $TERMINAL_WALLPAPER_MODE == "CENTER" ]]; then
|
|
|
|
# Calculate offset
|
|
|
|
terminal_width=$(tput cols)
|
|
|
|
terminal_height=$(tput lines)
|
|
|
|
offset_x=$(( ($terminal_width - $image_width) / 2 ))
|
|
|
|
offset_y=$(( ($terminal_height - $image_height) / 2 ))
|
|
|
|
# Ensure offset is positive
|
|
|
|
if [[ $offset_x -lt 0 ]]; then offset_x=0; fi
|
|
|
|
if [[ $offset_y -lt 0 ]]; then offset_y=0; fi
|
|
|
|
# Draw image
|
|
|
|
for (( i=0; i<$image_height; i++ )); do
|
|
|
|
tput cup $(( $offset_y + $i )) $offset_x
|
|
|
|
echo -e "${lines[$i]}"
|
|
|
|
done
|
|
|
|
elif [[ $TERMINAL_WALLPAPER_MODE == "TILE" ]]; then
|
|
|
|
# Draw tiled image
|
|
|
|
tput rmam
|
|
|
|
setterm -linewrap off
|
|
|
|
terminal_width=$(tput cols)
|
|
|
|
terminal_height=$(tput lines)
|
|
|
|
for (( y=0; y<$terminal_height; y+=$image_height )); do
|
|
|
|
for (( x=0; x<$terminal_width; x+=$image_width )); do
|
|
|
|
for (( i=0; i<$image_height; i++ )); do
|
|
|
|
# Don't scroll past bottom of terminal
|
|
|
|
if [[ $(( $y + $i + 1 )) -ge $terminal_height ]]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
# Draw line
|
|
|
|
tput cup $(( $y + $i )) $x
|
|
|
|
echo -e "${lines[$i]}"
|
|
|
|
done
|
2023-04-27 08:09:45 +03:00
|
|
|
done
|
|
|
|
done
|
2023-04-27 08:15:11 +03:00
|
|
|
tput smam
|
|
|
|
setterm -linewrap on
|
|
|
|
fi
|
2023-04-27 08:09:45 +03:00
|
|
|
fi
|
2023-04-27 07:52:20 +03:00
|
|
|
|
|
|
|
# Reset cursor position
|
|
|
|
echo -e "\033[0;0H"
|