Skip to content

Commit

Permalink
Merge pull request #273 from LinkUpGames/master
Browse files Browse the repository at this point in the history
Updated playerctl script to allow scrolling text
  • Loading branch information
ethancedwards8 committed Sep 5, 2024
2 parents 84b6b00 + dae8e6a commit 8f1a959
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions scripts/playerctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,59 @@
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8

current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $current_dir/utils.sh

main()
{
function slice_loop() {
local str="$1"
local start="$2"
local how_many="$3"
local len=${#str}

local result=""

for ((i = 0; i < how_many; i++)); do
local index=$(((start + i) % len))
local char="${str:index:1}"
result="$result$char"
done

echo "$result"
}

main() {
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)

if ! command -v playerctl &> /dev/null
then
if ! command -v playerctl &>/dev/null; then
exit 1
fi

FORMAT=$(get_tmux_option "@dracula-playerctl-format" "Now playing: {{ artist }} - {{ album }} - {{ title }}")
playerctl_playback=$(playerctl metadata --format "${FORMAT}")
echo ${playerctl_playback}
playerctl_playback="${playerctl_playback} "

# Adjust width of string
terminal_width=25

# Initial start point for scrolling
start=0
len=${#playerctl_playback}

scrolling_text=""

for ((start = 0; start <= len; start++)); do
scrolling_text=$(slice_loop "$playerctl_playback" "$start" "$terminal_width")
echo -ne "\r"
echo "$scrolling_text "
echo -ne "\r"

sleep 0.08
done

echo -ne "\r"
echo "$scrolling_text "
echo -ne "\r"
}

# run the main driver
Expand Down

0 comments on commit 8f1a959

Please sign in to comment.